1
Fork 0

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:
oakkitten 2022-04-12 19:50:36 +01:00
parent a433f600a4
commit e025a44ea3
6 changed files with 51 additions and 14 deletions

View File

@ -12,8 +12,15 @@ jobs:
sudo apt-get update
sudo apt-get install -y pyqt5-dev-tools xvfb
- name: Setup Python
- name: Setup Python 3.8
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
run: pip install tox

1
.gitignore vendored
View File

@ -2,3 +2,4 @@
AnkiConnect.zip
meta.json
.idea/
.tox/

View File

@ -1425,9 +1425,7 @@ class AnkiConnect:
if savedMid:
deck['mid'] = savedMid
addCards.editor.note = ankiNote
addCards.editor.loadNote()
addCards.editor.updateTags()
addCards.editor.set_note(ankiNote)
addCards.activateWindow()

View File

@ -5,6 +5,7 @@ from dataclasses import dataclass
import aqt.operations.note
import pytest
import anki.collection
from PyQt5 import QtTest
from _pytest.monkeypatch import MonkeyPatch # noqa
from pytest_anki._launch import anki_running, temporary_user # noqa
@ -77,22 +78,33 @@ def waitress_patched_to_prevent_it_from_dying():
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
def empty_anki_session_started():
with waitress_patched_to_prevent_it_from_dying():
with anki_running(
qtbot=None, # noqa
enable_web_debugging=False,
profile_name="test_user",
) as session:
yield session
with anki_patched_to_prevent_backups():
with anki_running(
qtbot=None, # noqa
enable_web_debugging=False,
profile_name="test_user",
) as session:
yield session
@contextmanager
def profile_created_and_loaded(session):
with temporary_user(session.base, "test_user", "en_US"):
with session.profile_loaded():
aqt.mw.pm.profile["numBackups"] = 0 # don't try to do backups
yield session

View File

@ -1,4 +1,7 @@
import os
import aqt
import pytest
from conftest import ac, anki_connect_config_loaded, \
set_up_test_deck_and_test_model_and_two_notes, \
@ -33,6 +36,19 @@ class TestProfiles:
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):
filename = session_with_profile_loaded.base + "/export.apkg"
ac.exportPackage(deck="test_deck", path=filename)

View File

@ -46,7 +46,7 @@
minversion = 3.24
skipsdist = true
skip_install = true
envlist = py38-anki{45,46,47,48,49}
envlist = py38-anki{45,46,47,48,49},py39-anki50qt5
[testenv]
commands =
@ -58,7 +58,7 @@ allowlist_externals =
deps =
pytest==7.1.1
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: aqt==2.1.45
@ -73,4 +73,7 @@ deps =
anki48: aqt==2.1.48
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