From 136ae5bd53f44a18840685393eccc73028e76e20 Mon Sep 17 00:00:00 2001 From: Dries Schaumont <5946712+DriesSchaumont@users.noreply.github.com> Date: Wed, 4 Oct 2023 06:30:05 +0200 Subject: [PATCH] Fix AssertionError when using viash test without --memory (#16) --- CHANGELOG.rst | 8 +++++ .../unittests/fixtures/test_run_component.py | 34 +++++++++++++++++-- viashpy/testing.py | 9 ++--- 3 files changed, 45 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 72610c7..cefde53 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -2,6 +2,14 @@ Changelog ********* +0.4.1 (4/10/2023) +================= + +Bug fixes +--------- +* Fix an issue with `run_component` raising `AssertionError` when using `viash test` without `--memory`. + + 0.4.0 (3/10/2023) ================= diff --git a/tests/unittests/fixtures/test_run_component.py b/tests/unittests/fixtures/test_run_component.py index b7cf7b5..4c54db2 100644 --- a/tests/unittests/fixtures/test_run_component.py +++ b/tests/unittests/fixtures/test_run_component.py @@ -49,7 +49,26 @@ def test_loading_run_component(run_component): @pytest.mark.parametrize( "memory_pb, memory_tb, memory_gb, memory_mb, memory_kb, memory_b, expected_bytes, expected_warning", [ - (None, None, None, None, None, None, None, False), # Not specified + ( + None, + None, + None, + None, + None, + None, + None, + False, + ), # Not specified (running test script directly but no memory constraints set) + ( + "None", + "None", + "None", + "None", + "None", + "None", + "None", + False, + ), # Using viash test without --memory ( 6, 6144, @@ -90,7 +109,18 @@ def test_run_component_different_memory_specification_warnings( expected_warning, ): expected_memory_args = "" - if any([memory_pb, memory_tb, memory_gb, memory_mb, memory_kb, memory_b]): + memory_specifiers = [ + memory_pb, + memory_tb, + memory_gb, + memory_mb, + memory_kb, + memory_b, + ] + memory_specifiers = [ + specifier for specifier in memory_specifiers if specifier != "None" + ] + if any(memory_specifiers): expected_memory_args = f', "--memory", "{expected_bytes}B"' expected = ( '["viash", "run", Path(meta["config"]), "--", "bar"%s]' % expected_memory_args diff --git a/viashpy/testing.py b/viashpy/testing.py index c6797cf..872327f 100644 --- a/viashpy/testing.py +++ b/viashpy/testing.py @@ -49,10 +49,11 @@ def memory_bytes(meta_attribute_getter): for suffix in tobytesconverter.AVAILABLE_UNITS(): try: memory_value = meta_attribute_getter(f"memory_{suffix.lower()}") - assert isinstance(memory_value, int) or isinstance( - memory_value, float - ), "The values for the memory resources set in the `meta` dictionairy must be floats or integers." - all_memory_attributes[suffix] = memory_value + if memory_value is not None: + assert isinstance(memory_value, int) or isinstance( + memory_value, float + ), "The values for the memory resources set in the `meta` dictionairy must be floats or integers." + all_memory_attributes[suffix] = memory_value except KeyError: pass if not all_memory_attributes: