Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for specifying build directory for tests #52

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ include doc/make.bat
include greenlet.c
include greenlet.h
include make-win-release
include my_build_ext.py
include platform/switch_aarch64_gcc.h
include platform/switch_amd64_unix.h
include platform/switch_arm32_gcc.h
Expand Down
2 changes: 1 addition & 1 deletion conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

def pytest_configure(config):
os.chdir(os.path.dirname(__file__))
cmd = [sys.executable, "setup.py", "-q", "build_ext", "-q"]
cmd = [sys.executable, "setup.py", "-q", "build_ext", "-q", "-i"]
spawn(cmd, search_path=0)

from tests import build_test_extensions
Expand Down
40 changes: 0 additions & 40 deletions my_build_ext.py

This file was deleted.

11 changes: 7 additions & 4 deletions run-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

build = True
verbosity = 2
build_base = None
here = os.path.dirname(os.path.abspath(__file__))
os.chdir(here)

Expand All @@ -16,7 +17,7 @@ def bits():

# -- parse options
try:
opts, args = getopt.getopt(sys.argv[1:], "nq")
opts, args = getopt.getopt(sys.argv[1:], "nqb:")
if args:
raise getopt.GetoptError("too many arguments")
except getopt.GetoptError:
Expand All @@ -27,13 +28,15 @@ def bits():
verbosity = 0
elif o == "-n":
build = False
elif o == "-b":
build_base = a

# -- build greenlet
if build:
if verbosity == 0:
cmd = [sys.executable, "setup.py", "-q", "build_ext", "-q"]
cmd = [sys.executable, "setup.py", "-q", "build_ext", "-q", "-i"]
else:
cmd = [sys.executable, "setup.py", "build_ext"]
cmd = [sys.executable, "setup.py", "build_ext", "-i"]

spawn(cmd, search_path=0)

Expand All @@ -55,5 +58,5 @@ def bits():

# -- run tests
from tests import test_collector
if unittest.TextTestRunner(verbosity=verbosity).run(test_collector()).failures:
if unittest.TextTestRunner(verbosity=verbosity).run(test_collector(build_base)).failures:
sys.exit(1)
34 changes: 26 additions & 8 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import os
import sys
import glob
import unittest
from distutils.core import setup, Extension
from distutils.command.build_ext import build_ext

TEST_EXTENSIONS = [
Extension('_test_extension',
Expand All @@ -20,11 +22,11 @@
TEST_EXTENSIONS_CPP = []


def test_collector():
def test_collector(build_base=None):
"""Collect all tests under the tests directory and return a
unittest.TestSuite
"""
build_test_extensions()
build_test_extensions(build_base)
tests_dir = os.path.realpath(os.path.dirname(__file__))
test_module_list = [
'tests.%s' % os.path.splitext(os.path.basename(t))[0]
Expand All @@ -34,21 +36,37 @@ def test_collector():
return unittest.TestLoader().loadTestsFromNames(test_module_list)


def build_test_extensions():
class build_test_ext(build_ext):
"""Command for building test extensions

Forces a non-inplace build and prepends library directory to sys.path.
"""
def build_extension(self, ext):
self.inplace = 0
build_ext.build_extension(self, ext)
build_lib = os.path.abspath(self.build_lib)
if build_lib not in sys.path:
if self.verbose:
sys.stderr.write('Adding %s to sys.path\n' % (build_lib,))
sys.path.insert(0, build_lib)


def build_test_extensions(build_base=None):
"""Because distutils sucks, it just copies the entire contents of the build
results dir (e.g. build/lib.linux-i686-2.6) during installation. That means
that we can't put any files there that we don't want to distribute.

To deal with it, this code will compile test extensions inplace, but
will use a separate directory for build files. This way testing with
To deal with it, this code will compile test extensions in a separate
directory, prepending it to sys.path afterwards. This way testing with
multiple Python release and pydebug versions works and test extensions
are not distributed.
"""
from my_build_ext import build_ext
if build_base is None:
build_base = os.path.join('build', 'tests')
setup(
options={
'build': {'build_base': os.path.join('build', 'tests')},
'build': {'build_base': build_base},
},
cmdclass=dict(build_ext=build_ext),
cmdclass=dict(build_ext=build_test_ext),
script_args=['-q', 'build_ext', '-q'],
ext_modules=TEST_EXTENSIONS + TEST_EXTENSIONS_CPP)