Skip to content

Commit

Permalink
Added test to check list states elements are deleted (even when refer…
Browse files Browse the repository at this point in the history
…enced, and hence not automatically garbage collected). Fixed failing test (want to check list state, but assigned Tensor)
  • Loading branch information
dominicgkerr committed Apr 7, 2024
1 parent 11df0eb commit 1fa7077
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion tests/unittests/bases/test_metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,17 @@ class B(DummyListMetric):
metric = B()
assert isinstance(metric.x, list)
assert len(metric.x) == 0
metric.x = tensor(5)
metric.x = [tensor(5)]
metric.reset()
assert isinstance(metric.x, list)
assert len(metric.x) == 0

metric = B()
metric.x = [1, 2, 3]
reference = metric.x # prevents garbage collection
metric.reset()
assert len(reference) == 0 # check list state is freed


def test_reset_compute():
"""Test that `reset`+`compute` methods works as expected."""
Expand Down

0 comments on commit 1fa7077

Please sign in to comment.