Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
    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)
Exemplo n.º 3
0
 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)
Exemplo n.º 4
0
    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)
Exemplo n.º 5
0
    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")
Exemplo n.º 6
0
    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")
Exemplo n.º 7
0
    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")
Exemplo n.º 8
0
    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)
Exemplo n.º 9
0
    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)
Exemplo n.º 10
0
 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)
Exemplo n.º 11
0
 def test_len(self):
     with storage.PersistentList(self.filename) as db:
         db.extend(["one", "two"])
         self.assertEqual(len(db), 2)
Exemplo n.º 12
0
 def test_insert(self):
     with storage.PersistentList(self.filename) as db:
         db.insert(0, "one")
         self.assertEqual(db[0], "one")
Exemplo n.º 13
0
 def test_del(self):
     with storage.PersistentList(self.filename) as db:
         db.append("data")
         del db[0]
         self.assertNotIn("data", db)
Exemplo n.º 14
0
 def test_get(self):
     with storage.PersistentList(self.filename) as db:
         db.append("data")
         self.assertEqual(db[0], "data")
Exemplo n.º 15
0
 def test_create_filename_full(self):
     with storage.PersistentList(self.path) as db:
         self.assertFalse(db)
         self.assertIsNone(db._stream)
Exemplo n.º 16
0
 def test_flush_with_data(self):
     with storage.PersistentList(self.filename) as db:
         db.append("data")
         db.flush()
         self.assertIn("data", db)
Exemplo n.º 17
0
 def test_flush_no_data(self):
     with storage.PersistentList(self.filename) as db:
         db.flush()