def test_static(self): loader = StubLoader() ds = BaseDataset(loader, self.SCHEMA) self.assertTrue(ds.is_static()) self.assertEqual(3, len(ds)) self.assertEqual({'value': 1}, dict(ds[0].num_values)) self.assertEqual({'value': 2}, dict(ds[1].num_values)) self.assertEqual({'value': 3}, dict(ds[2].num_values)) self.assertEqual({'v': 1}, dict(ds.get(0))) self.assertEqual({'v': 2}, dict(ds.get(1))) self.assertEqual({'v': 3}, dict(ds.get(2))) ds2 = ds[(1,2)] self.assertEqual(2, len(ds2)) self.assertEqual({'value': 2}, dict(ds2[0].num_values)) self.assertEqual({'value': 3}, dict(ds2[1].num_values)) self.assertEqual({'v': 2}, dict(ds2.get(0))) self.assertEqual({'v': 3}, dict(ds2.get(1))) expected_idx = 0 for (idx, row) in ds: self.assertEqual(expected_idx, idx) self.assertEqual({'value': idx+1}, dict(row.num_values)) expected_idx += 1
def test_static(self): loader = StubLoader() ds = BaseDataset(loader, self.SCHEMA) self.assertTrue(ds.is_static()) self.assertEqual(3, len(ds)) self.assertEqual({'value': 1}, dict(ds[0].num_values)) self.assertEqual({'value': 2}, dict(ds[1].num_values)) self.assertEqual({'value': 3}, dict(ds[2].num_values)) self.assertEqual({'v': 1}, dict(ds.get(0))) self.assertEqual({'v': 2}, dict(ds.get(1))) self.assertEqual({'v': 3}, dict(ds.get(2))) ds2 = ds[(1, 2)] self.assertEqual(2, len(ds2)) self.assertEqual({'value': 2}, dict(ds2[0].num_values)) self.assertEqual({'value': 3}, dict(ds2[1].num_values)) self.assertEqual({'v': 2}, dict(ds2.get(0))) self.assertEqual({'v': 3}, dict(ds2.get(1))) expected_idx = 0 for (idx, row) in ds: self.assertEqual(expected_idx, idx) self.assertEqual({'value': idx + 1}, dict(row.num_values)) expected_idx += 1
def test_infinite(self): loader = StubInfiniteLoader() ds = BaseDataset(loader, self.SCHEMA) self.assertFalse(ds.is_static()) expected_idx = 0 for (idx, row) in ds: self.assertEqual(expected_idx, idx) self.assertEqual({'value': idx+1}, dict(row.num_values)) expected_idx += 1 if 10 < expected_idx: break
def test_nonstatic(self): loader = StubLoader() ds = BaseDataset(loader, self.SCHEMA, False) self.assertFalse(ds.is_static()) expected_idx = 0 for (idx, row) in ds: self.assertEqual(expected_idx, idx) self.assertEqual({'value': idx+1}, dict(row.num_values)) self.assertEqual(row.num_values, ds[idx].num_values) self.assertEqual({'v': idx+1}, ds.get(idx)) expected_idx += 1
def test_infinite(self): loader = StubInfiniteLoader() ds = BaseDataset(loader, self.SCHEMA) self.assertFalse(ds.is_static()) expected_idx = 0 for (idx, row) in ds: self.assertEqual(expected_idx, idx) self.assertEqual({'value': idx + 1}, dict(row.num_values)) expected_idx += 1 if 10 < expected_idx: break
def test_nonstatic(self): loader = StubLoader() ds = BaseDataset(loader, self.SCHEMA, False) self.assertFalse(ds.is_static()) expected_idx = 0 for (idx, row) in ds: self.assertEqual(expected_idx, idx) self.assertEqual({'value': idx + 1}, dict(row.num_values)) self.assertEqual(row.num_values, ds[idx].num_values) self.assertEqual({'v': idx + 1}, ds.get(idx)) expected_idx += 1