|
| 1 | +import os |
| 2 | +import sys |
| 3 | +import unittest |
| 4 | +from unittest.mock import patch |
| 5 | +import importlib.util |
| 6 | + |
| 7 | +# Get the path to config.py directly |
| 8 | +config_path = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), 'roboflow', 'config.py') |
| 9 | + |
| 10 | + |
| 11 | +class TestClassSorting(unittest.TestCase): |
| 12 | + """Test DISABLE_CLASS_SORTING configuration for class ordering.""" |
| 13 | + |
| 14 | + def test_disable_class_sorting_default_value(self): |
| 15 | + """Test that DISABLE_CLASS_SORTING defaults to False.""" |
| 16 | + # Load config module directly without triggering __init__.py |
| 17 | + spec = importlib.util.spec_from_file_location("config", config_path) |
| 18 | + config = importlib.util.module_from_spec(spec) |
| 19 | + spec.loader.exec_module(config) |
| 20 | + |
| 21 | + self.assertFalse(config.DISABLE_CLASS_SORTING) |
| 22 | + |
| 23 | + def test_disable_class_sorting_env_var_true(self): |
| 24 | + """Test that ROBOFLOW_DISABLE_CLASS_SORTING=true sets config to True.""" |
| 25 | + with patch.dict(os.environ, {"ROBOFLOW_DISABLE_CLASS_SORTING": "true"}): |
| 26 | + # Reload config to pick up env var |
| 27 | + spec = importlib.util.spec_from_file_location("config", config_path) |
| 28 | + config = importlib.util.module_from_spec(spec) |
| 29 | + spec.loader.exec_module(config) |
| 30 | + |
| 31 | + # After reload, should be True |
| 32 | + self.assertTrue(config.DISABLE_CLASS_SORTING) |
| 33 | + |
| 34 | + def test_disable_class_sorting_env_var_false(self): |
| 35 | + """Test that ROBOFLOW_DISABLE_CLASS_SORTING=false keeps config as False.""" |
| 36 | + with patch.dict(os.environ, {"ROBOFLOW_DISABLE_CLASS_SORTING": "false"}): |
| 37 | + spec = importlib.util.spec_from_file_location("config", config_path) |
| 38 | + config = importlib.util.module_from_spec(spec) |
| 39 | + spec.loader.exec_module(config) |
| 40 | + |
| 41 | + self.assertFalse(config.DISABLE_CLASS_SORTING) |
| 42 | + |
| 43 | + def test_disable_class_sorting_env_var_case_insensitive(self): |
| 44 | + """Test that env var is case-insensitive.""" |
| 45 | + for value in ["True", "TRUE", "tRuE"]: |
| 46 | + with patch.dict(os.environ, {"ROBOFLOW_DISABLE_CLASS_SORTING": value}): |
| 47 | + spec = importlib.util.spec_from_file_location("config", config_path) |
| 48 | + config = importlib.util.module_from_spec(spec) |
| 49 | + spec.loader.exec_module(config) |
| 50 | + |
| 51 | + self.assertTrue(config.DISABLE_CLASS_SORTING) |
| 52 | + |
| 53 | + def test_config_import(self): |
| 54 | + """Test that DISABLE_CLASS_SORTING exists and is a boolean.""" |
| 55 | + spec = importlib.util.spec_from_file_location("config", config_path) |
| 56 | + config = importlib.util.module_from_spec(spec) |
| 57 | + spec.loader.exec_module(config) |
| 58 | + |
| 59 | + config_value = config.DISABLE_CLASS_SORTING |
| 60 | + self.assertIsNotNone(config_value) |
| 61 | + self.assertIsInstance(config_value, bool) |
| 62 | + |
| 63 | + |
| 64 | +if __name__ == "__main__": |
| 65 | + unittest.main() |
0 commit comments