From 1ce7dea55b5d981cdfb7fa66fcbd60711170e960 Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Thu, 16 Nov 2017 22:21:35 +0100 Subject: [PATCH 1/6] Fix flapping tests The installation of version fails sometimes when installed from tox. I could not find why. Get rid of tox and seems ok. --- .travis.yml | 28 ++++++++++++++++++++++------ tasks.py | 11 +++++++---- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/.travis.yml b/.travis.yml index e6aab8d..3503526 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,18 @@ language: python -python: 2.7 +python: + - 2.7 + - 3.6 env: - globals: - - SOURCE_CONFIG_FILE=${TRAVIS_BUILD_DIR}/tests/config/odoo-travis.cfg + - ODOOVERSION=9.0 + - ODOOVERSION=10.0 + +matrix: + exclude: + - python: 3.6 + env: ODOOVERSION=9.0 + - python: 3.6 + env: ODOOVERSION=10.0 services: - postgresql @@ -14,13 +23,20 @@ virtualenv: system_site_packages: true addons: - postgresql: "9.4" + postgresql: "9.6" apt: packages: - python-lxml # because pip installation is slow install: - - pip install flake8 invoke tox + - pip install flake8 invoke + +before_script: + - virtualenv /tmp/venv-${ODOOVERSION} + - source /tmp/venv-${ODOOVERSION}/bin/activate + - pip install invoke flake8 pytest + - pip install . + - invoke tests.prepare-version "${ODOOVERSION}" script: - - tox + - OPENERP_SERVER=/tmp/test-anthem-config-${ODOOVERSION}.cfg py.test tests diff --git a/tasks.py b/tasks.py index e72e3b9..9eb920d 100644 --- a/tasks.py +++ b/tasks.py @@ -88,12 +88,15 @@ def tests_prepare_config(ctx, version, source, target): @task(default=True) -def tests_run(ctx): - ctx.run('tox', pty=True) +def tests_prepare_version(ctx, version): + tests_prepare(ctx, version) + config_file = '/tmp/test-anthem-config-%s.cfg' % version + tests_prepare_config(ctx, version, 'tests/config/odoo.cfg', config_file) + tests_createdb(ctx, version) -tests.add_task(tests_run, 'run') +tests.add_task(tests_prepare_version, 'prepare-version') tests.add_task(tests_createdb, 'createdb') tests.add_task(tests_dropdb, 'dropdb') tests.add_task(tests_prepare, 'prepare') -tests.add_task(tests_prepare_config, 'prepare_config') +tests.add_task(tests_prepare_config, 'prepare-config') From 0128ea24b5a51afab8b379c4ea9cddac95c44722 Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Fri, 17 Nov 2017 10:10:02 +0100 Subject: [PATCH 2/6] Add a lint travis job --- .travis.yml | 34 ++++++++++++++++------------------ HISTORY.rst | 2 +- tox.ini | 45 --------------------------------------------- 3 files changed, 17 insertions(+), 64 deletions(-) delete mode 100644 tox.ini diff --git a/.travis.yml b/.travis.yml index 3503526..75ed706 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,39 +4,37 @@ python: - 3.6 env: - - ODOOVERSION=9.0 - - ODOOVERSION=10.0 + - ODOOVERSION=9.0 LINT=false + - ODOOVERSION=10.0 LINT=false matrix: exclude: - python: 3.6 - env: ODOOVERSION=9.0 + env: ODOOVERSION=9.0 LINT=false - python: 3.6 - env: ODOOVERSION=10.0 + env: ODOOVERSION=10.0 LINT=false + include: + - python: 3.6 + env: LINT=true services: - postgresql -virtualenv: - # needed for lxml, lxml installed with pip in the virtualenv gives an - # error on travis - system_site_packages: true - addons: postgresql: "9.6" apt: packages: - python-lxml # because pip installation is slow -install: - - pip install flake8 invoke - before_script: - - virtualenv /tmp/venv-${ODOOVERSION} - - source /tmp/venv-${ODOOVERSION}/bin/activate - - pip install invoke flake8 pytest - - pip install . - - invoke tests.prepare-version "${ODOOVERSION}" + - if [ "$LINT" == false ] ; then virtualenv /tmp/venv-${ODOOVERSION} ; fi + - if [ "$LINT" == false ] ; then source /tmp/venv-${ODOOVERSION}/bin/activate ; fi + - if [ "$LINT" == false ] ; then pip install invoke pytest ; fi + - if [ "$LINT" == false ] ; then pip install . ; fi + - if [ "$LINT" == false ] ; then invoke tests.prepare-version "${ODOOVERSION}" ; fi + - if [ "$LINT" == true ] ; then pip install flake8 readme_renderer ; fi script: - - OPENERP_SERVER=/tmp/test-anthem-config-${ODOOVERSION}.cfg py.test tests + - if [ "$LINT" == false ] ; then OPENERP_SERVER=/tmp/test-anthem-config-${ODOOVERSION}.cfg py.test tests ; fi + - if [ "$LINT" == true ] ; then flake8 anthem tests ; fi + - if [ "$LINT" == true ] ; then python setup.py check -r -s ; fi diff --git a/HISTORY.rst b/HISTORY.rst index 725e335..ccad2b9 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -18,7 +18,7 @@ Unreleased 0.10.0 (2017-09-19) ------------------- +------------------- **Bugfixes** diff --git a/tox.ini b/tox.ini deleted file mode 100644 index 8c0b3ed..0000000 --- a/tox.ini +++ /dev/null @@ -1,45 +0,0 @@ -[tox] -envlist = 9.0,10.0,lint - -[testenv:9.0] -passenv = OPENERP_SERVER -setenv = - OPENERP_SERVER = /tmp/test-anthem-config{envname}.cfg - SOURCE_CONFIG_FILE = {env:SOURCE_CONFIG_FILE:tests/config/odoo.cfg} -deps = - pytest - invoke -whitelist_externals = echo -commands = - invoke tests.prepare --version={envname} - invoke tests.prepare_config --version={envname} --source={env:SOURCE_CONFIG_FILE} --target={env:OPENERP_SERVER} - invoke tests.createdb --version={envname} - py.test {posargs} - -[testenv:10.0] -passenv = OPENERP_SERVER -setenv = - OPENERP_SERVER = /tmp/test-anthem-config-{envname}.cfg - SOURCE_CONFIG_FILE = {env:SOURCE_CONFIG_FILE:tests/config/odoo.cfg} -deps = - pytest - invoke -whitelist_externals = echo -commands = - invoke tests.prepare --version={envname} - invoke tests.prepare_config --version={envname} --source={env:SOURCE_CONFIG_FILE} --target={env:OPENERP_SERVER} - invoke tests.createdb --version={envname} - py.test {posargs} - -[testenv:lint] -basepython = python2.7 -deps = - flake8 - readme_renderer -commands = - flake8 {posargs} anthem/ tests/ - python setup.py check -r -s - -[pytest] -addopts = -q -norecursedirs = *.egg .git .* _* From 1ae60688ce2792a4677fd88350eb6385455c32cb Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Fri, 17 Nov 2017 11:19:39 +0100 Subject: [PATCH 3/6] Fix E722 do not use bare except --- anthem/lyrics/modules.py | 2 +- anthem/output.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/anthem/lyrics/modules.py b/anthem/lyrics/modules.py index eb81901..c3b9abd 100644 --- a/anthem/lyrics/modules.py +++ b/anthem/lyrics/modules.py @@ -14,7 +14,7 @@ def uninstall(ctx, module_list): mods = ctx.env['ir.module.module'].search([('name', 'in', module_list)]) try: mods.button_immediate_uninstall() - except: + except Exception: raise AnthemError(u'Cannot uninstall modules. See the logs') diff --git a/anthem/output.py b/anthem/output.py index e6645c4..3fbe9b2 100644 --- a/anthem/output.py +++ b/anthem/output.py @@ -30,7 +30,7 @@ def display(self, name, timing=True): start = time.time() try: yield - except: + except Exception: self.level -= 1 self.print_indent(u'{}: error'.format(name)) raise From 29bac4c431f8176fb89eea36b6340cf2e9b62069 Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Fri, 17 Nov 2017 15:08:06 +0100 Subject: [PATCH 4/6] Add tests instructions in readme --- README.rst | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/README.rst b/README.rst index 17e570b..72f9681 100644 --- a/README.rst +++ b/README.rst @@ -106,33 +106,39 @@ Run the tests ~~~~~~~~~~~~~ To run ``anthem``'s tests, it is a good idea to do an *editable* install of it -in a virtualenv, and then intall and run ``tox`` as follows:: +in a virtualenv. You must also prepare the environment by installing odoo packages. + +Odoo 9.0 (Python 2):: $ git clone https://github.com/camptocamp/anthem.git Cloning into 'anthem'... $ cd anthem - $ python2 -m virtualenv env - $ source env/bin/activate + $ virtualenv -p python2 env-9.0 + $ source env-9.0/bin/activate $ pip install -e . $ pip install pytest invoke tox - $ tox - -Additional arguments will be passed to ``pytest``:: + $ invoke tests.prepare-version 9.0 + $ OPENERP_SERVER=/tmp/test-anthem-config-9.0.cfg py.test -s tests - $ tox -e py27 -- -x tests/test_cli.py +Odoo 10.0 (Python 2):: -If you prefer to execute the tests directly with ``pytest``, you can run:: - - $ OPENERP_SERVER=tests/config/odoo.cfg py.test + $ git clone https://github.com/camptocamp/anthem.git + Cloning into 'anthem'... + $ cd anthem + $ virtualenv -p python2 env-10.0 + $ source env-10.0/bin/activate + $ pip install -e . + $ pip install pytest invoke tox + $ invoke tests.prepare-version 10.0 + $ OPENERP_SERVER=/tmp/test-anthem-config-10.0.cfg py.test -s tests -But before, you have to ensure to have the proper environment for the tests with:: +If need be, you can drop the test database with (adapt the version):: - $ invoke tests.prepare - $ invoke tests.createdb + $ invoke tests.dropdb 9.0 -Those steps, automatically called when using ``tox``, will download the nightly -release of Odoo and install it as a package, so tests can be run against it -(and that's also why it is important to use a virtualenv!) +These steps will download the nightly release of Odoo install it as a package +then install a database, so tests can be run against it (and that's also why it +is important to use a virtualenv!) When calling ``pytest``, you have to define the ``OPENERP_SERVER`` environment variable with the configuration file for the Odoo database that will be used From fb7e45545fea2e6bf7dcf90af278a495994f374a Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Fri, 17 Nov 2017 15:51:27 +0100 Subject: [PATCH 5/6] Fix usage of deprecated function in tests --- tests/test_lyrics_uninstaller.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_lyrics_uninstaller.py b/tests/test_lyrics_uninstaller.py index 386d256..53f95b2 100644 --- a/tests/test_lyrics_uninstaller.py +++ b/tests/test_lyrics_uninstaller.py @@ -4,7 +4,7 @@ import pytest import anthem.cli -from anthem.lyrics.uninstaller import uninstall +from anthem.lyrics.modules import uninstall from anthem.exceptions import AnthemError From 7f0b0514495309b0e58323abc90be03c6e1904df Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Fri, 17 Nov 2017 16:35:22 +0100 Subject: [PATCH 6/6] Prepare py3 (flake8) --- anthem/lyrics/loaders.py | 2 ++ anthem/lyrics/records.py | 1 + anthem/lyrics/settings.py | 1 + setup.py | 3 ++- 4 files changed, 6 insertions(+), 1 deletion(-) diff --git a/anthem/lyrics/loaders.py b/anthem/lyrics/loaders.py index 4579337..3ca8fdd 100644 --- a/anthem/lyrics/loaders.py +++ b/anthem/lyrics/loaders.py @@ -5,6 +5,8 @@ import codecs import csv +from past.types import basestring + from ..exceptions import AnthemError diff --git a/anthem/lyrics/records.py b/anthem/lyrics/records.py index 47179e2..d8f92da 100644 --- a/anthem/lyrics/records.py +++ b/anthem/lyrics/records.py @@ -2,6 +2,7 @@ # Copyright 2016 Camptocamp SA # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl-3.0.en.html) +from past.types import basestring from contextlib import contextmanager diff --git a/anthem/lyrics/settings.py b/anthem/lyrics/settings.py index 95b4f63..eabc74c 100644 --- a/anthem/lyrics/settings.py +++ b/anthem/lyrics/settings.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- # Copyright 2017 Camptocamp SA # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl-3.0.en.html) +from past.types import basestring def define_settings(ctx, model, values): diff --git a/setup.py b/setup.py index ce140bf..ee1cc48 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ from setuptools import setup, find_packages with open('anthem/__init__.py') as f: - version = re.search('^__version__\s*=\s*"(.*)"', f.read(), re.M).group(1) + version = re.search(r'^__version__\s*=\s*"(.*)"', f.read(), re.M).group(1) with open('README.rst') as f: readme = f.read() with open('HISTORY.rst') as f: @@ -24,6 +24,7 @@ entry_points={ 'console_scripts': ['anthem = anthem.cli:main'] }, + install_requires=['future'], classifiers=( 'Development Status :: 3 - Alpha', 'Intended Audience :: Developers',