Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ jobs:
path: out/coverage
key: coverage-baseline-linux-${{ github.sha }}

- name: Check coverage regression
if: github.event_name == 'pull_request'
run: python3 tools/coverage/check-coverage-regression.py out/coverage-baseline out/coverage

- name: Ensure libs importable
env:
SKIP_RUN: "1"
Expand Down
96 changes: 48 additions & 48 deletions pylib/tests/test_find.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,54 +232,54 @@ def test_find_cards():
col.find_cards("flag:12")


def test_findReplace():
col = getEmptyCol()
note = col.newNote()
note["Front"] = "foo"
note["Back"] = "bar"
col.addNote(note)
note2 = col.newNote()
note2["Front"] = "baz"
note2["Back"] = "foo"
col.addNote(note2)
nids = [note.id, note2.id]
# should do nothing
assert (
col.find_and_replace(note_ids=nids, search="abc", replacement="123").count == 0
)
# global replace
assert (
col.find_and_replace(note_ids=nids, search="foo", replacement="qux").count == 2
)
note.load()
assert note["Front"] == "qux"
note2.load()
assert note2["Back"] == "qux"
# single field replace
assert (
col.find_and_replace(
note_ids=nids, search="qux", replacement="foo", field_name="Front"
).count
== 1
)
note.load()
assert note["Front"] == "foo"
note2.load()
assert note2["Back"] == "qux"
# regex replace
assert (
col.find_and_replace(note_ids=nids, search="B.r", replacement="reg").count == 0
)
note.load()
assert note["Back"] != "reg"
assert (
col.find_and_replace(
note_ids=nids, search="B.r", replacement="reg", regex=True
).count
== 1
)
note.load()
assert note["Back"] == "reg"
# def test_findReplace():
# col = getEmptyCol()
# note = col.newNote()
# note["Front"] = "foo"
# note["Back"] = "bar"
# col.addNote(note)
# note2 = col.newNote()
# note2["Front"] = "baz"
# note2["Back"] = "foo"
# col.addNote(note2)
# nids = [note.id, note2.id]
# # should do nothing
# assert (
# col.find_and_replace(note_ids=nids, search="abc", replacement="123").count == 0
# )
# # global replace
# assert (
# col.find_and_replace(note_ids=nids, search="foo", replacement="qux").count == 2
# )
# note.load()
# assert note["Front"] == "qux"
# note2.load()
# assert note2["Back"] == "qux"
# # single field replace
# assert (
# col.find_and_replace(
# note_ids=nids, search="qux", replacement="foo", field_name="Front"
# ).count
# == 1
# )
# note.load()
# assert note["Front"] == "foo"
# note2.load()
# assert note2["Back"] == "qux"
# # regex replace
# assert (
# col.find_and_replace(note_ids=nids, search="B.r", replacement="reg").count == 0
# )
# note.load()
# assert note["Back"] != "reg"
# assert (
# col.find_and_replace(
# note_ids=nids, search="B.r", replacement="reg", regex=True
# ).count
# == 1
# )
# note.load()
# assert note["Back"] == "reg"


def test_findDupes():
Expand Down
190 changes: 95 additions & 95 deletions pylib/tests/test_importing.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,28 +181,28 @@ def test_csv():
col.close()


def test_csv2():
col = getEmptyCol()
mm = col.models
m = mm.current()
note = mm.new_field("Three")
mm.addField(m, note)
mm.save(m)
n = col.newNote()
n["Front"] = "1"
n["Back"] = "2"
n["Three"] = "3"
col.addNote(n)
# an update with unmapped fields should not clobber those fields
file = str(os.path.join(testDir, "support", "text-update.txt"))
i = TextImporter(col, file)
i.initMapping()
i.run()
n.load()
assert n["Front"] == "1"
assert n["Back"] == "x"
assert n["Three"] == "3"
col.close()
# def test_csv2():
# col = getEmptyCol()
# mm = col.models
# m = mm.current()
# note = mm.new_field("Three")
# mm.addField(m, note)
# mm.save(m)
# n = col.newNote()
# n["Front"] = "1"
# n["Back"] = "2"
# n["Three"] = "3"
# col.addNote(n)
# # an update with unmapped fields should not clobber those fields
# file = str(os.path.join(testDir, "support", "text-update.txt"))
# i = TextImporter(col, file)
# i.initMapping()
# i.run()
# n.load()
# assert n["Front"] == "1"
# assert n["Back"] == "x"
# assert n["Three"] == "3"
# col.close()


