Skip to content

Commit

Permalink
Use pytest-virtualenv and pytest-warnings. Adjust the scaffol…
Browse files Browse the repository at this point in the history
…d tests accordingly.
  • Loading branch information
disko committed Oct 10, 2016
1 parent 33d0e47 commit c7a0907
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 92 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ before_script:
- psql -c 'create database kotti_testing;' -U postgres
- mysql -e 'create database kotti_testing;'
script:
- py.test --runslow --tb=native --cov=kotti --cov-report=term-missing
- py.test -rw --runslow --tb=native --cov=kotti --cov-report=term-missing
after_success:
- coveralls
- codecov
Expand Down
13 changes: 11 additions & 2 deletions kotti/scaffolds/package/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
-e git://github.com/Kotti/Kotti.git#egg=Kotti
# ``master`` is where development happens:
# -e git://github.com/Kotti/Kotti.git#egg=kotti

# -r https://raw.githubusercontent.com/Kotti/Kotti/testing/requirements.txt
# ``testing`` is *always* the latest non final release (alpha, beta, etc.):
# -e git://github.com/Kotti/Kotti.git@testing#egg=kotti

# ``production`` is *always* the latest final release:
# -e git://github.com/Kotti/Kotti.git@production#egg=kotti

# You can also install a specific version with its pinned requirements:
# -r https://raw.githubusercontent.com/Kotti/Kotti/1.3.0-alpha.4/requirements.txt
# Kotti == 1.3.0-alpha.4
108 changes: 24 additions & 84 deletions kotti/tests/test_zzz_scaffolds.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
""" This module contains the tests for the scaffolds. Each test tries to
simulate actual usage of the scaffolds as much as possible. A clean virtualenv
is created, a package created from a scaffold and the tests of that package are
run. Because the is potentially really time consuming the scaffolding tests
run. Because this is potentially really time consuming the scaffolding tests
are marked with ``slow`` and are not run unless ``py.test`` is invoked with the
``--runslow`` option.
Expand All @@ -12,109 +12,49 @@
"""

import os
import shutil
import subprocess
import sys
from copy import copy
from tempfile import mkdtemp

from pytest import fixture
from pkg_resources import working_set
from pytest import mark

slow = mark.slow


@fixture
def virtualenv(request, travis):
""" Create a virtualenv and ``chdir`` into it. Remove it and ``chdir``
into the previous working directory again when the test has been run.
"""
@slow
def test_scaffold_kotti_addon(virtualenv, travis):

# install kotti and dependencies in a fresh virtualenv
with travis.folding_output():
import virtualenv
from virtualenv import Logger

# create a temp directory
cwd = os.getcwd()
virtualenv_directory = mkdtemp()

# install a virtualenv
logger = Logger([(Logger.level_for_integer(2), sys.stdout)])
virtualenv.logger = logger
virtualenv.create_environment(
virtualenv_directory,
site_packages=False,
clear=True,
unzip_setuptools=True)

# chdir into the virtualenv directory
os.chdir(virtualenv_directory)

# update setuptools in the virtualenv
subprocess.check_call([
os.path.join('bin', 'pip'),
'install', '-U', 'pip', 'wheel', 'setuptools', ])

# create a local copy of the environment, where we can override
# VIRTUAL_ENV to make pip-accel work
env = copy(os.environ)
env.update({'VIRTUAL_ENV': virtualenv_directory, })

# install requirements.txt into the virtualenv
subprocess.check_call([
os.path.join('bin', 'pip'),
'install', '-r',
os.path.join(cwd, 'requirements.txt')],
env=env)

# setuptools-git is required to be able to call setup.py install
# sucessfully. also install psycopg2 and oursql.
subprocess.check_call([
os.path.join('bin', 'pip'),
'install', 'setuptools-git', 'psycopg2', 'oursql'],
env=env)

shutil.copytree(cwd, os.path.join(virtualenv_directory, 'kotti'))

