From 990e7bf3b9f8505ed3e0fa29074e4c937857f451 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Wed, 30 Jul 2014 19:16:51 -0300 Subject: [PATCH] first implementation and tox environment for cx-freeze support --HG-- branch : cx_freeze-support --- _pytest/cx_freeze_support.py | 52 ++++++++++++++++++++++++ pytest.py | 1 + testing/cx_freeze/run.py | 7 ++++ testing/cx_freeze/runtests_script.py | 10 +++++ testing/cx_freeze/runtests_setup.py | 11 +++++ testing/cx_freeze/tests/test_doctest.txt | 6 +++ testing/cx_freeze/tests/test_trivial.py | 6 +++ tox.ini | 8 ++++ 8 files changed, 101 insertions(+) create mode 100644 _pytest/cx_freeze_support.py create mode 100644 testing/cx_freeze/run.py create mode 100644 testing/cx_freeze/runtests_script.py create mode 100644 testing/cx_freeze/runtests_setup.py create mode 100644 testing/cx_freeze/tests/test_doctest.txt create mode 100644 testing/cx_freeze/tests/test_trivial.py diff --git a/_pytest/cx_freeze_support.py b/_pytest/cx_freeze_support.py new file mode 100644 index 000000000..84b2a11ee --- /dev/null +++ b/_pytest/cx_freeze_support.py @@ -0,0 +1,52 @@ + + +def includes(): + return [ + '_pytest.assertion.newinterpret', + '_pytest.assertion.oldinterpret', + '_pytest.assertion.reinterpret', + '_pytest.assertion.rewrite', + '_pytest.assertion.util', + + '_pytest._argcomplete', + '_pytest.doctest', + '_pytest.pdb', + '_pytest.unittest', + '_pytest.capture', + '_pytest.config', + '_pytest.core', + '_pytest.genscript', + '_pytest.helpconfig', + '_pytest.hookspec', + '_pytest.junitxml', + '_pytest.main', + '_pytest.mark', + '_pytest.monkeypatch', + '_pytest.nose', + '_pytest.pastebin', + '_pytest.pytester', + '_pytest.python', + '_pytest.recwarn', + '_pytest.resultlog', + '_pytest.runner', + '_pytest.skipping', + '_pytest.standalonetemplate', + '_pytest.terminal', + '_pytest.tmpdir', + + 'py._builtin', + 'py._path.local', + 'py._io.capture', + 'py._io.saferepr', + 'py._iniconfig', + 'py._io.terminalwriter', + 'py._xmlgen', + 'py._error', + 'py._std', + + # builtin files imported by pytest using py.std implicit mechanism + 'argparse', + 'shlex', + 'warnings', + 'types', + ] \ No newline at end of file diff --git a/pytest.py b/pytest.py index 6c25c6195..b84cb2a17 100644 --- a/pytest.py +++ b/pytest.py @@ -13,6 +13,7 @@ if __name__ == '__main__': # if run as a script or by 'python -m pytest' from _pytest.config import main, UsageError, _preloadplugins, cmdline from _pytest import __version__ +from _pytest import cx_freeze_support _preloadplugins() # to populate pytest.* namespace so help(pytest) works diff --git a/testing/cx_freeze/run.py b/testing/cx_freeze/run.py new file mode 100644 index 000000000..d52906df3 --- /dev/null +++ b/testing/cx_freeze/run.py @@ -0,0 +1,7 @@ +import os +import sys + +executable = os.path.join(os.getcwd(), 'build', 'runtests_script') +if sys.platform.startswith('win'): + executable += '.exe' +sys.exit(os.system('%s tests' % executable)) \ No newline at end of file diff --git a/testing/cx_freeze/runtests_script.py b/testing/cx_freeze/runtests_script.py new file mode 100644 index 000000000..d3e32ec82 --- /dev/null +++ b/testing/cx_freeze/runtests_script.py @@ -0,0 +1,10 @@ +""" +Simple script that actually executes py.test runner when passed "--pytest" as +first argument; in this case, all other arguments are forwarded to pytest's +main(). +""" + +if __name__ == '__main__': + import sys + import pytest + sys.exit(pytest.main()) \ No newline at end of file diff --git a/testing/cx_freeze/runtests_setup.py b/testing/cx_freeze/runtests_setup.py new file mode 100644 index 000000000..3d15a5a82 --- /dev/null +++ b/testing/cx_freeze/runtests_setup.py @@ -0,0 +1,11 @@ +from cx_Freeze import setup, Executable + +import pytest +setup( + name="runtests", + version="0.1", + description="exemple of how embedding py.test into an executable using cx_freeze", + executables=[Executable("runtests_script.py")], + options={"build_exe": {'includes': pytest.cx_freeze_support.includes()}}, +) + diff --git a/testing/cx_freeze/tests/test_doctest.txt b/testing/cx_freeze/tests/test_doctest.txt new file mode 100644 index 000000000..82159edb4 --- /dev/null +++ b/testing/cx_freeze/tests/test_doctest.txt @@ -0,0 +1,6 @@ + + +Testing doctest:: + + >>> 1 + 1 + 2 diff --git a/testing/cx_freeze/tests/test_trivial.py b/testing/cx_freeze/tests/test_trivial.py new file mode 100644 index 000000000..d8a572baa --- /dev/null +++ b/testing/cx_freeze/tests/test_trivial.py @@ -0,0 +1,6 @@ + +def test_upper(): + assert 'foo'.upper() == 'FOO' + +def test_lower(): + assert 'FOO'.lower() == 'foo' \ No newline at end of file diff --git a/tox.ini b/tox.ini index 8fc46de54..d0ae9c9cc 100644 --- a/tox.ini +++ b/tox.ini @@ -123,6 +123,14 @@ commands= {envpython} {envbindir}/py.test-jython \ -rfsxX --junitxml={envlogdir}/junit-{envname}2.xml [] +[testenv:py27-cxfreeze] +deps=cx_freeze +changedir=testing/cx_freeze +basepython=python2.7 +commands= + {envpython} runtests_setup.py build --build-exe build + {envpython} run.py + [pytest] minversion=2.0 plugins=pytester