Skip to content

Commit

Permalink
added tests for ignore setting
Browse files Browse the repository at this point in the history
  • Loading branch information
niposch committed Jan 23, 2024
1 parent c143e13 commit f9e7f35
Show file tree
Hide file tree
Showing 4 changed files with 163 additions and 0 deletions.
45 changes: 45 additions & 0 deletions tests/anki/test_ignore_setting.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import re
import pytest
from anki.errors import NotFoundError # noqa
from anki.collection import Collection
from anki.collection import SearchNode

# from conftest import col

test_name = "ignore_setting"
col_path = "tests/test_outputs/{}/Anki2/User 1/collection.anki2".format(test_name)
included_file_path = "tests/test_outputs/{}/Obsidian/{}/{}.md".format(
test_name, test_name, test_name + "_included"
)

ignored_file_path = "tests/test_outputs/{}/Obsidian/{}/{}.md".format(
test_name, test_name, test_name + "_ignored"
)


@pytest.fixture()
def col():
col = Collection(col_path)
yield col
col.close()


def test_should_only_add_included(col: Collection):
assert len(col.find_cards(col.build_search_string(SearchNode(deck="Default")))) == 4


def test_included_cards_added(col: Collection):
ID_REGEXP_STR = r"\n?(?:<!--)?(?:ID: (\d+).*)"
obsidian_test_md = included_file_path

obs_IDs = []
with open(obsidian_test_md) as file:
for line in file:
output = re.search(ID_REGEXP_STR, line.rstrip())
if output is not None:
output = output.group(1)
obs_IDs.append(output)

anki_IDs = col.find_notes(col.build_search_string(SearchNode(deck="Default")))
for aid, oid in zip(anki_IDs, obs_IDs):
assert str(aid) == oid
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{
"settings": {
"CUSTOM_REGEXPS": {
"Basic": "",
"Basic (and reversed card)": "",
"Basic (optional reversed card)": "",
"Basic (type in the answer)": "",
"Cloze": ""
},
"FILE_LINK_FIELDS": {
"Basic": "Front",
"Basic (and reversed card)": "Front",
"Basic (optional reversed card)": "Front",
"Basic (type in the answer)": "Front",
"Cloze": "Text"
},
"CONTEXT_FIELDS": {},
"FOLDER_DECKS": {},
"FOLDER_TAGS": {},
"Syntax": {
"Begin Note": "START",
"End Note": "END",
"Begin Inline Note": "STARTI",
"End Inline Note": "ENDI",
"Target Deck Line": "TARGET DECK",
"File Tags Line": "FILE TAGS",
"Delete Note Line": "DELETE",
"Frozen Fields Line": "FROZEN"
},
"Defaults": {
"Scan Directory": "",
"Tag": "Obsidian_to_Anki",
"Deck": "Default",
"Scheduling Interval": 0,
"Add File Link": false,
"Add Context": false,
"CurlyCloze": true,
"CurlyCloze - Highlights to Clozes": false,
"ID Comments": true,
"Add Obsidian Tags": false
},
"IGNORED_FILE_GLOBS": [
"ignore_setting*/*ignored/**"
]
},
"Added Media": [],
"File Hashes": {},
"fields_dict": {
"Basic": [
"Front",
"Back"
],
"Basic (and reversed card)": [
"Front",
"Back"
],
"Basic (optional reversed card)": [
"Front",
"Back",
"Add Reverse"
],
"Basic (type in the answer)": [
"Front",
"Back"
],
"Cloze": [
"Text",
"Back Extra"
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!-- NOT A CARD BECAUSE ITS IGNORED -->
START
Basic
This is a test.
Back: Test successful!
Tags: Testing
END

<!-- NOT A CARD BECAUSE ITS IGNORED -->
START
Basic
Front: This is a test with Front specified.
Back: Test successful!
Tags: Testing 2
END

<!-- NOT A CARD BECAUSE ITS IGNORED -->
START
Basic
This is a test.
And the test is continuing.
Back: Test successful!
END
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

<!-- CARD -->
START
Basic
This is a test.
Back: Test successful!
Tags: Testing
END

<!-- CARD -->
START
Basic
Front: This is a test with Front specified.
Back: Test successful!
Tags: Testing 2
END

<!-- CARD -->
START
Basic
This is a test.
And the test is continuing.
Back: Test successful!
END

0 comments on commit f9e7f35

Please sign in to comment.