-
Notifications
You must be signed in to change notification settings - Fork 19
Support space-separated key-value pairs in moduleArgs and case-insensitive arg matching #243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| from unittest import TestCase | ||
|
|
||
| from RLTest.utils import fix_modulesArgs | ||
|
|
||
|
|
||
| class TestFixModulesArgs(TestCase): | ||
|
|
||
| # 1. Single key-value pair string | ||
| def test_single_key_value_pair(self): | ||
| result = fix_modulesArgs(['/mod.so'], 'WORKERS 4') | ||
| self.assertEqual(result, [['WORKERS 4']]) | ||
|
|
||
| # 2. Multiple key-value pairs without semicolons (new behavior) | ||
| def test_multiple_kv_pairs_no_semicolons(self): | ||
| result = fix_modulesArgs(['/mod.so'], '_FREE_RESOURCE_ON_THREAD FALSE TIMEOUT 80 WORKERS 4') | ||
| self.assertEqual(result, [['_FREE_RESOURCE_ON_THREAD FALSE', 'TIMEOUT 80', 'WORKERS 4']]) | ||
|
|
||
| # 3. Semicolon-separated args (existing behavior) | ||
| def test_semicolon_separated_args(self): | ||
| result = fix_modulesArgs(['/mod.so'], 'KEY1 V1; KEY2 V2') | ||
| self.assertEqual(result, [['KEY1 V1', 'KEY2 V2']]) | ||
|
|
||
| # 4a. Odd number of words without semicolons - should error | ||
| def test_odd_words_no_semicolons_exits(self): | ||
| with self.assertRaises(SystemExit): | ||
| fix_modulesArgs(['/mod.so'], 'FLAG TIMEOUT 80') | ||
|
|
||
| # 4b. Odd number of words with semicolons - valid, semicolons split first | ||
| def test_odd_words_with_semicolons_valid(self): | ||
| result = fix_modulesArgs(['/mod.so'], 'FLAG; TIMEOUT 80') | ||
| self.assertEqual(result, [['FLAG', 'TIMEOUT 80']]) | ||
|
|
||
| # 5a. Space-separated string overrides matching defaults, non-matching defaults added | ||
| def test_space_separated_overrides_defaults(self): | ||
| defaults = [['WORKERS 8', 'TIMEOUT 60', 'EXTRA 1']] | ||
| result = fix_modulesArgs(['/mod.so'], 'WORKERS 4 TIMEOUT 80', defaults) | ||
| result_dict = {arg.split(' ')[0]: arg for arg in result[0]} | ||
| self.assertEqual(result_dict['WORKERS'], 'WORKERS 4') | ||
| self.assertEqual(result_dict['TIMEOUT'], 'TIMEOUT 80') | ||
| self.assertEqual(result_dict['EXTRA'], 'EXTRA 1') | ||
|
|
||
| # 5b. Semicolon-separated string overrides matching defaults | ||
| def test_semicolon_separated_overrides_defaults(self): | ||
| defaults = [['WORKERS 8', 'TIMEOUT 60', 'EXTRA 1']] | ||
| result = fix_modulesArgs(['/mod.so'], 'WORKERS 4; TIMEOUT 80', defaults) | ||
| result_dict = {arg.split(' ')[0]: arg for arg in result[0]} | ||
| self.assertEqual(result_dict['WORKERS'], 'WORKERS 4') | ||
| self.assertEqual(result_dict['TIMEOUT'], 'TIMEOUT 80') | ||
| self.assertEqual(result_dict['EXTRA'], 'EXTRA 1') | ||
|
|
||
| # 5c. Space-separated explicit overrides some defaults, non-overlapping defaults are merged | ||
| def test_space_separated_partial_override_with_defaults(self): | ||
| defaults = [['_FREE_RESOURCE_ON_THREAD TRUE', 'TIMEOUT 100', 'WORKERS 8']] | ||
| result = fix_modulesArgs(['/mod.so'], 'WORKERS 4 TIMEOUT 80', defaults) | ||
| result_dict = {arg.split(' ')[0]: arg for arg in result[0]} | ||
| self.assertEqual(result_dict['WORKERS'], 'WORKERS 4') | ||
| self.assertEqual(result_dict['TIMEOUT'], 'TIMEOUT 80') | ||
| self.assertEqual(result_dict['_FREE_RESOURCE_ON_THREAD'], '_FREE_RESOURCE_ON_THREAD TRUE') | ||
|
|
||
| # 6. None input with defaults - deep copy of defaults | ||
| def test_none_uses_defaults(self): | ||
| defaults = [['WORKERS 8', 'TIMEOUT 60']] | ||
| result = fix_modulesArgs(['/mod.so'], None, defaults) | ||
| self.assertEqual(result, defaults) | ||
| # Verify it's a deep copy | ||
| result[0][0] = 'MODIFIED' | ||
| self.assertEqual(defaults[0][0], 'WORKERS 8') | ||
|
|
||
| # 7. List of strings with defaults - overlapping and non-overlapping keys | ||
| def test_list_of_strings_with_defaults(self): | ||
| defaults = [['K1 default1', 'K2 default2', 'K4 default4']] | ||
| result = fix_modulesArgs(['/mod.so'], ['K1 override1', 'K2 override2', 'K3 new3'], defaults) | ||
| result_dict = {arg.split(' ')[0]: arg for arg in result[0]} | ||
| self.assertEqual(result_dict['K1'], 'K1 override1') | ||
| self.assertEqual(result_dict['K2'], 'K2 override2') | ||
| self.assertEqual(result_dict['K3'], 'K3 new3') | ||
| self.assertEqual(result_dict['K4'], 'K4 default4') | ||
|
|
||
| # 8. List of lists (multi-module) with defaults - overlapping and non-overlapping keys | ||
| def test_multi_module_with_defaults(self): | ||
| modules = ['/mod1.so', '/mod2.so'] | ||
| explicit = [['K1 v1', 'K2 v2'], ['K3 v3']] | ||
| defaults = [['K1 d1', 'K5 d5'], ['K3 d3', 'K4 d4']] | ||
| result = fix_modulesArgs(modules, explicit, defaults) | ||
| # Module 1: K1 overridden, K5 added from defaults | ||
| dict1 = {arg.split(' ')[0]: arg for arg in result[0]} | ||
| self.assertEqual(dict1['K1'], 'K1 v1') | ||
| self.assertEqual(dict1['K2'], 'K2 v2') | ||
| self.assertEqual(dict1['K5'], 'K5 d5') | ||
| # Module 2: K3 overridden, K4 added from defaults | ||
| dict2 = {arg.split(' ')[0]: arg for arg in result[1]} | ||
| self.assertEqual(dict2['K3'], 'K3 v3') | ||
| self.assertEqual(dict2['K4'], 'K4 d4') | ||
|
|
||
|
|
||
| # 9. Case-insensitive matching between explicit args and defaults (both directions) | ||
| def test_case_insensitive_override(self): | ||
| # Uppercase explicit overrides lowercase defaults | ||
| defaults = [['workers 8', 'timeout 60', 'EXTRA 1', 'MIxEd 7', 'lower true']] | ||
| result = fix_modulesArgs(['/mod.so'], 'WORKERS 4 TIMEOUT 80 miXed 0 LOWER false', defaults) | ||
| result_dict = {arg.split(' ')[0]: arg for arg in result[0]} | ||
| self.assertEqual(result_dict['WORKERS'], 'WORKERS 4') | ||
| self.assertEqual(result_dict['TIMEOUT'], 'TIMEOUT 80') | ||
| self.assertEqual(result_dict['EXTRA'], 'EXTRA 1') | ||
| self.assertEqual(result_dict['miXed'], 'miXed 0') | ||
| self.assertEqual(result_dict['LOWER'], 'LOWER false') | ||
| self.assertNotIn('workers', result_dict) | ||
| self.assertNotIn('timeout', result_dict) | ||
| self.assertNotIn('MIxEd', result_dict) | ||
| self.assertNotIn('lower', result_dict) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: f-string not needed here.