testing no inplace change to the hashed item
(self)
| 64 | |
| 65 | class TestDataset(unittest.TestCase): |
| 66 | def test_cache(self): |
| 67 | """testing no inplace change to the hashed item""" |
| 68 | items = [[list(range(i))] for i in range(5)] |
| 69 | |
| 70 | with tempfile.TemporaryDirectory() as tempdir: |
| 71 | ds = PersistentDataset( |
| 72 | data=items, |
| 73 | transform=_InplaceXform(), |
| 74 | cache_dir=tempdir, |
| 75 | pickle_module="pickle", |
| 76 | # TODO: was pickle.HIGHEST_PROTOCOL but this wasn't compatible with torch.load, need to improve compatibility |
| 77 | pickle_protocol=torch.serialization.DEFAULT_PROTOCOL, |
| 78 | ) |
| 79 | self.assertEqual(items, [[[]], [[0]], [[0, 1]], [[0, 1, 2]], [[0, 1, 2, 3]]]) |
| 80 | ds1 = PersistentDataset(items, transform=_InplaceXform(), cache_dir=tempdir) |
| 81 | self.assertEqual(list(ds1), list(ds)) |
| 82 | self.assertEqual(items, [[[]], [[0]], [[0, 1]], [[0, 1, 2]], [[0, 1, 2, 3]]]) |
| 83 | |
| 84 | ds = PersistentDataset(items, transform=_InplaceXform(), cache_dir=tempdir, hash_func=json_hashing) |
| 85 | self.assertEqual(items, [[[]], [[0]], [[0, 1]], [[0, 1, 2]], [[0, 1, 2, 3]]]) |
| 86 | ds1 = PersistentDataset(items, transform=_InplaceXform(), cache_dir=tempdir, hash_func=json_hashing) |
| 87 | self.assertEqual(list(ds1), list(ds)) |
| 88 | self.assertEqual(items, [[[]], [[0]], [[0, 1]], [[0, 1, 2]], [[0, 1, 2, 3]]]) |
| 89 | |
| 90 | @parameterized.expand([TEST_CASE_1, TEST_CASE_2, TEST_CASE_3]) |
| 91 | def test_shape(self, transform, expected_shape): |
nothing calls this directly
no test coverage detected