# install Kotti into the virtualenv
os.chdir('kotti')
subprocess.check_call([
os.path.join('..', 'bin', 'python'), 'setup.py', 'develop'])
os.chdir('..')

def delete_virtualenv():
shutil.rmtree(virtualenv_directory)
os.chdir(cwd)

request.addfinalizer(delete_virtualenv)

for pkgname in ('pip', 'wheel', 'setuptools', 'setuptools-git',
'psycopg2', 'oursql', ):
virtualenv.run('pip install -U ' + pkgname)

@slow
def test_scaffold_kotti_addon(virtualenv, travis):
pkg = [p for p in working_set if p.project_name == 'Kotti'][0]
d = {'python': virtualenv.python, 'src_dir': pkg.location, }

virtualenv.run('pip install -r %(src_dir)s/requirements.txt' % d)
if 'Kotti' in [p for p in virtualenv.installed_packages()]:
virtualenv.run('pip uninstall -y Kotti')
virtualenv.run('cd %(src_dir)s; %(python)s setup.py develop' % d)
virtualenv.run('cd %(src_dir)s; %(python)s setup.py dev' % d)

# create and develop an addon with the scaffold and run the generated tests
with travis.folding_output():

# print available scaffolds
subprocess.check_call([os.path.join('bin', 'pcreate'), '-l'])
virtualenv.run('pcreate -l')

# set some environment variables to make pcreate non interactive
os.environ["author"] = "Kotti developers"
os.environ["email"] = "kotti@googlegroups.com"
os.environ["gh_user"] = "Kotti"

# create a project from the scaffold
subprocess.check_call([
os.path.join('bin', 'pcreate'),
'-s', 'kotti', 'kotti_my_addon'])
virtualenv.run('pcreate -s kotti kotti_my_addon', env=os.environ)

# develop the package
os.chdir('kotti_my_addon')
subprocess.check_call([
os.path.join('..', 'bin', 'python'),
'setup.py', 'develop'])
subprocess.check_call([
os.path.join('..', 'bin', 'python'),
'setup.py', 'dev'])
cwd = os.path.join(virtualenv.workspace, 'kotti_my_addon')
virtualenv.run('python setup.py develop', cwd=cwd)
virtualenv.run('python setup.py dev', cwd=cwd)

# run the tests
subprocess.check_call([
os.path.join('..', 'bin', 'py.test')])
virtualenv.run('py.test', cwd=cwd)
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
Kotti==1.3.0-alpha.4
# Kotti==1.3.0a5.dev0

alembic==0.8.8
appdirs==1.4.0
Expand Down Expand Up @@ -35,10 +35,10 @@ js.jqueryui-tagit==2.0.24.post2
js.modernizr==2.5.3.1
js.select2==3.4.1
js.tinymce==4.2.7
kotti-image==0.1.3
kotti-image==0.1.4
kotti-tinymce==0.5.4
LEPL==5.1.3
lingua==4.9
lingua==4.10
Mako==1.0.4
MarkupSafe==0.23
PasteDeploy==1.5.2
Expand Down
8 changes: 6 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
'usersettings',
'waitress',
'zope.deprecation',
'zope.interface',
'zope.sqlalchemy',
]

Expand All @@ -63,17 +64,20 @@
'mock',
'py>=1.4.29',
'pyquery',
'pyramid_debugtoolbar',
'pytest>=3.0.0',
'pytest-cov',
'pytest-pep8!=1.0.3',
'pytest-travis-fold',
'pytest-virtualenv',
'pytest-warnings',
'pytest-xdist',
'virtualenv', # needed for scaffolding tests
'zope.testbrowser>=5.0.0',
]

development_requires = []
development_requires = [
'pyramid_debugtoolbar',
]

docs_require = [
'Sphinx',
Expand Down

0 comments on commit c7a0907

Please sign in to comment.