Skip to content

Commit bc5b003

Browse files
authored
Merge pull request #596 from EducationalTestingService/make-test-examples-testable-for-pkgs
Improve testability of `test_examples.py`.
2 parents b1a5e14 + 22b5770 commit bc5b003

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

tests/test_examples.py

+14-6
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
import subprocess
1010

1111
from glob import glob
12-
from os import getcwd, makedirs
13-
from os.path import abspath, basename, dirname, exists, join
12+
from os import environ, getcwd, makedirs
13+
from os.path import abspath, basename, dirname, exists, join, normpath
1414
from shutil import copytree, copyfile, rmtree
1515

1616
from nose.tools import eq_, assert_almost_equal
@@ -20,7 +20,7 @@
2020

2121
_my_cwd = getcwd()
2222
_my_dir = abspath(dirname(__file__))
23-
_examples_dir = join(_my_dir, '..', 'examples')
23+
_examples_dir = normpath(join(_my_dir, '..', 'examples'))
2424

2525
_old_titanic_dir = join(_examples_dir, 'titanic')
2626
_old_boston_dir = join(_examples_dir, 'boston')
@@ -30,6 +30,13 @@
3030
_new_boston_dir = join(_my_dir, 'other', 'boston')
3131
_new_iris_dir = join(_my_dir, 'other', 'iris')
3232

33+
# if we are running the tests without activating the conda
34+
# environment (as we do when testing the conda and TestPyPI
35+
# packages), then we will usually pass in a BINDIR environment
36+
# variable that points to where the environment's `bin` directory
37+
# is located
38+
_binary_dir = environ.get('BINDIR', '')
39+
3340

3441
def run_configuration_and_check_outputs(config_path):
3542
"""
@@ -90,11 +97,12 @@ def setup():
9097
copytree(_old_titanic_dir, _new_titanic_dir)
9198

9299
# Create all of the data sets we need
93-
subprocess.run(['python', join(_examples_dir, 'make_titanic_example_data.py')],
100+
python_binary = join(_binary_dir, 'python') if _binary_dir else 'python'
101+
subprocess.run([python_binary, join(_examples_dir, 'make_titanic_example_data.py')],
94102
cwd=dirname(_new_titanic_dir))
95-
subprocess.run(['python', join(_examples_dir, 'make_boston_example_data.py')],
103+
subprocess.run([python_binary, join(_examples_dir, 'make_boston_example_data.py')],
96104
cwd=dirname(_new_boston_dir))
97-
subprocess.run(['python', join(_examples_dir, 'make_iris_example_data.py')],
105+
subprocess.run([python_binary, join(_examples_dir, 'make_iris_example_data.py')],
98106
cwd=dirname(_new_iris_dir))
99107

100108
# Move all the configuration files to our new directories

tests/test_input.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
from glob import glob
1616
from itertools import product
17-
from os.path import abspath, dirname, exists, join, normpath
17+
from os.path import abspath, dirname, exists, join, normcase, normpath
1818
from shutil import rmtree
1919

2020
import numpy as np
@@ -1141,7 +1141,8 @@ def test_config_parsing_relative_input_path():
11411141
class_map, custom_learner_path, learning_curve_cv_folds_list,
11421142
learning_curve_train_sizes, output_metrics) = _parse_config_file(config_path)
11431143

1144-
eq_(normpath(train_path), (join(_my_dir, 'train')))
1144+
# we need to use normcase here for Azure package builds to pass
1145+
eq_(normcase(normpath(train_path)), normcase(join(_my_dir, 'train')))
11451146

11461147

11471148
def test_config_parsing_relative_input_paths():

0 commit comments

Comments
 (0)