Skip to content

Commit ee77f55

Browse files
committed
passing tests
1 parent 4c7fdf8 commit ee77f55

18 files changed

+269
-301
lines changed

.pylintrc

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[MESSAGES CONTROL]
2+
disable=locally-disabled,
3+
# False positive for type annotations with typing module
4+
# invalid-sequence-index,
5+
# False positive for OK test methods names and few other places
6+
invalid-name,
7+
# False positive for test file classes and methods
8+
missing-docstring
9+
10+
[REPORTS]
11+
# Simplify pylint reports
12+
reports=no
13+
14+
[SIMILARITIES]
15+
min-similarity-lines=10
16+
ignore-docstrings=yes

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ install:
1515
- |
1616
conda create -q -n test-environment python=$TRAVIS_PYTHON_VERSION cytoolz numpy pandas pip pytables pyyaml toolz psutil
1717
- source activate test-environment
18-
- pip install orca openmatrix zbox
18+
- pip install openmatrix zbox future
1919
- pip install pytest pytest-cov coveralls pycodestyle
2020
- pip install sphinx numpydoc sphinx_rtd_theme
2121
- pip install .

activitysim/abm/models/util/test/test_vectorize_tour_scheduling.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import pytest
66
import pandas as pd
77
import numpy as np
8-
import orca
98

109
import pandas.util.testing as pdt
1110

@@ -17,15 +16,15 @@
1716

1817
def test_vts():
1918

20-
orca.add_injectable("settings", {})
19+
inject.add_injectable("settings", {})
2120

2221
# note: need 0 duration tour on one end of day to guarantee at least one available tour
2322
alts = pd.DataFrame({
2423
"start": [1, 1, 2, 3],
2524
"end": [1, 4, 5, 6]
2625
})
2726
alts['duration'] = alts.end - alts.start
28-
orca.add_injectable("tdd_alts", alts)
27+
inject.add_injectable("tdd_alts", alts)
2928

3029
current_tour_person_ids = pd.Series(['b', 'c'],
3130
index=['d', 'e'])
@@ -54,13 +53,13 @@ def test_vts():
5453
persons = pd.DataFrame({
5554
"income": [20, 30, 25]
5655
}, index=[1, 2, 3])
57-
orca.add_table('persons', persons)
56+
inject.add_table('persons', persons)
5857

5958
spec = pd.DataFrame({"Coefficient": [1.2]},
6059
index=["income"])
6160
spec.index.name = "Expression"
6261

63-
orca.add_injectable("check_for_variability", True)
62+
inject.add_injectable("check_for_variability", True)
6463

6564
tdd_choices = vectorize_tour_scheduling(tours, persons, alts, spec)
6665

activitysim/abm/test/test_misc.py

+11-17
Original file line numberDiff line numberDiff line change
@@ -5,46 +5,40 @@
55
import tempfile
66

77
import numpy as np
8-
import orca
98
import pytest
109
import yaml
1110

12-
# orca injectables complicate matters because the decorators are executed at module load time
13-
# and since py.test collects modules and loads them at the start of a run
14-
# if a test method does something that has a lasting side-effect, then that side effect
15-
# will carry over not just to subsequent test functions, but to subsequently called modules
16-
# for instance, columns added with add_column will remain attached to orca tables
17-
# pytest-xdist allows us to run py.test with the --boxed option which runs every function
18-
# with a brand new python interpreter
11+
from activitysim.core import inject
1912

20-
# Also note that the following import statement has the side-effect of registering injectables:
13+
14+
# The following import statement has the side-effect of registering injectables:
2115
from .. import __init__
2216

2317

2418
def test_misc():
2519

26-
orca.clear_cache()
20+
inject.clear_cache()
2721

2822
with pytest.raises(RuntimeError) as excinfo:
29-
orca.get_injectable("configs_dir")
23+
inject.get_injectable("configs_dir")
3024
assert "directory does not exist" in str(excinfo.value)
3125

3226
with pytest.raises(RuntimeError) as excinfo:
33-
orca.get_injectable("data_dir")
27+
inject.get_injectable("data_dir")
3428
assert "directory does not exist" in str(excinfo.value)
3529

3630
with pytest.raises(RuntimeError) as excinfo:
37-
orca.get_injectable("output_dir")
31+
inject.get_injectable("output_dir")
3832
assert "directory does not exist" in str(excinfo.value)
3933

4034
configs_dir = os.path.join(os.path.dirname(__file__), 'configs_test_misc')
41-
orca.add_injectable("configs_dir", configs_dir)
35+
inject.add_injectable("configs_dir", configs_dir)
4236

43-
settings = orca.get_injectable("settings")
37+
settings = inject.get_injectable("settings")
4438
assert isinstance(settings, dict)
4539

4640
data_dir = os.path.join(os.path.dirname(__file__), 'data')
47-
orca.add_injectable("data_dir", data_dir)
41+
inject.add_injectable("data_dir", data_dir)
4842

4943
# default values if not specified in settings
50-
assert orca.get_injectable("chunk_size") == 0
44+
assert inject.get_injectable("chunk_size") == 0

