Skip to content

Commit f1d2789

Browse files
committed
Add tests
The test framework is [pytest](https://docs.pytest.org/en/stable/). Setup: ```shell pip install pytest ./nova3/aux/fetch_aux.sh ``` Run tests: ```shell pytest nova3/tests/*.py ``` Note that for unknown reasons the tests will fail when run on Github CI with Python 3.9. So the tests are only run with Python 3.10.
1 parent 7f55dff commit f1d2789

17 files changed

+149
-20
lines changed

.github/workflows/ci.yaml

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,36 @@ jobs:
2929
python-version: ${{ matrix.python-version }}
3030

3131
- name: Install tools
32-
run: pip install bandit isort pycodestyle pyflakes
32+
run: pip install bandit isort mypy pycodestyle pyflakes pyright pytest
33+
34+
- name: Run tests
35+
if: matrix.python-version == '3.10' # avoid hammering the sites
36+
continue-on-error: true
37+
run: |
38+
./nova3/aux/fetch_aux.sh
39+
pytest \
40+
--showlocals \
41+
nova3/tests/*.py
42+
43+
- name: Check typings
44+
run: |
45+
mypy \
46+
--follow-imports skip \
47+
--strict \
48+
nova3/tests/*.py
49+
pyright \
50+
--skipunannotated \
51+
nova3/tests/*.py
3352
3453
- name: Lint code
3554
run: |
36-
pyflakes nova3/engines/*.py
37-
bandit --skip B110,B310,B314,B405 nova3/engines/*.py
55+
pyflakes \
56+
nova3/engines/*.py \
57+
nova3/tests/*.py
58+
bandit \
59+
--skip B101,B110,B310,B314,B405 \
60+
nova3/engines/*.py \
61+
nova3/tests/*.py
3862
3963
- name: Format code
4064
run: |
@@ -43,11 +67,13 @@ jobs:
4367
--ignore=E265,W503 \
4468
--max-line-length=1000 \
4569
--statistics \
46-
nova3/engines/*.py
70+
nova3/engines/*.py \
71+
nova3/tests/*.py
4772
isort \
4873
--check \
4974
--diff \
50-
nova3/engines/*.py
75+
nova3/engines/*.py \
76+
nova3/tests/*.py
5177
5278
- name: Build code
5379
run: |

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,7 @@
66
*.pyc
77

88
# Plugin config
9-
/nova3/engines/jackett.json
9+
nova3/engines/jackett.json
10+
11+
# Auxiliary files for testing
12+
nova3/aux

nova3/__init__.py

Whitespace-only changes.

nova3/aux/fetch_aux.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/sh
2+
3+
cd "$(dirname "$0")" || exit
4+
git clone --depth 1 https://github.com/qbittorrent/qBittorrent.git
5+
mv qBittorrent/src/searchengine/nova3/* ./
6+
rm -rf qBittorrent __init__.py

nova3/engines/eztv.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# VERSION: 1.18
1+
# VERSION: 1.19
22
# AUTHORS: nindogo
33
# CONTRIBUTORS: Diego de las Heras ([email protected])
44

@@ -104,8 +104,3 @@ def search(self, what, cat='all'):
104104
eztv_parser = self.MyHtmlParser(self.url)
105105
eztv_parser.feed(eztv_html)
106106
eztv_parser.close()
107-
108-
109-
if __name__ == '__main__':
110-
eztv_se = eztv()
111-
eztv_se.search('Acre', 'all')

nova3/engines/jackett.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# VERSION: 4.3
1+
# VERSION: 4.4
22
# AUTHORS: Diego de las Heras ([email protected])
33
# CONTRIBUTORS: ukharley
44
# hannsen (github.com/hannsen)
@@ -279,8 +279,3 @@ def escape_pipe(self, dictionary):
279279
if isinstance(dictionary[key], str):
280280
dictionary[key] = dictionary[key].replace('|', '%7C')
281281
return dictionary
282-
283-
284-
if __name__ == "__main__":
285-
jackett_se = jackett()
286-
jackett_se.search("ubuntu server", 'software')

nova3/engines/versions.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
eztv: 1.18
2-
jackett: 4.3
1+
eztv: 1.19
2+
jackett: 4.4
33
limetorrents: 4.11
44
piratebay: 3.7
55
solidtorrents: 2.5

nova3/pyproject.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[tool.mypy]
2+
mypy_path = "aux"
3+
4+
[tool.pyright]
5+
include = ["aux"]
6+
7+
[tool.pytest.ini_options]
8+
pythonpath = "aux"

nova3/tests/__init__.py

Whitespace-only changes.

nova3/tests/test_eztv.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import pytest
2+
3+
from ..engines import eztv
4+
5+
6+
def test_eztv(capfd: pytest.CaptureFixture[str]) -> None:
7+
engine = eztv.eztv()
8+
engine.search('linux', 'all')
9+
10+
capturedOutput = capfd.readouterr()
11+
assert capturedOutput.err == ""
12+
assert len(capturedOutput.out) >= 0

0 commit comments

Comments
 (0)