add pytest to CI pipeline (#286)

This commit is contained in:
Jiri
2024-06-14 06:29:22 +08:00
committed by GitHub
parent 5bc80a043f
commit aa2925cde0
14 changed files with 172 additions and 18 deletions

View File

@@ -80,7 +80,7 @@ class Entry:
# self.word_count: int = None
def __str__(self) -> str:
return f"\n{self.compressed_dict()}\n"
return str(self.compressed_dict())
def __repr__(self) -> str:
return self.__str__()

View File

@@ -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)

View File

@@ -0,0 +1,6 @@
[
[
"<ItemType.ENTRY: 0>",
2
]
]

View File

@@ -0,0 +1,6 @@
[
[
"<ItemType.ENTRY: 0>",
1
]
]

View File

@@ -0,0 +1,4 @@
[
"{'id': 1, 'filename': 'foo.txt', 'path': '.', 'fields': [{6: [1001]}]}",
"{'id': 2, 'filename': 'bar.txt', 'path': '.', 'fields': [{6: [1000]}]}"
]

View File

@@ -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

View File

@@ -1,18 +1,8 @@
from src.core.library import Tag
def test_subtag(test_tag):
test_tag.remove_subtag(2)
test_tag.remove_subtag(2)
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
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]

View File

@@ -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
]
}
]
}
]
}

View File

View File