forked from ActivitySim/activitysim
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
set up testing infrastructure (ActivitySim#40)
Co-authored-by: Lisa Zorn <lzorn@bayareametro.gov>
- Loading branch information
1 parent
7c67f35
commit 43cd89c
Showing
6 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import os | ||
|
||
import orca | ||
import pandas as pd | ||
import pytest | ||
from activitysim.core import pipeline | ||
from activitysim.core.los import Network_LOS as los | ||
|
||
|
||
@pytest.fixture(scope='module') | ||
def initialize_pipeline(module: str, tables: dict[str, str], initialize_network_los: bool) -> pipeline.Pipeline: | ||
test_dir = os.path.join('test', module) | ||
configs_dir = os.path.join(test_dir, 'configs') | ||
data_dir = os.path.join(test_dir, 'data') | ||
output_dir = os.path.join(test_dir, 'output') | ||
|
||
if os.path.isdir(configs_dir): | ||
orca.add_injectable('configs_dir', configs_dir) | ||
|
||
if os.path.isdir(data_dir): | ||
orca.add_injectable('data_dir', data_dir) | ||
|
||
if os.path.isdir(test_dir): | ||
if not os.path.isdir(output_dir): | ||
os.mkdir(output_dir) | ||
orca.add_injectable('output_dir', output_dir) | ||
|
||
# Read in the input test dataframes | ||
for dataframe_name, idx_name in tables.items(): | ||
df = pd.read_csv( | ||
os.path.join('test', module, 'data', f'{dataframe_name}.csv'), index_col=idx_name | ||
) | ||
orca.add_table(dataframe_name, df) | ||
|
||
if initialize_network_los: | ||
net_los = los() | ||
net_los.load_data() | ||
orca.add_injectable('network_los', net_los) | ||
|
||
# Add an output directory in current working directory if it's not already there | ||
try: | ||
os.makedirs('output') | ||
except FileExistsError: | ||
# directory already exists | ||
pass | ||
|
||
# Add the dataframes to the pipeline | ||
pipeline.open_pipeline() | ||
pipeline.add_checkpoint(module) | ||
pipeline.close_pipeline() | ||
|
||
# By convention, this method needs to yield something | ||
yield pipeline._PIPELINE | ||
|
||
if pipeline.is_open(): | ||
pipeline.close_pipeline() | ||
|
||
@pytest.fixture(scope='module') | ||
def reconnect_pipeline(module: str, initialize_network_los: bool, load_checkpoint: str) -> pipeline.Pipeline: | ||
test_dir = os.path.join('test', module) | ||
configs_dir = os.path.join(test_dir, 'configs') | ||
data_dir = os.path.join(test_dir, 'data') | ||
output_dir = os.path.join(test_dir, 'output') | ||
|
||
if os.path.isdir(configs_dir): | ||
orca.add_injectable('configs_dir', configs_dir) | ||
|
||
if os.path.isdir(data_dir): | ||
orca.add_injectable('data_dir', data_dir) | ||
|
||
if os.path.isdir(test_dir): | ||
if not os.path.isdir(output_dir): | ||
os.mkdir(output_dir) | ||
orca.add_injectable('output_dir', output_dir) | ||
|
||
# Read in the existing pipeline | ||
orca.add_injectable('pipeline_file_path', output_dir) | ||
|
||
if initialize_network_los: | ||
net_los = los() | ||
net_los.load_data() | ||
orca.add_injectable('network_los', net_los) | ||
|
||
# Add an output directory in current working directory if it's not already there | ||
try: | ||
os.makedirs('output') | ||
except FileExistsError: | ||
# directory already exists | ||
pass | ||
|
||
pipeline.open_pipeline(resume_after=load_checkpoint) | ||
pipeline.add_checkpoint(module) | ||
pipeline.close_pipeline() | ||
# By convention, this method needs to yield something | ||
yield pipeline._PIPELINE | ||
|
||
# pytest teardown code | ||
if pipeline.is_open(): | ||
pipeline.close_pipeline() |
Empty file.
Empty file.
Empty file.