From 6dffe39a733fb41e662d92124914398d16ed44d2 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Tue, 1 Aug 2017 00:46:01 +0300 Subject: [PATCH] Feat(tests): Use tox for testing --- MANIFEST.in | 3 ++- TODO | 3 --- devscripts/requirements/requirements_tox.txt | 1 + test/Makefile | 3 +-- test/html2txt.py | 16 +++++++++--- test/test_all | 11 ++++++--- tox.ini | 26 ++++++++++++++++++++ 7 files changed, 51 insertions(+), 12 deletions(-) create mode 100644 devscripts/requirements/requirements_tox.txt create mode 100644 tox.ini diff --git a/MANIFEST.in b/MANIFEST.in index 8e8e515..f80c0d1 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,4 +1,5 @@ global-include Makefile* *.py *.txt include ANNOUNCE ChangeLog MANIFEST.in TODO -include mimedecode.docbook mimedecode.man mimedecode.html mk-distr +include mimedecode.docbook mimedecode.man mimedecode.html +include mk-distr tox.ini include test/.mailcap test/README test/test_all diff --git a/TODO b/TODO index e9223a1..d8c3457 100644 --- a/TODO +++ b/TODO @@ -1,6 +1,3 @@ -tox. - - flake8. diff --git a/devscripts/requirements/requirements_tox.txt b/devscripts/requirements/requirements_tox.txt new file mode 100644 index 0000000..9927ea4 --- /dev/null +++ b/devscripts/requirements/requirements_tox.txt @@ -0,0 +1 @@ +tox >= 1.8 diff --git a/test/Makefile b/test/Makefile index fc8fe45..88ee55d 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,8 +1,7 @@ .PHONY: all all: - PYTHON=python2 ./test_all - PYTHON=python3 ./test_all + ./test_all .PHONY: clean diff --git a/test/html2txt.py b/test/html2txt.py index 4fa49f8..6b47f77 100755 --- a/test/html2txt.py +++ b/test/html2txt.py @@ -4,11 +4,21 @@ from __future__ import print_function import sys from m_lib.net.www.html import HTMLFilter -with open(sys.argv[1], 'r') as f: - html = f.read() +PY2 = sys.version_info[0] < 3 +if PY2: + with open(sys.argv[1], 'r') as f: + html = f.read() +else: + with open(sys.argv[1], 'r', encoding='utf-8') as f: + html = f.read() filter = HTMLFilter() filter.feed(html) filter.close() -print(filter.accumulator) +if PY2: + print(filter.accumulator) +else: + if not isinstance(filter.accumulator, bytes): + filter.accumulator = filter.accumulator.encode('utf-8') + sys.stdout.buffer.write(filter.accumulator + b'\n') diff --git a/test/test_all b/test/test_all index d5b06e1..df65454 100755 --- a/test/test_all +++ b/test/test_all @@ -1,13 +1,18 @@ #! /bin/sh cd "`dirname \"$0\"`" && -MAILCAPS="`pwd`"/.mailcap && -export MAILCAPS && - rm -rf save tmp && mkdir tmp || exit 1 +LC_CTYPE=c.UTF-8 && +export LC_CTYPE && + +MAILCAPS="`pwd`"/.mailcap && +export MAILCAPS && + +: ${PYTHON:=python} RC=0 + if [ `$PYTHON -c "import sys; print(sys.version[0])"` -eq 2 ]; then PY3=NO else diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..aa6b387 --- /dev/null +++ b/tox.ini @@ -0,0 +1,26 @@ +# Tox (http://tox.testrun.org/) is a tool for running tests +# in multiple virtualenvs. This configuration file will run the +# test suite on all supported python versions. To use it, "pip install tox" +# and then run "tox" from this directory. + +[tox] +envlist = py27, py33, py34, py35, py36, pypy +skip_missing_interpreters=true +toxworkdir={homedir}/.tox/mimedecode + +[testenv] +basepython = + py27: {env:TOXPYTHON:python2.7} + py33: {env:TOXPYTHON:python3.3} + py34: {env:TOXPYTHON:python3.4} + py35: {env:TOXPYTHON:python3.5} + py36: {env:TOXPYTHON:python3.6} + pypy: {env:TOXPYTHON:pypy} +deps = + -rdevscripts/requirements/requirements_tests.txt +changedir = test +commands = + {envpython} --version + {envpython} -c "import struct; print(struct.calcsize('P') * 8)" + ./test_all +#whitelist_externals = -- 2.39.2