From 3f0b4ff3f6e037c7cc680b27b158ff4eda391fbf Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Thu, 26 Dec 2019 07:36:26 +1000 Subject: [PATCH] isort tests; black/isort should notice changes to tests --- Makefile | 12 +++++++----- tests/shared.py | 5 ++++- tests/test_addons.py | 3 ++- tests/test_collection.py | 10 +++++----- tests/test_exporting.py | 4 +++- tests/test_importing.py | 11 ++++++----- tests/test_latex.py | 3 +-- tests/test_media.py | 2 +- tests/test_models.py | 6 +++--- tests/test_schedv1.py | 6 +++--- tests/test_schedv2.py | 6 +++--- tests/test_stats.py | 4 +++- tests/test_undo.py | 3 ++- 13 files changed, 43 insertions(+), 32 deletions(-) diff --git a/Makefile b/Makefile index e4affd6fe..ddcf65c08 100644 --- a/Makefile +++ b/Makefile @@ -8,6 +8,7 @@ RUNARGS := .SUFFIXES: BLACKARGS := -t py36 anki aqt tests RUSTARGS := --release --strip +ISORTARGS := anki aqt tests $(shell mkdir -p .build) @@ -162,12 +163,13 @@ fix: fix-py-fmt fix-py-imports fix-rs-fmt fix-ts-fmt ###################### PYCHECKDEPS := $(BUILDDEPS) .build/py-check-reqs $(shell find anki aqt -name '*.py' | grep -v buildhash.py) +PYTESTDEPS := $(wildcard tests/*.py) .build/py-mypy: $(PYCHECKDEPS) mypy anki aqt @touch $@ -.build/py-test: $(PYCHECKDEPS) $(wildcard tests/*.py) +.build/py-test: $(PYCHECKDEPS) $(PYTESTDEPS) ./tools/tests.sh @touch $@ @@ -175,11 +177,11 @@ PYCHECKDEPS := $(BUILDDEPS) .build/py-check-reqs $(shell find anki aqt -name '*. pylint -j 0 --rcfile=.pylintrc -f colorized --extension-pkg-whitelist=PyQt5,_ankirs anki aqt @touch $@ -.build/py-imports: $(PYCHECKDEPS) - isort anki aqt --check # if this fails, run 'make fix-py-imports' +.build/py-imports: $(PYCHECKDEPS) $(PYTESTDEPS) + isort $(ISORTARGS) --check # if this fails, run 'make fix-py-imports' @touch $@ -.build/py-fmt: $(PYCHECKDEPS) +.build/py-fmt: $(PYCHECKDEPS) $(PYTESTDEPS) black --check $(BLACKARGS) # if this fails, run 'make fix-py-fmt' @touch $@ @@ -193,7 +195,7 @@ py-fmt: .build/py-fmt .PHONY: fix-py-imports fix-py-fmt fix-py-imports: - isort anki aqt + isort $(ISORTARGS) fix-py-fmt: black $(BLACKARGS) anki aqt diff --git a/tests/shared.py b/tests/shared.py index 1ddf13601..5294a84f0 100644 --- a/tests/shared.py +++ b/tests/shared.py @@ -1,4 +1,7 @@ -import tempfile, os, shutil +import os +import shutil +import tempfile + from anki import Collection as aopen diff --git a/tests/test_addons.py b/tests/test_addons.py index 69bc54245..c5708842c 100644 --- a/tests/test_addons.py +++ b/tests/test_addons.py @@ -1,7 +1,8 @@ import os.path -from mock import MagicMock from tempfile import TemporaryDirectory from zipfile import ZipFile + +from mock import MagicMock from nose2.tools.such import helper from aqt.addons import AddonManager diff --git a/tests/test_collection.py b/tests/test_collection.py index 1868cf8b9..43ce5d058 100644 --- a/tests/test_collection.py +++ b/tests/test_collection.py @@ -1,12 +1,12 @@ # coding: utf-8 -import os, tempfile - -from anki.utils import isWin -from tests.shared import assertException, getEmptyCol -from anki.stdmodels import addBasicModel, models +import os +import tempfile from anki import Collection as aopen +from anki.stdmodels import addBasicModel, models +from anki.utils import isWin +from tests.shared import assertException, getEmptyCol def test_create_open(): diff --git a/tests/test_exporting.py b/tests/test_exporting.py index f02754c3e..dc7db3ff2 100644 --- a/tests/test_exporting.py +++ b/tests/test_exporting.py @@ -1,12 +1,14 @@ # coding: utf-8 -import os, tempfile +import os +import tempfile from nose2.tools.decorators import with_setup from anki import Collection as aopen from anki.exporting import * from anki.importing import Anki2Importer + from .shared import getEmptyCol deck = None diff --git a/tests/test_importing.py b/tests/test_importing.py index fb51a9383..78c1edb2e 100644 --- a/tests/test_importing.py +++ b/tests/test_importing.py @@ -1,15 +1,16 @@ # coding: utf-8 import os -from tests.shared import getUpgradeDeckPath, getEmptyCol -from anki.utils import ids2str + from anki.importing import ( Anki2Importer, - TextImporter, - SupermemoXmlImporter, - MnemosyneImporter, AnkiPackageImporter, + MnemosyneImporter, + SupermemoXmlImporter, + TextImporter, ) +from anki.utils import ids2str +from tests.shared import getEmptyCol, getUpgradeDeckPath testDir = os.path.dirname(__file__) diff --git a/tests/test_latex.py b/tests/test_latex.py index 5bd6c9dae..d8e82b025 100644 --- a/tests/test_latex.py +++ b/tests/test_latex.py @@ -1,11 +1,10 @@ # coding: utf-8 import os - import shutil -from tests.shared import getEmptyCol from anki.utils import stripHTML +from tests.shared import getEmptyCol def test_latex(): diff --git a/tests/test_media.py b/tests/test_media.py index 6f23cd392..89d595468 100644 --- a/tests/test_media.py +++ b/tests/test_media.py @@ -1,7 +1,7 @@ # coding: utf-8 -import tempfile import os +import tempfile import time from .shared import getEmptyCol, testDir diff --git a/tests/test_models.py b/tests/test_models.py index 7deb26b44..f527bf389 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -1,10 +1,10 @@ # coding: utf-8 import time -from tests.shared import getEmptyCol -from anki.consts import MODEL_CLOZE -from anki.utils import stripHTML, joinFields, isWin import anki.template +from anki.consts import MODEL_CLOZE +from anki.utils import isWin, joinFields, stripHTML +from tests.shared import getEmptyCol def test_modelDelete(): diff --git a/tests/test_schedv1.py b/tests/test_schedv1.py index ad426164d..14b8982f6 100644 --- a/tests/test_schedv1.py +++ b/tests/test_schedv1.py @@ -1,12 +1,12 @@ # coding: utf-8 -import time import copy +import time from anki.consts import STARTING_FACTOR -from tests.shared import getEmptyCol as getEmptyColOrig -from anki.utils import intTime from anki.hooks import addHook +from anki.utils import intTime +from tests.shared import getEmptyCol as getEmptyColOrig def getEmptyCol(): diff --git a/tests/test_schedv2.py b/tests/test_schedv2.py index a1eb012cd..686bd816f 100644 --- a/tests/test_schedv2.py +++ b/tests/test_schedv2.py @@ -1,12 +1,12 @@ # coding: utf-8 -import time import copy +import time from anki.consts import STARTING_FACTOR -from tests.shared import getEmptyCol -from anki.utils import intTime from anki.hooks import addHook +from anki.utils import intTime +from tests.shared import getEmptyCol # Between 2-4AM, shift the time back so test assumptions hold. lt = time.localtime() diff --git a/tests/test_stats.py b/tests/test_stats.py index 193e9b273..7de3dc831 100644 --- a/tests/test_stats.py +++ b/tests/test_stats.py @@ -1,9 +1,10 @@ # coding: utf-8 import os -from tests.shared import getEmptyCol import tempfile +from tests.shared import getEmptyCol + def test_stats(): d = getEmptyCol() @@ -27,6 +28,7 @@ def test_graphs_empty(): def test_graphs(): from anki import Collection as aopen + dir = tempfile.gettempdir() d = aopen(os.path.join(dir, "test.anki2")) diff --git a/tests/test_undo.py b/tests/test_undo.py index 1fdfff8f7..4b310e171 100644 --- a/tests/test_undo.py +++ b/tests/test_undo.py @@ -1,8 +1,9 @@ # coding: utf-8 import time -from tests.shared import getEmptyCol + from anki.consts import * +from tests.shared import getEmptyCol def test_op():