Skip to content

Commit

Permalink
Fix AssertionError when using viash test without --memory (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
DriesSchaumont authored Oct 4, 2023
1 parent 6131f4d commit 136ae5b
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 6 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
=================

Expand Down
34 changes: 32 additions & 2 deletions tests/unittests/fixtures/test_run_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions viashpy/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 136ae5b

Please sign in to comment.