Exemplo n.º 1
0
def test_read_write_identical_trivial(db_path, tmpdir):
    db_path = shutil.copy2(str(db_path), str(tmpdir))
    (pathlib.Path(str(tmpdir)) / "backups").mkdir()
    col = Collection(db_path)
    col.write(modify=True, delete=True, add=True)
    col_rel = Collection(db_path)
    assert col.notes.equals(col_rel.notes)
    assert col.cards.equals(col_rel.cards)
    assert col.revs.equals(col_rel.revs)
Exemplo n.º 2
0
 def test_read_write_identical_trivial(self):
     with tempfile.TemporaryDirectory() as tmpdir:
         db_path = shutil.copy2(str(self.db_path), tmpdir)
         (pathlib.Path(tmpdir) / "backups").mkdir()
         col = Collection(db_path)
         col.write(modify=True, delete=True, add=True)
         col_rel = Collection(db_path)
         self.assertTrue(col.notes.equals(col_rel.notes))
         self.assertTrue(col.cards.equals(col_rel.cards))
         self.assertTrue(col.revs.equals(col_rel.revs))
Exemplo n.º 3
0
def test_write_added(db_path, tmpdir):
    db_path = shutil.copy2(str(db_path), str(tmpdir))
    (pathlib.Path(str(tmpdir)) / "backups").mkdir()
    col = Collection(db_path)
    _init_all_tables(col)
    col.notes.add_note("Basic", ["test", "back"], inplace=True)
    col.write(add=True)
Exemplo n.º 4
0
    def setUp(self):
        self.db_path = (pathlib.Path(__file__).parent / "data" /
                        "few_basic_cards" / "collection.anki2")

        self.col = Collection(self.db_path)
        self.notes = self.col.notes
        self.cards = self.col.cards
        self.revs = self.col.revs
Exemplo n.º 5
0
def test_summarize_changes_no_changes(db_path):
    col = Collection(db_path)
    _init_all_tables(col)
    col.summarize_changes()
    sc = col.summarize_changes(output="dict")
    for item in ["cards", "revs", "notes"]:
        assert sc[item]["n_modified"] == 0
        assert sc[item]["n_added"] == 0
        assert sc[item]["n_deleted"] == 0
        assert not sc[item]["has_changed"]
Exemplo n.º 6
0
def test_write_raises_modified(db_path, tmpdir):
    db_path = shutil.copy2(str(db_path), str(tmpdir))
    (pathlib.Path(str(tmpdir)) / "backups").mkdir()
    col = Collection(db_path)
    col.notes.add_tag("test", inplace=True)
    cases = [
        dict(add=False, delete=True),
        dict(add=True, delete=False),
        dict(add=True, delete=True),
    ]
    for case in cases:
        with pytest.raises(ValueError, match=".*would be modified.*"):
            col.write(**case, modify=False)
Exemplo n.º 7
0
def test_write_raises_delete(db_path, tmpdir):
    db_path = shutil.copy2(str(db_path), str(tmpdir))
    (pathlib.Path(str(tmpdir)) / "backups").mkdir()
    col = Collection(db_path)
    _init_all_tables(col)
    col.notes.drop(col.notes.index, inplace=True)
    cases = [
        dict(modify=False, add=True),
        dict(modify=True, add=False),
        dict(modify=True, add=True),
    ]
    for case in cases:
        with pytest.raises(ValueError, match=".*would be deleted.*"):
            col.write(**case, delete=False)
Exemplo n.º 8
0
 def test_write_raises_added(self):
     with tempfile.TemporaryDirectory() as tmpdir:
         db_path = shutil.copy2(str(self.db_path), tmpdir)
         (pathlib.Path(tmpdir) / "backups").mkdir()
         col = Collection(db_path)
         col.notes.add_note("Basic", ["test", "back"], inplace=True)
         cases = [
             dict(modify=False, delete=True),
             dict(modify=True, delete=False),
             dict(modify=True, delete=True),
         ]
         for case in cases:
             with self.subTest(**case):
                 with self.assertRaises(ValueError) as context:
                     col.write(**case, add=False)
                 self.assertTrue(
                     "would be modified" in str(context.exception))
Exemplo n.º 9
0
    def setUp(self):
        set_debug_log_level()
        self.db = raw.load_db(self.db_path)

        self.col = Collection(self.db_path)

        # Do not modify this one!
        self.notes = self.col.notes
        self.cards = self.col.cards
        self.revs = self.col.revs
        self.table2adf = {
            "notes": self.notes,
            "cards": self.cards,
            "revs": self.revs,
        }
        self.adfs = [self.notes, self.cards, self.revs]

        self.empty_notes = self.col.empty_notes()
        self.empty_cards = self.col.empty_cards()
        self.empty_revs = self.col.empty_revs()
Exemplo n.º 10
0
    def setUp(self):
        self.db_path = (pathlib.Path(__file__).parent / "data" /
                        "few_basic_cards" / "collection.anki2")
        self.db = raw.load_db(self.db_path)

        self.col = Collection(self.db_path)

        # Do not modify this one!
        self.notes = self.col.notes
        self.cards = self.col.cards
        self.revs = self.col.revs
        self.table2adf = {
            "notes": self.notes,
            "cards": self.cards,
            "revs": self.revs,
        }
        self.adfs = [self.notes, self.cards, self.revs]

        self.empty_notes = self.col.empty_notes()
        self.empty_cards = self.col.empty_cards()
        self.empty_revs = self.col.empty_revs()
Exemplo n.º 11
0
def test_summarize_notes_changed(db_path):
    col = Collection(db_path)
    col.notes.add_tag("this_will_be_modified", inplace=True)
    sc = col.summarize_changes(output="dict")
    assert sc["notes"]["n_modified"] == sc["notes"]["n"]
Exemplo n.º 12
0
def test_summarize_changes_uninitialized(db_path):
    col = Collection(db_path)
    sc = col.summarize_changes(output="dict")
    assert len(sc) == 0
Exemplo n.º 13
0
def test_inplace_merge_notes(db_path):
    """https://github.com/klieret/AnkiPandas/issues/51
    AttributeError: 'NoneType' object has no attribute 'col'
    """
    col = Collection(db_path)
    col.cards.merge_notes(inplace=True)
Exemplo n.º 14
0
 def test_summarize_notes_changed(self):
     col = Collection(self.db_path)
     col.notes.add_tag("this_will_be_modified", inplace=True)
     sc = col.summarize_changes(output="dict")
     self.assertEqual(sc["notes"]["n_modified"], sc["notes"]["n"])
Exemplo n.º 15
0
 def test_summarize_changes_uninitialized(self):
     col = Collection(self.db_path)
     sc = col.summarize_changes(output="dict")
     self.assertEqual(len(sc), 0)