Skip to content

Commit 2e0def1

Browse files
committed
use custom mapping
1 parent 78e5509 commit 2e0def1

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

tests/tests_pytorch/trainer/optimization/test_manual_optimization.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,26 @@ def on_train_epoch_end(self, *_, **__):
304304
trainer.fit(model)
305305

306306

307+
class CustomMapping(collections.abc.Mapping):
308+
"""A custom implementation of Mapping for testing purposes."""
309+
def __init__(self, *args, **kwargs):
310+
self._store = dict(*args, **kwargs)
311+
312+
def __getitem__(self, key):
313+
return self._store[key]
314+
315+
def __iter__(self):
316+
return iter(self._store)
317+
318+
def __len__(self):
319+
return len(self._store)
320+
321+
def __repr__(self):
322+
return f"{self.__class__.__name__}({self._store})"
323+
324+
307325
@RunIf(min_cuda_gpus=1)
308-
@pytest.mark.parametrize("dicttype", [dict, collections.OrderedDict])
326+
@pytest.mark.parametrize("dicttype", [dict, CustomMapping])
309327
def test_multiple_optimizers_step(tmp_path, dicttype):
310328
"""Tests that `step` works with several optimizers."""
311329

0 commit comments

Comments
 (0)