Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions gnm/shape/gnm_data_loader_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,17 @@ def test_load_model_from_custom_file_drops_extra_fields(self):

self.assertNotIn('extra_field', data)

def test_load_model_from_custom_file_rereads_changed_file(self):
"""A model file that changed on disk is read again, not served stale."""
local_path = self._write_model(joint_names=['joint1'])
data1 = gnm_data_loader.load_model_from_custom_file(local_path)

self._write_model(joint_names=['new_joint'])
data2 = gnm_data_loader.load_model_from_custom_file(local_path)

self.assertEqual(data1['joint_names'], ['joint1'])
self.assertEqual(data2['joint_names'], ['new_joint'])

def test_load_model_from_custom_file_fails_when_file_not_found(self):
with self.assertRaisesRegex(ValueError, 'not found'):
gnm_data_loader.load_model_from_custom_file(
Expand Down
5 changes: 4 additions & 1 deletion gnm/shape/gnm_utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ class BaseGNMUtilsTest(parameterized.TestCase):
"""Base class loading the GNMs on demand.

Attributes:
gnms: The GNMs, by version and variant.
gnms: The GNMs, by version and variant. Loaded models are shared by the
tests of a class, so tests must not modify them (neither in place nor by
reassigning attributes). Copy a model with `copy.deepcopy(...)` before
changing it.
max_loaded: The maximum number of models kept in memory at once, e.g. 2 for
tests using two models at once. If None, all the models of a version are
kept in memory.
Expand Down
5 changes: 5 additions & 0 deletions gnm/shape/oss_data_loaders/oss_data_loaders_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ def test_load_model_from_remote_returns_independent_data(self):
gnm_specs.GNMVariant.HEAD,
cache_dir=self.temp_dir,
)
expected_positions = np.array(data1['template_vertex_positions'])
data1['template_vertex_positions'][:] = 1.0
data1['joint_names'].append('leaked_joint')
data2 = oss_data_loaders.load_model_from_remote(
gnm_specs.GNMMajorVersion.V3,
Expand All @@ -254,6 +256,9 @@ def test_load_model_from_remote_returns_independent_data(self):
)

self.assertIsNot(data1, data2)
np.testing.assert_array_equal(
data2['template_vertex_positions'], expected_positions
)
self.assertNotIn('leaked_joint', data2['joint_names'])

def test_load_model_from_remote_with_str_cache_dir(self):
Expand Down
Loading