Merge pull request #510 from evandroforks/fix_tests_on_windows

Fix tests on windows
This commit is contained in:
Damien Elmes 2020-03-24 15:33:02 +10:00 committed by GitHub
commit cc34157e4b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 93 additions and 28 deletions

View File

@ -1,8 +1,13 @@
#!/bin/bash #!/bin/bash
set -e set -eo pipefail
# Checking version to force it fail the build if rg is not installed.
# Because `set -e` does not work inside the subshell $()
rg --version > /dev/null 2>&1
files=$(rg -l '[^\n]\z' -g '!*.{png,svg,scss,json,sql}' || true)
files=$(rg -l '[^\n]\z' -g '!*.{svg,scss,json,sql}' || true)
if [ "$files" != "" ]; then if [ "$files" != "" ]; then
echo "the following files are missing a newline on the last line:" echo "the following files are missing a newline on the last line:"
echo $files echo $files

View File

@ -4,7 +4,7 @@ ifndef OS
OS := unknown OS := unknown
endif endif
ifeq ($(OS),Windows_NT) ifeq (${OS},Windows_NT)
ifndef ACTIVATE_SCRIPT ifndef ACTIVATE_SCRIPT
ACTIVATE_SCRIPT := pyenv/Scripts/activate ACTIVATE_SCRIPT := pyenv/Scripts/activate
endif endif

View File

