Skip to content

Commit b86e725

Browse files
davidnichols-opsdevin-ai-integration[bot]
andcommitted
test: add tests and changelog entry for class sorting feature
- Add test suite for DISABLE_CLASS_SORTING configuration - Test default value, environment variable parsing, and case insensitivity - Update CHANGELOG.md with new feature entry Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
1 parent 72ebbb9 commit b86e725

2 files changed

Lines changed: 67 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ All notable changes to this project will be documented in this file.
88

99
- Weight upload support for yolo26-sem semantic segmentation models via
1010
`version.deploy()` and `workspace.deploy_model()`
11+
- `ROBOFLOW_DISABLE_CLASS_SORTING` environment variable to preserve custom
12+
class ordering during YOLO model deployment (opt-in, defaults to false)
1113

1214
## 1.3.9
1315

tests/util/test_class_sorting.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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

Comments
 (0)