def test_persistents(self): with storage.PersistentList(self.filename) as db: db.append("persistent") self.assertIn("persistent", db) with storage.PersistentList(self.filename) as db: db.append("persistent2") self.assertIn("persistent", db) self.assertIn("persistent2", db)
def test_ttl(self): with open(self.path, "wb") as db: pickle.dump(["one", "two"], db, protocol=2) with storage.PersistentList(self.filename) as db: self.assertIn("one", db) self.assertIn("two", db) time.sleep(2) with storage.PersistentList(self.filename, 1) as db: self.assertNotIn("one", db) self.assertNotIn("two", db)
def test_set(self): with storage.PersistentList(self.filename) as db: db.append("old") db[0] = "data" self.assertIn("data", db) self.assertEqual(db[0], "data") self.assertNotIn("old", db)
def test_version_convert(self): with open(self.path, "wb") as db: pickle.dump(["one", "two"], db, protocol=2) with storage.PersistentList(self.filename) as db: self.assertIn("one", db) self.assertIn("two", db)
def test_search_populated_invalid(self): # noinspection PyUnusedLocal @route.Route.register def results(_, search_query): pass with storage.PersistentList(search.SEARCH_DB) as db: db.append("Pop") db.flush() with testing.mock_keyboard(""): listitems = search.SavedSearches.test(search=True, route=results.route.path, execute_delayed=True) with storage.PersistentList(search.SEARCH_DB) as db: self.assertIn("Pop", db) self.assertEqual(len(listitems), 2) self.assertIn("Search", listitems[0].label) self.assertEqual(listitems[1].label, "Pop")
def test_saved_remove(self): # noinspection PyUnusedLocal @route.Route.register def results(_, search_query): pass with storage.PersistentList(search.SEARCH_DB) as db: db.append("Rock") db.append("Pop") db.flush() listitems = search.SavedSearches.test(remove_entry="Rock", route=results.route.path, execute_delayed=True) with storage.PersistentList(search.SEARCH_DB) as db: self.assertNotIn("Rock", db) self.assertIn("Pop", db) self.assertEqual(len(listitems), 2) self.assertIn("Search", listitems[0].label) self.assertEqual(listitems[1].label, "Pop")
def test_search_populated(self): @route.Route.register def results(_, search_query): self.assertEqual(search_query, "Rock") yield Listitem.from_dict(results, "listitem one") yield Listitem.from_dict(results, "listitem two") with storage.PersistentList(search.SEARCH_DB) as db: db.append("Pop") db.flush() with testing.mock_keyboard("Rock"): listitems = search.SavedSearches.test(search=True, route=results.route.path, execute_delayed=True) with storage.PersistentList(search.SEARCH_DB) as db: self.assertIn("Rock", db) self.assertIn("Pop", db) self.assertEqual(len(listitems), 2) self.assertEqual(listitems[0].label, "listitem one") self.assertEqual(listitems[1].label, "listitem two")
def test_first_load_canceled(self): # noinspection PyUnusedLocal @route.Route.register def results(_, search_query): pass with testing.mock_keyboard(""): listitems = search.SavedSearches.test(first_load=True, route=results.route.path, execute_delayed=True) with storage.PersistentList(search.SEARCH_DB) as db: self.assertFalse(bool(db)) self.assertFalse(listitems)
def test_first_load_invalid(self): @route.Route.register def results(_, search_query): self.assertEqual(search_query, "Rock") return False with testing.mock_keyboard("Rock"): listitems = search.SavedSearches.test(first_load=True, route=results.route.path, execute_delayed=True) with storage.PersistentList(search.SEARCH_DB) as db: self.assertNotIn("Rock", db) self.assertFalse(listitems)
def test_flush_with_missing_dir(self): shutil.rmtree(storage.profile_dir) with storage.PersistentList(self.filename) as db: db.append("data") db.flush() self.assertIn("data", db)
def test_len(self): with storage.PersistentList(self.filename) as db: db.extend(["one", "two"]) self.assertEqual(len(db), 2)
def test_insert(self): with storage.PersistentList(self.filename) as db: db.insert(0, "one") self.assertEqual(db[0], "one")
def test_del(self): with storage.PersistentList(self.filename) as db: db.append("data") del db[0] self.assertNotIn("data", db)
def test_get(self): with storage.PersistentList(self.filename) as db: db.append("data") self.assertEqual(db[0], "data")
def test_create_filename_full(self): with storage.PersistentList(self.path) as db: self.assertFalse(db) self.assertIsNone(db._stream)
def test_flush_with_data(self): with storage.PersistentList(self.filename) as db: db.append("data") db.flush() self.assertIn("data", db)
def test_flush_no_data(self): with storage.PersistentList(self.filename) as db: db.flush()