@ -1,5 +1,19 @@
SHELL := /bin/bash SHELL := /bin/bash
FIND := $(if $(wildcard /bin/find),/bin/find,/usr/bin/find) FIND := $(if $(wildcard /bin/find),/bin/find,/usr/bin/find)
MYPY_ARGS :=
ifndef OS
OS := unknown
endif
ifndef UNAME
UNAME := unknown
endif
# https://anki.tenderapp.com/discussions/beta-testing/1860-error-unused-type-ignore-comment
ifneq (${OS},Windows_NT)
MYPY_ARGS := --warn-unused-ignores
endif
.SHELLFLAGS := -eu -o pipefail -c .SHELLFLAGS := -eu -o pipefail -c
.DELETE_ON_ERROR: .DELETE_ON_ERROR:
@ -33,7 +47,7 @@ PROTODEPS := $(wildcard ../proto/*.proto)
.build/hooks: tools/genhooks.py tools/hookslib.py .build/hooks: tools/genhooks.py tools/hookslib.py
python tools/genhooks.py python tools/genhooks.py
black anki/hooks.py python -m black anki/hooks.py
@touch $@ @touch $@
BUILD_STEPS := .build/run-deps .build/dev-deps .build/py-proto anki/buildinfo.py .build/hooks BUILD_STEPS := .build/run-deps .build/dev-deps .build/py-proto anki/buildinfo.py .build/hooks
@ -47,7 +61,7 @@ check: $(BUILD_STEPS) .build/mypy .build/test .build/fmt .build/imports .build/l
.PHONY: fix .PHONY: fix
fix: $(BUILD_STEPS) fix: $(BUILD_STEPS)
isort $(ISORTARGS) isort $(ISORTARGS)
black $(BLACKARGS) python -m black $(BLACKARGS)
.PHONY: clean .PHONY: clean
clean: clean:
@ -59,7 +73,7 @@ clean:
CHECKDEPS := $(shell ${FIND} anki tests -name '*.py' | grep -v buildinfo.py) CHECKDEPS := $(shell ${FIND} anki tests -name '*.py' | grep -v buildinfo.py)
.build/mypy: $(CHECKDEPS) .build/mypy: $(CHECKDEPS)
mypy anki python -m mypy ${MYPY_ARGS} anki
@touch $@ @touch $@
.build/test: $(CHECKDEPS) .build/test: $(CHECKDEPS)
@ -67,7 +81,8 @@ CHECKDEPS := $(shell ${FIND} anki tests -name '*.py' | grep -v buildinfo.py)
@touch $@ @touch $@
.build/lint: $(CHECKDEPS) .build/lint: $(CHECKDEPS)
pylint -j 0 --rcfile=.pylintrc -f colorized --extension-pkg-whitelist=ankirspy anki tests setup.py python -m pylint -j 0 --rcfile=.pylintrc -f colorized \
--extension-pkg-whitelist=ankirspy anki tests setup.py
@touch $@ @touch $@
.build/imports: $(CHECKDEPS) .build/imports: $(CHECKDEPS)
@ -75,7 +90,7 @@ CHECKDEPS := $(shell ${FIND} anki tests -name '*.py' | grep -v buildinfo.py)
@touch $@ @touch $@
.build/fmt: $(CHECKDEPS) .build/fmt: $(CHECKDEPS)
black --check $(BLACKARGS) python -m black --check $(BLACKARGS)
@touch $@ @touch $@
# Building # Building

View File

@ -7,7 +7,6 @@ check_untyped_defs = true
disallow_untyped_decorators = True disallow_untyped_decorators = True
warn_redundant_casts = True warn_redundant_casts = True
warn_unused_configs = True warn_unused_configs = True
warn_unused_ignores = True
[mypy-win32file] [mypy-win32file]
ignore_missing_imports = True ignore_missing_imports = True

View File

@ -18,6 +18,15 @@ srcNotes = None
srcCards = None srcCards = None
def clear_tempfile(tf):
""" https://stackoverflow.com/questions/23212435/permission-denied-to-write-to-my-temporary-file """
try:
tf.close()
os.unlink(tf.name)
except:
pass
def test_anki2_mediadupes(): def test_anki2_mediadupes():
tmp = getEmptyCol() tmp = getEmptyCol()
# add a note that references a sound # add a note that references a sound
@ -208,13 +217,15 @@ def test_tsv_tag_modified():
n.addTag("four") n.addTag("four")
deck.addNote(n) deck.addNote(n)
with NamedTemporaryFile(mode="w") as tf: # https://stackoverflow.com/questions/23212435/permission-denied-to-write-to-my-temporary-file
with NamedTemporaryFile(mode="w", delete=False) as tf:
tf.write("1\tb\tc\n") tf.write("1\tb\tc\n")
tf.flush() tf.flush()
i = TextImporter(deck, tf.name) i = TextImporter(deck, tf.name)
i.initMapping() i.initMapping()
i.tagModified = "boom" i.tagModified = "boom"
i.run() i.run()
clear_tempfile(tf)
n.load() n.load()
assert n["Front"] == "1" assert n["Front"] == "1"
@ -243,13 +254,15 @@ def test_tsv_tag_multiple_tags():
n.addTag("five") n.addTag("five")
deck.addNote(n) deck.addNote(n)
with NamedTemporaryFile(mode="w") as tf: # https://stackoverflow.com/questions/23212435/permission-denied-to-write-to-my-temporary-file
with NamedTemporaryFile(mode="w", delete=False) as tf:
tf.write("1\tb\tc\n") tf.write("1\tb\tc\n")
tf.flush() tf.flush()
i = TextImporter(deck, tf.name) i = TextImporter(deck, tf.name)
i.initMapping() i.initMapping()
i.tagModified = "five six" i.tagModified = "five six"
i.run() i.run()
clear_tempfile(tf)
n.load() n.load()
assert n["Front"] == "1" assert n["Front"] == "1"
@ -273,13 +286,15 @@ def test_csv_tag_only_if_modified():
n["Left"] = "3" n["Left"] = "3"
deck.addNote(n) deck.addNote(n)
with NamedTemporaryFile(mode="w") as tf: # https://stackoverflow.com/questions/23212435/permission-denied-to-write-to-my-temporary-file
with NamedTemporaryFile(mode="w", delete=False) as tf:
tf.write("1,2,3\n") tf.write("1,2,3\n")
tf.flush() tf.flush()
i = TextImporter(deck, tf.name) i = TextImporter(deck, tf.name)
i.initMapping() i.initMapping()
i.tagModified = "right" i.tagModified = "right"
i.run() i.run()
clear_tempfile(tf)
n.load() n.load()
assert n.tags == [] assert n.tags == []

View File

@ -1,4 +1,5 @@
# coding: utf-8 #!/usr/bin/env python3
# -*- coding: UTF-8 -*-
import os import os
import tempfile import tempfile
@ -34,6 +35,6 @@ def test_graphs():
d = aopen(os.path.join(dir, "test.anki2")) d = aopen(os.path.join(dir, "test.anki2"))
g = d.stats() g = d.stats()
rep = g.report() rep = g.report()
with open(os.path.join(dir, "test.html"), "w") as f: with open(os.path.join(dir, "test.html"), "w", encoding="UTF-8") as f:
f.write(rep) f.write(rep)
return return

View File

@ -1,5 +1,22 @@
SHELL := /bin/bash SHELL := /bin/bash
FIND := $(if $(wildcard /bin/find),/bin/find,/usr/bin/find) FIND := $(if $(wildcard /bin/find),/bin/find,/usr/bin/find)
MYPY_ARGS :=
PYLINT_ARGS :=
ifndef OS
OS := unknown
endif
ifndef UNAME
UNAME := unknown
endif
# https://anki.tenderapp.com/discussions/beta-testing/1860-error-unused-type-ignore-comment
ifneq (${OS},Windows_NT)
MYPY_ARGS := --warn-unused-ignores
else
PYLINT_ARGS := --ignored-modules=win32file,pywintypes,socket,win32pipe
endif
.SHELLFLAGS := -eu -o pipefail -c .SHELLFLAGS := -eu -o pipefail -c
.DELETE_ON_ERROR: .DELETE_ON_ERROR:
@ -42,7 +59,7 @@ TSDEPS := $(wildcard ts/src/*.ts) $(wildcard ts/scss/*.scss)
.build/hooks: tools/genhooks_gui.py ../pylib/tools/hookslib.py .build/hooks: tools/genhooks_gui.py ../pylib/tools/hookslib.py
python tools/genhooks_gui.py python tools/genhooks_gui.py
black aqt/gui_hooks.py python -m black aqt/gui_hooks.py
@touch $@ @touch $@
BUILD_STEPS := .build/run-deps .build/dev-deps .build/js .build/ui aqt/buildinfo.py .build/hooks .build/i18n BUILD_STEPS := .build/run-deps .build/dev-deps .build/js .build/ui aqt/buildinfo.py .build/hooks .build/i18n
@ -56,7 +73,7 @@ check: $(BUILD_STEPS) .build/mypy .build/test .build/fmt .build/imports .build/l
.PHONY: fix .PHONY: fix
fix: $(BUILD_STEPS) fix: $(BUILD_STEPS)
isort $(ISORTARGS) isort $(ISORTARGS)
black $(BLACKARGS) python -m black $(BLACKARGS)
(cd ts && npm run pretty) (cd ts && npm run pretty)
.PHONY: clean .PHONY: clean
@ -80,7 +97,7 @@ PYLIB := ../pylib
CHECKDEPS := $(shell ${FIND} aqt tests -name '*.py' | grep -v buildinfo.py) CHECKDEPS := $(shell ${FIND} aqt tests -name '*.py' | grep -v buildinfo.py)
.build/mypy: $(CHECKDEPS) .build/qt-stubs .build/mypy: $(CHECKDEPS) .build/qt-stubs
mypy aqt python -m mypy ${MYPY_ARGS} aqt
@touch $@ @touch $@
.build/test: $(CHECKDEPS) .build/test: $(CHECKDEPS)
@ -88,7 +105,8 @@ CHECKDEPS := $(shell ${FIND} aqt tests -name '*.py' | grep -v buildinfo.py)
@touch $@ @touch $@
.build/lint: $(CHECKDEPS) .build/lint: $(CHECKDEPS)
pylint -j 0 --rcfile=.pylintrc -f colorized --extension-pkg-whitelist=PyQt5,ankirspy aqt tests setup.py python -m pylint -j 0 --rcfile=.pylintrc -f colorized ${PYLINT_ARGS} \
--extension-pkg-whitelist=PyQt5,ankirspy aqt tests setup.py
@touch $@ @touch $@
.build/imports: $(CHECKDEPS) .build/imports: $(CHECKDEPS)
@ -96,7 +114,7 @@ CHECKDEPS := $(shell ${FIND} aqt tests -name '*.py' | grep -v buildinfo.py)
@touch $@ @touch $@
.build/fmt: $(CHECKDEPS) .build/fmt: $(CHECKDEPS)
black --check $(BLACKARGS) python -m black --check $(BLACKARGS)
@touch $@ @touch $@
.build/qt-stubs: .build/qt-stubs:

View File

@ -1462,8 +1462,8 @@ will be lost. Continue?"""
# make sure ctypes is bundled # make sure ctypes is bundled
from ctypes import windll, wintypes # type: ignore from ctypes import windll, wintypes # type: ignore
_dummy = windll _dummy1 = windll
_dummy = wintypes _dummy2 = wintypes
def maybeHideAccelerators(self, tgt: Optional[Any] = None) -> None: def maybeHideAccelerators(self, tgt: Optional[Any] = None) -> None:
if not self.hideMenuAccels: if not self.hideMenuAccels:

View File

@ -6,7 +6,6 @@ show_error_codes = true
disallow_untyped_decorators = True disallow_untyped_decorators = True
warn_redundant_casts = True warn_redundant_casts = True
warn_unused_configs = True warn_unused_configs = True
warn_unused_ignores = True
[mypy-win32file] [mypy-win32file]
ignore_missing_imports = True ignore_missing_imports = True

View File

@ -14,4 +14,4 @@ case "${unameOut}" in
;; ;;
esac esac
rsync -a "$qtTranslations"/qt* "$out" rsync -a "$qtTranslations/" "$out/"

View File

@ -6,8 +6,21 @@
# able to resolve. A solution that doesn't require modifying the python install # able to resolve. A solution that doesn't require modifying the python install
# would be welcome! # would be welcome!
TOOLS="$(cd "`dirname "$0"`"; pwd)" set -eo pipefail
modDir=$(python -c 'import PyQt5, sys, os; print(os.path.dirname(sys.modules["PyQt5"].__file__))')
cmd="rsync -a $TOOLS/stubs/PyQt5/* $modDir/"
$cmd > /dev/null 2>&1 || sudo $cmd TOOLS="$(cd "`dirname "$0"`"; pwd)"
modDir=$(python -c 'import PyQt5, sys, os; sys.stdout.write(os.path.dirname(sys.modules["PyQt5"].__file__))')
unameOut="$(uname -s)"
case "${unameOut}" in
CYGWIN*)
modDir="$(cygpath -u "${modDir}")"
;;
esac
if [[ "w${OS}" == "wWindows_NT" ]];
then
rsync -a "${TOOLS}/stubs/PyQt5/" "${modDir}/"
else
rsync -a "${TOOLS}/stubs/PyQt5/" "${modDir}/" || sudo rsync -a "${TOOLS}/stubs/PyQt5/" "${modDir}/"
fi

View File

@ -5,7 +5,7 @@ ifndef OS
OS := unknown OS := unknown
endif endif
ifeq ($(OS),Windows_NT) ifeq (${OS},Windows_NT)
ifndef PYTHON_BIN ifndef PYTHON_BIN
PYTHON_BIN := python PYTHON_BIN := python
endif endif