-
Notifications
You must be signed in to change notification settings - Fork 386
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
1 parent
5bc80a0
commit 7bb52d1
Showing
14 changed files
with
173 additions
and
19 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,22 @@ | ||
name: pytest | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
pytest: | ||
name: Run tests | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repo | ||
uses: actions/checkout@v4 | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -r requirements.txt | ||
pip install -r requirements-dev.txt | ||
- name: Run tests | ||
run: | | ||
pytest tagstudio/tests/ |
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
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 |
---|---|---|
|
@@ -3,3 +3,4 @@ pre-commit==3.7.0 | |
pytest==8.2.0 | ||
Pyinstaller==6.6.0 | ||
mypy==1.10.0 | ||
syrupy==4.6.1 |
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
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,36 @@ | ||
import sys | ||
import pathlib | ||
|
||
import pytest | ||
from syrupy.extensions.json import JSONSnapshotExtension | ||
|
||
CWD = pathlib.Path(__file__).parent | ||
|
||
sys.path.insert(0, str(CWD.parent)) | ||
|
||
from src.core.library import Tag, Library | ||
|
||
|
||
@pytest.fixture | ||
def test_tag(): | ||
yield Tag( | ||
id=1, | ||
name="Tag Name", | ||
shorthand="TN", | ||
aliases=["First A", "Second A"], | ||
subtags_ids=[2, 3, 4], | ||
color="", | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def test_library(): | ||
lib = Library() | ||
ret_code = lib.open_library(CWD / "fixtures" / "library") | ||
assert ret_code == 1 | ||
yield lib | ||
|
||
|
||
@pytest.fixture | ||
def snapshot_json(snapshot): | ||
return snapshot.with_defaults(extension_class=JSONSnapshotExtension) |
1 change: 1 addition & 0 deletions
1
tagstudio/tests/core/__snapshots__/test_lib/test_library_search[--nomatch--].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 @@ | ||
[] |
6 changes: 6 additions & 0 deletions
6
tagstudio/tests/core/__snapshots__/test_lib/test_library_search[First].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,6 @@ | ||
[ | ||
[ | ||
"<ItemType.ENTRY: 0>", | ||
2 | ||
] | ||
] |
6 changes: 6 additions & 0 deletions
6
tagstudio/tests/core/__snapshots__/test_lib/test_library_search[Second].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,6 @@ | ||
[ | ||
[ | ||
"<ItemType.ENTRY: 0>", | ||
1 | ||
] | ||
] |
4 changes: 4 additions & 0 deletions
4
tagstudio/tests/core/__snapshots__/test_lib/test_open_library.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,4 @@ | ||
[ | ||
"{'id': 1, 'filename': 'foo.txt', 'path': '.', 'fields': [{6: [1001]}]}", | ||
"{'id': 2, 'filename': 'bar.txt', 'path': '.', 'fields': [{6: [1000]}]}" | ||
] |
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,18 @@ | ||
import pytest | ||
|
||
|
||
def test_open_library(test_library, snapshot_json): | ||
assert test_library.entries == snapshot_json | ||
|
||
|
||
@pytest.mark.parametrize( | ||
["query"], | ||
[ | ||
("First",), | ||
("Second",), | ||
("--nomatch--",), | ||
], | ||
) | ||
def test_library_search(test_library, query, snapshot_json): | ||
res = test_library.search_library(query) | ||
assert res == snapshot_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 |
---|---|---|
@@ -1,18 +1,8 @@ | ||
from src.core.library import Tag | ||
|
||
|
||
def test_construction(): | ||
tag = Tag( | ||
id=1, | ||
name="Tag Name", | ||
shorthand="TN", | ||
aliases=["First A", "Second A"], | ||
subtags_ids=[2, 3, 4], | ||
color="", | ||
) | ||
assert tag | ||
|
||
|
||
def test_empty_construction(): | ||
tag = Tag(id=1, name="", shorthand="", aliases=[], subtags_ids=[], color="") | ||
assert tag | ||
def test_subtag(test_tag): | ||
test_tag.remove_subtag(2) | ||
test_tag.remove_subtag(2) | ||
|
||
test_tag.add_subtag(5) | ||
# repeated add should not add the subtag | ||
test_tag.add_subtag(5) | ||
assert test_tag.subtag_ids == [3, 4, 5] |
69 changes: 69 additions & 0 deletions
69
tagstudio/tests/fixtures/library/.TagStudio/ts_library.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,69 @@ | ||
{ | ||
"ts-version": "9.3.1", | ||
"ext_list": [ | ||
".json", | ||
".xmp", | ||
".aae" | ||
], | ||
"is_exclude_list": true, | ||
"tags": [ | ||
{ | ||
"id": 0, | ||
"name": "Archived", | ||
"aliases": [ | ||
"Archive" | ||
], | ||
"color": "Red" | ||
}, | ||
{ | ||
"id": 1, | ||
"name": "Favorite", | ||
"aliases": [ | ||
"Favorited", | ||
"Favorites" | ||
], | ||
"color": "Yellow" | ||
}, | ||
{ | ||
"id": 1000, | ||
"name": "first", | ||
"shorthand": "first", | ||
"color": "magenta" | ||
}, | ||
{ | ||
"id": 1001, | ||
"name": "second", | ||
"shorthand": "second", | ||
"color": "blue" | ||
} | ||
], | ||
"collations": [], | ||
"fields": [], | ||
"macros": [], | ||
"entries": [ | ||
{ | ||
"id": 1, | ||
"filename": "foo.txt", | ||
"path": ".", | ||
"fields": [ | ||
{ | ||
"6": [ | ||
1001 | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"id": 2, | ||
"filename": "bar.txt", | ||
"path": ".", | ||
"fields": [ | ||
{ | ||
"6": [ | ||
1000 | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} |
Empty file.
Empty file.