""" Unit tests for job_enums module. Copyright (c) 2016 - present Syncleus, Inc. Copyright (c) 2016 - present CleverThis, Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. """ import pytest from cleverswarm_python_client.libs.job_enums import JobStatus, JobType class TestJobType: """Test cases for JobType enum.""" def test_enum_values(self): """Test that JobType has the correct values.""" assert JobType.UnstructuredWithOntology == "UnstructuredWithOntology" assert JobType.UnstructuredWithWildcards == "UnstructuredWithWildcards" assert JobType.Benchmark == "Benchmark" def test_enum_membership(self): """Test that JobType members can be checked for membership.""" # Test enum member membership (works in all Python versions) assert JobType.UnstructuredWithOntology in JobType assert JobType.UnstructuredWithWildcards in JobType assert JobType.Benchmark in JobType # Test string value membership (Python 3.12+ only) import sys if sys.version_info >= (3, 12): assert "UnstructuredWithOntology" in JobType assert "UnstructuredWithWildcards" in JobType assert "Benchmark" in JobType assert "InvalidType" not in JobType def test_enum_iteration(self): """Test that JobType can be iterated over.""" values = list(JobType) expected_values = ["UnstructuredWithOntology", "UnstructuredWithWildcards", "Benchmark"] assert len(values) == 3 for value in expected_values: assert value in values def test_enum_comparison(self): """Test that JobType values can be compared.""" assert JobType.UnstructuredWithOntology == "UnstructuredWithOntology" assert JobType.UnstructuredWithWildcards == "UnstructuredWithWildcards" assert JobType.Benchmark == "Benchmark" assert JobType.UnstructuredWithOntology != JobType.Benchmark def test_enum_string_representation(self): """Test string representation of JobType values.""" assert str(JobType.UnstructuredWithOntology) == "UnstructuredWithOntology" assert str(JobType.UnstructuredWithWildcards) == "UnstructuredWithWildcards" assert str(JobType.Benchmark) == "Benchmark" def test_enum_repr(self): """Test repr representation of JobType values.""" # Python 3.12+ uses a different repr format for enums assert "JobType.UnstructuredWithOntology" in repr(JobType.UnstructuredWithOntology) assert "JobType.UnstructuredWithWildcards" in repr(JobType.UnstructuredWithWildcards) assert "JobType.Benchmark" in repr(JobType.Benchmark) def test_enum_inheritance(self): """Test that JobType inherits from StrEnum.""" # Import StrEnum from the same module where JobType is defined from cleverswarm_python_client.libs.job_enums import StrEnum assert issubclass(JobType, StrEnum) def test_enum_equality_with_string(self): """Test that JobType values are equal to their string representations.""" assert JobType.UnstructuredWithOntology == "UnstructuredWithOntology" assert JobType.UnstructuredWithWildcards == "UnstructuredWithWildcards" assert JobType.Benchmark == "Benchmark" def test_enum_case_sensitivity(self): """Test that JobType values are case sensitive.""" assert JobType.UnstructuredWithOntology != "unstructuredwithontology" assert JobType.UnstructuredWithWildcards != "unstructuredwithwildcards" assert JobType.Benchmark != "benchmark" def test_enum_ordering(self): """Test that JobType values can be ordered.""" job_types = [JobType.Benchmark, JobType.UnstructuredWithOntology, JobType.UnstructuredWithWildcards] sorted_types = sorted(job_types) expected_order = ["Benchmark", "UnstructuredWithOntology", "UnstructuredWithWildcards"] assert [str(t) for t in sorted_types] == expected_order class TestJobStatus: """Test cases for JobStatus enum.""" def test_enum_values(self): """Test that JobStatus has the correct values.""" assert JobStatus.Created == "Created" assert JobStatus.ReadyForProcessing == "ReadyForProcessing" assert JobStatus.Processing == "Processing" assert JobStatus.Completed == "Completed" assert JobStatus.Failed == "Failed" def test_enum_membership(self): """Test that JobStatus members can be checked for membership.""" # Test enum member membership (works in all Python versions) assert JobStatus.Created in JobStatus assert JobStatus.ReadyForProcessing in JobStatus assert JobStatus.Processing in JobStatus assert JobStatus.Completed in JobStatus assert JobStatus.Failed in JobStatus # Test string value membership (Python 3.12+ only) import sys if sys.version_info >= (3, 12): assert "Created" in JobStatus assert "ReadyForProcessing" in JobStatus assert "Processing" in JobStatus assert "Completed" in JobStatus assert "Failed" in JobStatus assert "InvalidStatus" not in JobStatus def test_enum_iteration(self): """Test that JobStatus can be iterated over.""" values = list(JobStatus) expected_values = ["Created", "ReadyForProcessing", "Processing", "Completed", "Failed"] assert len(values) == 5 for value in expected_values: assert value in values def test_enum_comparison(self): """Test that JobStatus values can be compared.""" assert JobStatus.Created == "Created" assert JobStatus.ReadyForProcessing == "ReadyForProcessing" assert JobStatus.Processing == "Processing" assert JobStatus.Completed == "Completed" assert JobStatus.Failed == "Failed" assert JobStatus.Created != JobStatus.Completed def test_enum_string_representation(self): """Test string representation of JobStatus values.""" assert str(JobStatus.Created) == "Created" assert str(JobStatus.ReadyForProcessing) == "ReadyForProcessing" assert str(JobStatus.Processing) == "Processing" assert str(JobStatus.Completed) == "Completed" assert str(JobStatus.Failed) == "Failed" def test_enum_repr(self): """Test repr representation of JobStatus values.""" # Python 3.12+ uses a different repr format for enums assert "JobStatus.Created" in repr(JobStatus.Created) assert "JobStatus.ReadyForProcessing" in repr(JobStatus.ReadyForProcessing) assert "JobStatus.Processing" in repr(JobStatus.Processing) assert "JobStatus.Completed" in repr(JobStatus.Completed) assert "JobStatus.Failed" in repr(JobStatus.Failed) def test_enum_inheritance(self): """Test that JobStatus inherits from StrEnum.""" # Import StrEnum from the same module where JobStatus is defined from cleverswarm_python_client.libs.job_enums import StrEnum assert issubclass(JobStatus, StrEnum) def test_enum_equality_with_string(self): """Test that JobStatus values are equal to their string representations.""" assert JobStatus.Created == "Created" assert JobStatus.ReadyForProcessing == "ReadyForProcessing" assert JobStatus.Processing == "Processing" assert JobStatus.Completed == "Completed" assert JobStatus.Failed == "Failed" def test_enum_case_sensitivity(self): """Test that JobStatus values are case sensitive.""" assert JobStatus.Created != "created" assert JobStatus.ReadyForProcessing != "readyforprocessing" assert JobStatus.Processing != "processing" assert JobStatus.Completed != "completed" assert JobStatus.Failed != "failed" def test_enum_ordering(self): """Test that JobStatus values can be ordered.""" statuses = [JobStatus.Failed, JobStatus.Created, JobStatus.Completed, JobStatus.Processing, JobStatus.ReadyForProcessing] sorted_statuses = sorted(statuses) expected_order = ["Completed", "Created", "Failed", "Processing", "ReadyForProcessing"] assert [str(s) for s in sorted_statuses] == expected_order def test_enum_workflow_states(self): """Test that JobStatus represents a valid workflow.""" # Test that we can represent a typical job workflow workflow = [ JobStatus.Created, JobStatus.ReadyForProcessing, JobStatus.Processing, JobStatus.Completed ] # All states should be valid for status in workflow: assert status in JobStatus # Test failure state assert JobStatus.Failed in JobStatus class TestEnumInteractions: """Test cases for interactions between JobType and JobStatus enums.""" def test_different_enum_types(self): """Test that JobType and JobStatus are different enum types.""" # They should not be the same type assert JobType.Benchmark is not JobStatus.Completed # But they can have the same string value (though they don't in this case) assert JobType.Benchmark != JobStatus.Completed def test_enum_type_checking(self): """Test that enum types can be checked.""" assert isinstance(JobType.Benchmark, JobType) assert isinstance(JobStatus.Completed, JobStatus) assert not isinstance(JobType.Benchmark, JobStatus) assert not isinstance(JobStatus.Completed, JobType) def test_enum_unique_values(self): """Test that each enum has unique values.""" job_type_values = [member.value for member in JobType] job_status_values = [member.value for member in JobStatus] # Check that values within each enum are unique assert len(job_type_values) == len(set(job_type_values)) assert len(job_status_values) == len(set(job_status_values)) # Check that there are no overlapping values between the enums common_values = set(job_type_values) & set(job_status_values) assert len(common_values) == 0 def test_enum_usage_in_conditionals(self): """Test that enums can be used in conditional statements.""" job_type = JobType.Benchmark job_status = JobStatus.Completed # Test equality conditions if job_type == JobType.Benchmark: assert True else: assert False if job_status == JobStatus.Completed: assert True else: assert False def test_enum_usage_in_switch_like_statements(self): """Test that enums can be used in switch-like statements.""" def process_job_type(job_type): if job_type == JobType.UnstructuredWithOntology: return "processing_with_ontology" elif job_type == JobType.UnstructuredWithWildcards: return "processing_with_wildcards" elif job_type == JobType.Benchmark: return "processing_benchmark" else: return "unknown_type" assert process_job_type(JobType.UnstructuredWithOntology) == "processing_with_ontology" assert process_job_type(JobType.UnstructuredWithWildcards) == "processing_with_wildcards" assert process_job_type(JobType.Benchmark) == "processing_benchmark" def test_enum_usage_in_status_checks(self): """Test that enums can be used in status checking functions.""" def is_job_finished(status): return status in [JobStatus.Completed, JobStatus.Failed] def is_job_running(status): return status in [JobStatus.Processing, JobStatus.ReadyForProcessing] assert is_job_finished(JobStatus.Completed) assert is_job_finished(JobStatus.Failed) assert not is_job_finished(JobStatus.Processing) assert not is_job_finished(JobStatus.Created) assert is_job_running(JobStatus.Processing) assert is_job_running(JobStatus.ReadyForProcessing) assert not is_job_running(JobStatus.Completed) assert not is_job_running(JobStatus.Failed)