activitysim/abm/test/test_pipeline.py

+21-28
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import logging
77

88
import numpy as np
9-
import orca
109
import pandas as pd
1110
import pandas.util.testing as pdt
1211
import pytest
@@ -35,7 +34,7 @@
3534

3635

3736
def teardown_function(func):
38-
orca.clear_cache()
37+
inject.clear_cache()
3938
inject.reinject_decorated_tables()
4039

4140

@@ -64,25 +63,25 @@ def inject_settings(configs_dir, households_sample_size, chunk_size=None,
6463
if check_for_variability is not None:
6564
settings['check_for_variability'] = check_for_variability
6665

67-
orca.add_injectable("settings", settings)
66+
inject.add_injectable("settings", settings)
6867

6968
return settings
7069

7170

7271
def test_rng_access():
7372

7473
configs_dir = os.path.join(os.path.dirname(__file__), 'configs')
75-
orca.add_injectable("configs_dir", configs_dir)
74+
inject.add_injectable("configs_dir", configs_dir)
7675

7776
output_dir = os.path.join(os.path.dirname(__file__), 'output')
78-
orca.add_injectable("output_dir", output_dir)
77+
inject.add_injectable("output_dir", output_dir)
7978

8079
data_dir = os.path.join(os.path.dirname(__file__), 'data')
81-
orca.add_injectable("data_dir", data_dir)
80+
inject.add_injectable("data_dir", data_dir)
8281

8382
inject_settings(configs_dir, households_sample_size=HOUSEHOLDS_SAMPLE_SIZE)
8483

85-
orca.clear_cache()
84+
inject.clear_cache()
8685

8786
inject.add_injectable('rng_base_seed', 0)
8887

@@ -91,7 +90,7 @@ def test_rng_access():
9190
rng = pipeline.get_rn_generator()
9291

9392
pipeline.close_pipeline()
94-
orca.clear_cache()
93+
inject.clear_cache()
9594

9695

9796
def regress_mini_auto():
@@ -149,22 +148,20 @@ def regress_mini_mtf():
149148
def test_mini_pipeline_run():
150149

151150
configs_dir = os.path.join(os.path.dirname(__file__), 'configs')
152-
orca.add_injectable("configs_dir", configs_dir)
151+
inject.add_injectable("configs_dir", configs_dir)
153152

154153
output_dir = os.path.join(os.path.dirname(__file__), 'output')
155-
orca.add_injectable("output_dir", output_dir)
154+
inject.add_injectable("output_dir", output_dir)
156155

157156
data_dir = os.path.join(os.path.dirname(__file__), 'data')
158-
orca.add_injectable("data_dir", data_dir)
157+
inject.add_injectable("data_dir", data_dir)
159158

160159
inject_settings(configs_dir, households_sample_size=HOUSEHOLDS_SAMPLE_SIZE)
161160

162-
orca.clear_cache()
161+
inject.clear_cache()
163162

164163
tracing.config_logger()
165164

166-
# assert len(orca.get_table("households").index) == HOUSEHOLDS_SAMPLE_SIZE
167-
168165
_MODELS = [
169166
'initialize_landuse',
170167
'compute_accessibility',
@@ -198,7 +195,7 @@ def test_mini_pipeline_run():
198195
assert "not in checkpoints" in str(excinfo.value)
199196

200197
pipeline.close_pipeline()
201-
orca.clear_cache()
198+
inject.clear_cache()
202199

203200
close_handlers()
204201

@@ -210,17 +207,17 @@ def test_mini_pipeline_run2():
210207
# when we restart pipeline
211208

212209
configs_dir = os.path.join(os.path.dirname(__file__), 'configs')
213-
orca.add_injectable("configs_dir", configs_dir)
210+
inject.add_injectable("configs_dir", configs_dir)
214211

215212
output_dir = os.path.join(os.path.dirname(__file__), 'output')
216-
orca.add_injectable("output_dir", output_dir)
213+
inject.add_injectable("output_dir", output_dir)
217214

218215
data_dir = os.path.join(os.path.dirname(__file__), 'data')
219-
orca.add_injectable("data_dir", data_dir)
216+
inject.add_injectable("data_dir", data_dir)
220217

221218
inject_settings(configs_dir, households_sample_size=HOUSEHOLDS_SAMPLE_SIZE)
222219

223-
orca.clear_cache()
220+
inject.clear_cache()
224221

225222
# should be able to get this BEFORE pipeline is opened
226223
checkpoints_df = pipeline.get_checkpoints()
@@ -249,21 +246,21 @@ def test_mini_pipeline_run2():
249246
assert len(checkpoints_df.index) == prev_checkpoint_count
250247

251248
pipeline.close_pipeline()
252-
orca.clear_cache()
249+
inject.clear_cache()
253250

254251

255252
def full_run(resume_after=None, chunk_size=0,
256253
households_sample_size=HOUSEHOLDS_SAMPLE_SIZE,
257254
trace_hh_id=None, trace_od=None, check_for_variability=None):
258255

259256
configs_dir = os.path.join(os.path.dirname(__file__), '..', '..', '..', 'example', 'configs')
260-
orca.add_injectable("configs_dir", configs_dir)
257+
inject.add_injectable("configs_dir", configs_dir)
261258

262259
data_dir = os.path.join(os.path.dirname(__file__), 'data')
263-
orca.add_injectable("data_dir", data_dir)
260+
inject.add_injectable("data_dir", data_dir)
264261

265262
output_dir = os.path.join(os.path.dirname(__file__), 'output')
266-
orca.add_injectable("output_dir", output_dir)
263+
inject.add_injectable("output_dir", output_dir)
267264

268265
settings = inject_settings(
269266
configs_dir,
@@ -273,7 +270,7 @@ def full_run(resume_after=None, chunk_size=0,
273270
trace_od=trace_od,
274271
check_for_variability=check_for_variability)
275272

276-
orca.clear_cache()
273+
inject.clear_cache()
277274

278275
tracing.config_logger()
279276

@@ -284,10 +281,6 @@ def full_run(resume_after=None, chunk_size=0,
284281
tours = pipeline.get_table('tours')
285282
tour_count = len(tours.index)
286283

287-
# pipeline.close_pipeline()
288-
#
289-
# orca.clear_cache()
290-
291284
return tour_count
292285

293286

activitysim/core/inject.py

+21
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# ActivitySim
2+
# See full license in LICENSE.txt.
3+
14
import logging
25

36
import pandas as pd
@@ -84,6 +87,7 @@ def add_table(table_name, table, cache=False):
8487
return orca.add_table(table_name, table, cache=cache)
8588

8689

90+
#fixme remove?
8791
def add_column(table_name, column_name, column, cache=False):
8892
return orca.add_column(table_name, column_name, column, cache=cache)
8993

@@ -114,6 +118,13 @@ def get_injectable(name, default=_NO_DEFAULT):
114118
return default
115119

116120

121+
def remove_injectable(name):
122+
123+
#fixme
124+
#del orca.orca._INJECTABLES[name]
125+
orca.orca._INJECTABLES.pop(name, None)
126+
127+
117128
def reinject_decorated_tables():
118129
"""
119130
reinject the decorated tables (and columns)
@@ -141,6 +152,10 @@ def reinject_decorated_tables():
141152
orca.add_injectable(name, args['func'], cache=args['cache'])
142153

143154

155+
def clear_cache():
156+
return orca.clear_cache()
157+
158+
144159
def set_step_args(args=None):
145160

146161
assert isinstance(args, dict) or args is None
@@ -156,3 +171,9 @@ def get_step_arg(arg_name, default=_NO_DEFAULT):
156171
raise "step arg '%s' not found and no default" % arg_name
157172

158173
return args.get(arg_name, default)
174+
175+
176+
def dump_state():
177+
178+
print "_DECORATED_STEPS", _DECORATED_STEPS.keys()
179+
print "orca._STEPS", orca.orca._STEPS.keys()

activitysim/core/orca/orca.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from collections import namedtuple
2525

2626
warnings.filterwarnings('ignore', category=tables.NaturalNameWarning)
27-
logger = logging.getLogger('orca')
27+
logger = logging.getLogger(__name__)
2828

2929
_TABLES = {}
3030
_COLUMNS = {}
@@ -1978,7 +1978,6 @@ def run(steps, iter_vars=None, data_out=None, out_interval=1,
19781978
'running iteration {} with iteration value {!r}'.format(
19791979
i, var))
19801980

1981-
t1 = time.time()
19821981
for j, step_name in enumerate(steps):
19831982
add_injectable('iter_step', iter_step(j, step_name))
19841983
with log_start_finish(

activitysim/core/pipeline.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# ActivitySim
2+
# See full license in LICENSE.txt.
3+
14
import os
25
import datetime as dt
36

@@ -224,6 +227,7 @@ def rewrap(table_name, df=None):
224227

225228
for column_name in orca.list_columns_for_table(table_name):
226229
# logger.debug("pop %s.%s: %s" % (table_name, column_name, t.column_type(column_name)))
230+
#fixme
227231
orca.orca._COLUMNS.pop((table_name, column_name), None)
228232

229233
# remove from orca's table list
@@ -501,7 +505,6 @@ def last_checkpoint():
501505
name of last checkpoint
502506
"""
503507

504-
#fixme
505508
if not _PIPELINE.is_open:
506509
raise RuntimeError("Pipeline is not open!")
507510

@@ -551,10 +554,11 @@ def run(models, resume_after=None):
551554

552555
if resume_after == '_':
553556
resume_after = _PIPELINE.last_checkpoint[CHECKPOINT_NAME]
554-
logger.info("Setting resume_after to %s" % (resume_after, ))
557+
558+
if resume_after:
559+
logger.info('resume_after %s' % resume_after)
555560
if resume_after in models:
556561
models = models[models.index(resume_after) + 1:]
557-
#bug
558562

559563
# preload any bulky injectables (e.g. skims) not in pipeline
560564
if orca.is_injectable('preload_injectables'):

0 commit comments

Comments
 (0)