-
Notifications
You must be signed in to change notification settings - Fork 57
Feat: Added functionalities to remove duplicate parameters and overwrite existing ones. #506
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
Closed
DannyLiCom
wants to merge
8
commits into
AI-Hypercomputer:develop
from
CIeNET-International:lidanny/feature/Extended_Subnet_Ranges
Closed
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
91b3ae1
feat: Adding a de-dupe function
DannyLiCom bc47601
Refactored GKE cluster creation to use a dictionary for argument mana…
DannyLiCom 85f0982
feat: Add process_gcloud_args to handle custom gcloud arguments.
DannyLiCom ab3cd89
feat: Added two unit tests.
DannyLiCom 928f693
Update test_gcloud_arg_processor.py
DannyLiCom e95b91f
feat: Updated the functionality of the process_gcloud_args function. …
DannyLiCom 1b7442c
Resolve lint issue
DannyLiCom 2a787ff
Merge branch 'develop' into lidanny/feature/Extended_Subnet_Ranges
DannyLiCom 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,43 @@ | ||
| import unittest | ||
| from ...cluster import parse_command_args_to_dict | ||
|
|
||
| class TestParseCommandArgsToDict(unittest.TestCase): | ||
|
|
||
| def test_empty_string(self): | ||
| self.assertEqual(parse_command_args_to_dict(''), {}) | ||
|
|
||
| def test_simple_key_value_pairs(self): | ||
| result = parse_command_args_to_dict('--key1=value1 --key2=value2') | ||
| self.assertEqual(result, {'--key1': 'value1', '--key2': 'value2'}) | ||
|
|
||
| def test_flag_with_space_value(self): | ||
| result = parse_command_args_to_dict('--key1 value1 --key2 value2') | ||
| self.assertEqual(result, {'--key1': 'value1', '--key2': 'value2'}) | ||
|
|
||
| def test_boolean_flags(self): | ||
| result = parse_command_args_to_dict('--enable-feature --no-logs') | ||
| self.assertEqual(result, {'--enable-feature': True, '--no-logs': True}) | ||
|
|
||
| def test_mixed_formats(self): | ||
| result = parse_command_args_to_dict('--project=my-project --zone us-central1 --dry-run') | ||
| self.assertEqual(result, {'--project': 'my-project', '--zone': 'us-central1', '--dry-run': True}) | ||
|
|
||
| def test_quoted_values(self): | ||
| result = parse_command_args_to_dict('--description "My cluster with spaces" --name=test-cluster') | ||
| self.assertEqual(result, {'--description': 'My cluster with spaces', '--name': 'test-cluster'}) | ||
|
|
||
| def test_no_double_hyphen_flags(self): | ||
| result = parse_command_args_to_dict('random-word -f --flag') | ||
| self.assertEqual(result, {'--flag': True}) # Only --flag should be parsed | ||
|
|
||
| def test_duplicate_keys_last_one_wins(self): | ||
| result = parse_command_args_to_dict('--key=value1 --key=value2') | ||
| self.assertEqual(result, {'--key': 'value2'}) | ||
|
|
||
| def test_hyphenated_keys(self): | ||
| result = parse_command_args_to_dict('--api-endpoint=some-url') | ||
| self.assertEqual(result, {'--api-endpoint': 'some-url'}) | ||
|
|
||
| if __name__ == '__main__': | ||
| # Run python3 -m src.xpk.commands.tests.unit.test_arg_parser under the xpk folder. | ||
| unittest.main() |
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,70 @@ | ||
| import unittest | ||
| from ...cluster import process_gcloud_args | ||
|
|
||
| class TestProcessGcloudArgs(unittest.TestCase): | ||
|
|
||
| def test_add_new_argument(self): | ||
| final_args = {'--existing-key': 'existing-value'} | ||
| user_args = {'--new-key': 'new-value'} | ||
| process_gcloud_args(user_args, final_args) | ||
| self.assertEqual(final_args, {'--existing-key': 'existing-value', '--new-key': 'new-value'}) | ||
|
|
||
| def test_override_existing_argument(self): | ||
| final_args = {'--common-key': 'old-value'} | ||
| user_args = {'--common-key': 'new-value'} | ||
| process_gcloud_args(user_args, final_args) | ||
| self.assertEqual(final_args, {'--common-key': 'new-value'}) | ||
|
|
||
| def test_no_enable_flag_overrides_enable(self): | ||
| final_args = {'--enable-logging': True} | ||
| user_args = {'--no-enable-logging': True} | ||
| process_gcloud_args(user_args, final_args) | ||
| self.assertEqual(final_args, {'--no-enable-logging': True}) | ||
| self.assertNotIn('--enable-logging', final_args) | ||
|
|
||
| def test_enable_flag_overrides_no_enable(self): | ||
| final_args = {'--no-enable-monitoring': True} | ||
| user_args = {'--enable-monitoring': True} | ||
| process_gcloud_args(user_args, final_args) | ||
| self.assertEqual(final_args, {'--enable-monitoring': True}) | ||
| self.assertNotIn('--no-enable-monitoring', final_args) | ||
|
|
||
| def test_no_conflict(self): | ||
| final_args = {'--param1': 'value1'} | ||
| user_args = {'--param2': 'value2'} | ||
| process_gcloud_args(user_args, final_args) | ||
| self.assertEqual(final_args, {'--param1': 'value1', '--param2': 'value2'}) | ||
|
|
||
| def test_empty_user_args(self): | ||
| final_args = {'--param1': 'value1'} | ||
| user_args = {} | ||
| process_gcloud_args(user_args, final_args) | ||
| self.assertEqual(final_args, {'--param1': 'value1'}) | ||
|
|
||
| def test_complex_overrides(self): | ||
| final_args = { | ||
| '--zone': 'us-east1-b', | ||
| '--enable-ip-alias': True, | ||
| '--machine-type': 'n1-standard-4', | ||
| '--no-enable-public-ip': True # This will be removed if --enable-public-ip is set | ||
| } | ||
| user_args = { | ||
| '--zone': 'us-central1-a', # Overrides | ||
| '--no-enable-ip-alias': True, # Overrides --enable-ip-alias | ||
| '--disk-size': '200GB', # New | ||
| '--enable-public-ip': True # Overrides --no-enable-public-ip | ||
| } | ||
| process_gcloud_args(user_args, final_args) | ||
| self.assertEqual(final_args, { | ||
| '--zone': 'us-central1-a', | ||
| '--no-enable-ip-alias': True, | ||
| '--machine-type': 'n1-standard-4', # Not affected | ||
| '--disk-size': '200GB', | ||
| '--enable-public-ip': True | ||
| }) | ||
| self.assertNotIn('--enable-ip-alias', final_args) | ||
| self.assertNotIn('--no-enable-public-ip', final_args) | ||
|
|
||
| if __name__ == '__main__': | ||
| # Run python3 -m src.xpk.commands.tests.unit.test_gcloud_arg_processor under the xpk folder. | ||
| unittest.main() |
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.
Uh oh!
There was an error while loading. Please reload this page.