Tests: make tests pass for Anki 2.1.50 (Qt5)
* require Python 3.10 * prevent Anki from doing backups, again * restore cwd that deck exporter changes for some wild reason
This commit is contained in:
parent
a433f600a4
commit
e025a44ea3
9
.github/workflows/main.yml
vendored
9
.github/workflows/main.yml
vendored
@ -12,8 +12,15 @@ jobs:
|
|||||||
sudo apt-get update
|
sudo apt-get update
|
||||||
sudo apt-get install -y pyqt5-dev-tools xvfb
|
sudo apt-get install -y pyqt5-dev-tools xvfb
|
||||||
|
|
||||||
- name: Setup Python
|
- name: Setup Python 3.8
|
||||||
uses: actions/setup-python@v2
|
uses: actions/setup-python@v2
|
||||||
|
with:
|
||||||
|
python-version: 3.8
|
||||||
|
|
||||||
|
- name: Setup Python 3.9
|
||||||
|
uses: actions/setup-python@v2
|
||||||
|
with:
|
||||||
|
python-version: 3.9
|
||||||
|
|
||||||
- name: Install tox
|
- name: Install tox
|
||||||
run: pip install tox
|
run: pip install tox
|
||||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,3 +2,4 @@
|
|||||||
AnkiConnect.zip
|
AnkiConnect.zip
|
||||||
meta.json
|
meta.json
|
||||||
.idea/
|
.idea/
|
||||||
|
.tox/
|
||||||
|
@ -1425,9 +1425,7 @@ class AnkiConnect:
|
|||||||
if savedMid:
|
if savedMid:
|
||||||
deck['mid'] = savedMid
|
deck['mid'] = savedMid
|
||||||
|
|
||||||
addCards.editor.note = ankiNote
|
addCards.editor.set_note(ankiNote)
|
||||||
addCards.editor.loadNote()
|
|
||||||
addCards.editor.updateTags()
|
|
||||||
|
|
||||||
addCards.activateWindow()
|
addCards.activateWindow()
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ from dataclasses import dataclass
|
|||||||
|
|
||||||
import aqt.operations.note
|
import aqt.operations.note
|
||||||
import pytest
|
import pytest
|
||||||
|
import anki.collection
|
||||||
from PyQt5 import QtTest
|
from PyQt5 import QtTest
|
||||||
from _pytest.monkeypatch import MonkeyPatch # noqa
|
from _pytest.monkeypatch import MonkeyPatch # noqa
|
||||||
from pytest_anki._launch import anki_running, temporary_user # noqa
|
from pytest_anki._launch import anki_running, temporary_user # noqa
|
||||||
@ -77,22 +78,33 @@ def waitress_patched_to_prevent_it_from_dying():
|
|||||||
yield
|
yield
|
||||||
|
|
||||||
|
|
||||||
|
@contextmanager
|
||||||
|
def anki_patched_to_prevent_backups():
|
||||||
|
with MonkeyPatch().context() as monkey:
|
||||||
|
if ac._anki21_version < 50:
|
||||||
|
monkey.setitem(aqt.profiles.profileConf, "numBackups", 0)
|
||||||
|
else:
|
||||||
|
monkey.setattr(anki.collection.Collection, "create_backup",
|
||||||
|
lambda *args, **kwargs: True)
|
||||||
|
yield
|
||||||
|
|
||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def empty_anki_session_started():
|
def empty_anki_session_started():
|
||||||
with waitress_patched_to_prevent_it_from_dying():
|
with waitress_patched_to_prevent_it_from_dying():
|
||||||
with anki_running(
|
with anki_patched_to_prevent_backups():
|
||||||
qtbot=None, # noqa
|
with anki_running(
|
||||||
enable_web_debugging=False,
|
qtbot=None, # noqa
|
||||||
profile_name="test_user",
|
enable_web_debugging=False,
|
||||||
) as session:
|
profile_name="test_user",
|
||||||
yield session
|
) as session:
|
||||||
|
yield session
|
||||||
|
|
||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def profile_created_and_loaded(session):
|
def profile_created_and_loaded(session):
|
||||||
with temporary_user(session.base, "test_user", "en_US"):
|
with temporary_user(session.base, "test_user", "en_US"):
|
||||||
with session.profile_loaded():
|
with session.profile_loaded():
|
||||||
aqt.mw.pm.profile["numBackups"] = 0 # don't try to do backups
|
|
||||||
yield session
|
yield session
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
import aqt
|
import aqt
|
||||||
|
import pytest
|
||||||
|
|
||||||
from conftest import ac, anki_connect_config_loaded, \
|
from conftest import ac, anki_connect_config_loaded, \
|
||||||
set_up_test_deck_and_test_model_and_two_notes, \
|
set_up_test_deck_and_test_model_and_two_notes, \
|
||||||
@ -33,6 +36,19 @@ class TestProfiles:
|
|||||||
|
|
||||||
|
|
||||||
class TestExportImport:
|
class TestExportImport:
|
||||||
|
# since Anki 2.1.50, exporting media for some wild reason
|
||||||
|
# will change the current working directory, which then gets removed.
|
||||||
|
# see `exporting.py`, ctrl-f `os.chdir(self.mediaDir)`
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def current_working_directory_preserved(self):
|
||||||
|
cwd = os.getcwd()
|
||||||
|
yield
|
||||||
|
|
||||||
|
try:
|
||||||
|
os.getcwd()
|
||||||
|
except FileNotFoundError:
|
||||||
|
os.chdir(cwd)
|
||||||
|
|
||||||
def test_exportPackage(self, session_with_profile_loaded, setup):
|
def test_exportPackage(self, session_with_profile_loaded, setup):
|
||||||
filename = session_with_profile_loaded.base + "/export.apkg"
|
filename = session_with_profile_loaded.base + "/export.apkg"
|
||||||
ac.exportPackage(deck="test_deck", path=filename)
|
ac.exportPackage(deck="test_deck", path=filename)
|
||||||
|
9
tox.ini
9
tox.ini
@ -46,7 +46,7 @@
|
|||||||
minversion = 3.24
|
minversion = 3.24
|
||||||
skipsdist = true
|
skipsdist = true
|
||||||
skip_install = true
|
skip_install = true
|
||||||
envlist = py38-anki{45,46,47,48,49}
|
envlist = py38-anki{45,46,47,48,49},py39-anki50qt5
|
||||||
|
|
||||||
[testenv]
|
[testenv]
|
||||||
commands =
|
commands =
|
||||||
@ -58,7 +58,7 @@ allowlist_externals =
|
|||||||
deps =
|
deps =
|
||||||
pytest==7.1.1
|
pytest==7.1.1
|
||||||
pytest-forked==1.4.0
|
pytest-forked==1.4.0
|
||||||
pytest-anki @ git+https://github.com/oakkitten/pytest-anki.git@17d19043
|
pytest-anki @ git+https://github.com/oakkitten/pytest-anki.git@97708344
|
||||||
|
|
||||||
anki45: anki==2.1.45
|
anki45: anki==2.1.45
|
||||||
anki45: aqt==2.1.45
|
anki45: aqt==2.1.45
|
||||||
@ -73,4 +73,7 @@ deps =
|
|||||||
anki48: aqt==2.1.48
|
anki48: aqt==2.1.48
|
||||||
|
|
||||||
anki49: anki==2.1.49
|
anki49: anki==2.1.49
|
||||||
anki49: aqt==2.1.49
|
anki49: aqt==2.1.49
|
||||||
|
|
||||||
|
anki50qt5: anki==2.1.50
|
||||||
|
anki50qt5: aqt[qt5]==2.1.50
|
||||||
|
Loading…
Reference in New Issue
Block a user