Skip to content

Commit

Permalink
TST: test the setup.py using the configure step
Browse files Browse the repository at this point in the history
Also make the setup less verbose
  • Loading branch information
GaelVaroquaux committed Jul 25, 2012
1 parent 993b6b4 commit 3b15f44
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
13 changes: 10 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
# Optional setuptools features

# For some commands, use setuptools
if len(set(('develop', 'sdist', 'release', 'bdist_egg', 'bdist_rpm',
'bdist', 'bdist_dumb', 'bdist_wininst', 'install_egg_info',
'build_sphinx', 'egg_info', 'easy_install', 'upload',
if len(set(('develop', 'release', 'bdist_egg', 'bdist_rpm',
'bdist_wininst', 'install_egg_info', 'build_sphinx',
'egg_info', 'easy_install', 'upload',
)).intersection(sys.argv)) > 0:
extra_setuptools_args = dict(
zip_safe=False, # the package can run out of an .egg file
Expand All @@ -43,6 +43,13 @@ def configuration(parent_package='', top_path=None):
from numpy.distutils.misc_util import Configuration
config = Configuration(None, parent_package, top_path)

# Avoid non-useful msg:
# "Ignoring attempt to set 'name' (from ... "
config.set_options(ignore_setup_xxx_py=True,
assume_default_configuration=True,
delegate_options_to_subpackages=True,
quiet=True)

config.add_subpackage('sklearn')

return config
Expand Down
27 changes: 27 additions & 0 deletions sklearn/tests/test_common.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
"""
General tests for all estimators in sklearn.
"""
import os
import warnings
import sys

import numpy as np
from nose.tools import assert_raises, assert_equal
from numpy.testing import assert_array_equal

import sklearn
from sklearn.utils.testing import all_estimators
from sklearn.utils.testing import assert_greater
from sklearn.base import clone, ClassifierMixin, RegressorMixin
Expand Down Expand Up @@ -163,3 +167,26 @@ def test_regressors_train():
reg.fit(X, y)
reg.predict(X)
assert_greater(reg.score(X, y), 0.5)


def test_configure():
# Smoke test the 'configure' step of setup, this tests all the
# 'configure' functions in the setup.pys in the scikit
cwd = os.getcwd()
setup_path = os.path.abspath(os.path.join(sklearn.__path__[0], '..'))
setup_filename = os.path.join(setup_path, 'setup.py')
if not os.path.exists(setup_filename):
return
try:
os.chdir(setup_path)
old_argv = sys.argv
sys.argv = ['setup.py', 'config']
with warnings.catch_warnings():
# The configuration spits out warnings when not finding
# Blas/Atlas development headers
warnings.simplefilter('ignore', UserWarning)
execfile('setup.py', dict(__name__='__main__'))
finally:
sys.argv = old_argv
os.chdir(cwd)

3 changes: 2 additions & 1 deletion sklearn/utils/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def is_abstract(c):
# get parent folder
path = sklearn.__path__
for importer, modname, ispkg in pkgutil.walk_packages(path=path,
prefix='sklearn.', onerror=lambda x: None):
prefix='sklearn.', onerror=lambda x: None):
module = __import__(modname, fromlist="dummy")
classes = inspect.getmembers(module, inspect.isclass)
# get rid of abstract base classes
Expand All @@ -147,3 +147,4 @@ def is_abstract(c):
estimators = [c for c in all_classes if issubclass(c[1], BaseEstimator)]
estimators = [c for c in estimators if not is_abstract(c[1])]
return estimators

0 comments on commit 3b15f44

Please sign in to comment.