def setUp(self): self.ts = TierStore(self.tmp_dir, self.lines_per_store, self.prefix)
class TierStoreTest(unittest.TestCase): tmp_dir = tempfile.gettempdir() prefix = "test" lines_per_store = 10 def setUp(self): self.ts = TierStore(self.tmp_dir, self.lines_per_store, self.prefix) def tearDown(self): pass def check_store_label(self, label): tier = self.ts._stores[label] self.assertIsNotNone(tier) self.assertTrue(label in tier._file.name) def check_write_line_store(self, label, n_lines, expected, text): for i in range(n_lines): self.ts.store(text + label, label) tier = self.ts._stores[label] self.assertEqual(expected, tier._stored_matches) def test_store_creation(self): text = "test_store_creation" label = "tier" self.ts.store(text, label) self.check_store_label(label) tier = self.ts._stores[label] self.assertEqual(1, tier._stored_matches) def test_multiple_stores(self): text = "test_multiple_stores " label1 = "test1" label2 = "test2" self.ts.store(text + label1, label1) self.ts.store(text + label2, label2) self.check_store_label(label1) self.check_store_label(label2) self.assertEqual(1, self.ts._stores[label1]._stored_matches) self.assertEqual(1, self.ts._stores[label2]._stored_matches) lines = self.lines_per_store - 2 self.check_write_line_store(label1, lines, lines + 1, text) self.check_write_line_store(label2, lines, lines + 1, text) def test_multiple_file_one_store(self): text = "test_multiple_file_one_store" label1 = "test_1" self.check_write_line_store(label1, 2 * self.lines_per_store + 5, 5, text) def test_multiple_file_multiple_store(self): text = "test_multiple_file_multiple_store" for i in range(5): self.check_write_line_store("label " + str(i), 2 * self.lines_per_store + 5, 5, text) def test_auto_closing(self): with closing(self.ts): self.test_multiple_file_multiple_store() for store in list(self.ts._stores.values()): self.assertIsNone(store._file)
class TierStoreTest(unittest.TestCase): tmp_dir = tempfile.gettempdir() prefix = "test" lines_per_store = 10 def setUp(self): self.ts = TierStore(self.tmp_dir, self.lines_per_store, self.prefix) def tearDown(self): pass def check_store_label(self, label): tier = self.ts._stores[label] self.assertIsNotNone(tier) self.assertTrue(label in tier._file.name) def check_write_line_store(self, label, n_lines, expected, text): for i in range(n_lines): self.ts.store(text + label, label) tier = self.ts._stores[label] self.assertEqual(expected, tier._stored_matches) def test_store_creation(self): text = "test_store_creation" label = "tier" self.ts.store(text, label) self.check_store_label(label) tier = self.ts._stores[label] self.assertEqual(1, tier._stored_matches) def test_multiple_stores(self): text = "test_multiple_stores " label1 = "test1" label2 = "test2" self.ts.store(text + label1, label1) self.ts.store(text + label2, label2) self.check_store_label(label1) self.check_store_label(label2) self.assertEqual(1, self.ts._stores[label1]._stored_matches) self.assertEqual(1, self.ts._stores[label2]._stored_matches) lines = self.lines_per_store -2 self.check_write_line_store(label1, lines, lines+1, text) self.check_write_line_store(label2, lines, lines+1, text) def test_multiple_file_one_store(self): text = "test_multiple_file_one_store" label1 = "test_1" self.check_write_line_store(label1, 2*self.lines_per_store +5, 5, text) def test_multiple_file_multiple_store(self): text = "test_multiple_file_multiple_store" for i in range(5): self.check_write_line_store("label " + str(i), 2*self.lines_per_store +5, 5, text) def test_auto_closing(self): with closing(self.ts): self.test_multiple_file_multiple_store() for store in self.ts._stores.values(): self.assertIsNone(store._file)