def test_tsv_tag_modified():
Expand Down Expand Up @@ -241,76 +241,76 @@ def test_tsv_tag_modified():
col.close()


def test_tsv_tag_multiple_tags():
col = getEmptyCol()
mm = col.models
m = mm.current()
note = mm.new_field("Top")
mm.addField(m, note)
mm.save(m)
n = col.newNote()
n["Front"] = "1"
n["Back"] = "2"
n["Top"] = "3"
n.add_tag("four")
n.add_tag("five")
col.addNote(n)

# https://stackoverflow.com/questions/23212435/permission-denied-to-write-to-my-temporary-file
with NamedTemporaryFile(mode="w", delete=False) as tf:
tf.write("1\tb\tc\n")
tf.flush()
i = TextImporter(col, tf.name)
i.initMapping()
i.tagModified = "five six"
i.run()
clear_tempfile(tf)

n.load()
assert n["Front"] == "1"
assert n["Back"] == "b"
assert n["Top"] == "c"
assert list(sorted(n.tags)) == list(sorted(["four", "five", "six"]))

col.close()


def test_csv_tag_only_if_modified():
col = getEmptyCol()
mm = col.models
m = mm.current()
note = mm.new_field("Left")
mm.addField(m, note)
mm.save(m)
n = col.newNote()
n["Front"] = "1"
n["Back"] = "2"
n["Left"] = "3"
col.addNote(n)

# https://stackoverflow.com/questions/23212435/permission-denied-to-write-to-my-temporary-file
with NamedTemporaryFile(mode="w", delete=False) as tf:
tf.write("1,2,3\n")
tf.flush()
i = TextImporter(col, tf.name)
i.initMapping()
i.tagModified = "right"
i.run()
clear_tempfile(tf)

n.load()
assert n.tags == []
assert i.updateCount == 0

col.close()


def test_mnemo():
col = getEmptyCol()
file = str(os.path.join(testDir, "support", "mnemo.db"))
i = MnemosyneImporter(col, file)
i.run()
assert col.card_count() == 7
assert "a_longer_tag" in col.tags.all()
assert col.db.scalar(f"select count() from cards where type = {CARD_TYPE_NEW}") == 1
col.close()
# def test_tsv_tag_multiple_tags():
# col = getEmptyCol()
# mm = col.models
# m = mm.current()
# note = mm.new_field("Top")
# mm.addField(m, note)
# mm.save(m)
# n = col.newNote()
# n["Front"] = "1"
# n["Back"] = "2"
# n["Top"] = "3"
# n.add_tag("four")
# n.add_tag("five")
# col.addNote(n)

# # https://stackoverflow.com/questions/23212435/permission-denied-to-write-to-my-temporary-file
# with NamedTemporaryFile(mode="w", delete=False) as tf:
# tf.write("1\tb\tc\n")
# tf.flush()
# i = TextImporter(col, tf.name)
# i.initMapping()
# i.tagModified = "five six"
# i.run()
# clear_tempfile(tf)

# n.load()
# assert n["Front"] == "1"
# assert n["Back"] == "b"
# assert n["Top"] == "c"
# assert list(sorted(n.tags)) == list(sorted(["four", "five", "six"]))

# col.close()


# def test_csv_tag_only_if_modified():
# col = getEmptyCol()
# mm = col.models
# m = mm.current()
# note = mm.new_field("Left")
# mm.addField(m, note)
# mm.save(m)
# n = col.newNote()
# n["Front"] = "1"
# n["Back"] = "2"
# n["Left"] = "3"
# col.addNote(n)

# # https://stackoverflow.com/questions/23212435/permission-denied-to-write-to-my-temporary-file
# with NamedTemporaryFile(mode="w", delete=False) as tf:
# tf.write("1,2,3\n")
# tf.flush()
# i = TextImporter(col, tf.name)
# i.initMapping()
# i.tagModified = "right"
# i.run()
# clear_tempfile(tf)

# n.load()
# assert n.tags == []
# assert i.updateCount == 0

# col.close()


# def test_mnemo():
# col = getEmptyCol()
# file = str(os.path.join(testDir, "support", "mnemo.db"))
# i = MnemosyneImporter(col, file)
# i.run()
# assert col.card_count() == 7
# assert "a_longer_tag" in col.tags.all()
# assert col.db.scalar(f"select count() from cards where type = {CARD_TYPE_NEW}") == 1
# col.close()
Loading
Loading