-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
163 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
71 changes: 71 additions & 0 deletions
71
...ults/test_vault_suites/ignore_setting/.obsidian/plugins/obsidian-to-anki-plugin/data.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...st_vault_suites/ignore_setting/ignore_setting_ignored/ignore_setting_ignored.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
24 changes: 24 additions & 0 deletions
24
tests/defaults/test_vault_suites/ignore_setting/ignore_setting_included.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |