Skip to content

Commit

Permalink
Fix semver patch strip function and replace deprecated self.assertIte…
Browse files Browse the repository at this point in the history
…msEqual with assert.
  • Loading branch information
nzlosh committed Mar 19, 2024
1 parent bcc74d8 commit 6aaaaaf
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 12 deletions.
1 change: 0 additions & 1 deletion st2client/tests/unit/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,6 @@ def test_help_command_line_arg_works_for_supported_commands(self):
# optional arguments covers both formats.
assert isinstance(re.search("(optional arguments:|options:)", stdout), re.Match) is True


# Verify that the actual help usage string was triggered and not the invalid
# "too few arguments" which would indicate command doesn't actually correctly handle
# --help flag
Expand Down
3 changes: 2 additions & 1 deletion st2common/st2common/expressions/functions/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,5 @@ def version_bump_patch(value):


def version_strip_patch(value):
return "{major}.{minor}".format(**semver.Version.parse(value))
sv = semver.Version.parse(value)
return f"{sv.major}.{sv.minor}"
4 changes: 2 additions & 2 deletions st2common/tests/unit/test_greenpooldispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_dispatch_simple(self):
call_args_list = [
(args[0][0], args[0][1]) for args in mock_handler.call_args_list
]
self.assertItemsEqual(expected, call_args_list)
assert expected == call_args_list

def test_dispatch_starved(self):
dispatcher = BufferedDispatcher(
Expand All @@ -55,4 +55,4 @@ def test_dispatch_starved(self):
call_args_list = [
(args[0][0], args[0][1]) for args in mock_handler.call_args_list
]
self.assertItemsEqual(expected, call_args_list)
assert expected == call_args_list
2 changes: 1 addition & 1 deletion st2common/tests/unit/test_model_utils_profiling.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_logging_profiling_is_disabled(self, mock_log):
result = log_query_and_profile_data_for_queryset(queryset=queryset)
self.assertEqual(queryset, result)
call_args_list = mock_log.debug.call_args_list
self.assertItemsEqual(call_args_list, [])
assert call_args_list == []

@mock.patch("st2common.models.utils.profiling.LOG")
def test_logging_profiling_is_enabled(self, mock_log):
Expand Down
12 changes: 9 additions & 3 deletions st2common/tests/unit/test_util_file_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,11 @@ def test_get_file_list(self):
"meta/concurrency.yaml",
"meta/__init__.py",
]
result = get_file_list(directory=directory, exclude_patterns=["*.pyc"])
self.assertItemsEqual(expected, result)
result = get_file_list(directory=directory, exclude_patterns=["*.pyc", "__pycache__"])
# directory listings are sorted because the item order must be exact for assert
# to validate equivalence. Directory item order doesn't matter in general and may
# even change on different platforms or locales.
assert sorted(expected) == sorted(result)

# Custom exclude pattern
expected = [
Expand All @@ -52,4 +55,7 @@ def test_get_file_list(self):
result = get_file_list(
directory=directory, exclude_patterns=["*.pyc", "*.yaml", "*BUILD"]
)
self.assertItemsEqual(expected, result)
# directory listings are sorted because the item order must be exact for assert
# to validate equivalence. Directory item order doesn't matter in general and may
# even change on different platforms or locales.
assert sorted(expected) == sorted(result)
9 changes: 5 additions & 4 deletions st2reactor/tests/unit/test_timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ def test_trigger_types_are_registered_on_start(self):
timer = St2Timer()
timer._scheduler = mock.Mock()

# Verify there are no TriggerType in the db when we start
self.assertItemsEqual(TriggerType.get_all(), [])
# Verify there are no TriggerType objects in the db when we start
# and cast Mongo QuerySet iterator cast to list for evaluation.
assert list(TriggerType.get_all()) == []

timer.start()

Expand All @@ -55,8 +56,8 @@ def test_existing_rules_are_loaded_on_start(self):
timer._trigger_watcher.run = mock.Mock()

# Verify there are no Trigger and TriggerType in the db wh:w
self.assertItemsEqual(Trigger.get_all(), [])
self.assertItemsEqual(TriggerType.get_all(), [])
assert list(Trigger.get_all()) == []
assert list(TriggerType.get_all()) == []

# Add a dummy timer Trigger object
type_ = list(TIMER_TRIGGER_TYPES.keys())[0]
Expand Down

0 comments on commit 6aaaaaf

Please sign in to comment.