Skip to content

Commit

Permalink
Moving simulator tests so they are distributed as part of Prescient (#…
Browse files Browse the repository at this point in the history
…139)

* moving simulator tests so they are distributed as part of Prescient

* creating missing __init__ files

* using pytest for less verbosity

* specifying path for custom_data_provider

* including baselines in package_data
  • Loading branch information
bknueven authored Mar 1, 2022
1 parent 4d585d3 commit d7d92be
Show file tree
Hide file tree
Showing 171 changed files with 32 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,4 @@ jobs:
- name: Run Prescient Simulator Tests
run: |
python tests/simulator_tests/test_sim_rts_mod.py
pytest -v prescient/simulator/tests/test_simulator.py
Empty file added prescient/__init__.py
Empty file.
Empty file added prescient/data/__init__.py
Empty file.
Empty file.
Empty file.
Empty file.
Empty file added prescient/engine/__init__.py
Empty file.
Empty file added prescient/reporting/__init__.py
Empty file.
Empty file added prescient/scripts/__init__.py
Empty file.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,24 @@
import pandas as pd
import numpy as np

from prescient.downloaders import rts_gmlc
from prescient.scripts import runner
from tests.simulator_tests import simulator_diff

from prescient.simulator import Prescient

this_file_path = os.path.dirname(os.path.realpath(__file__))

class _SimulatorModRTSGMLC:
class SimulatorRegressionBase:
"""Test class for running the simulator."""
# arbitrary comparison threshold
COMPARISON_THRESHOLD = .01

def setUp(self):
self.this_file_path = this_file_path
self.test_cases_path = os.path.join(self.this_file_path, 'test_cases')

self._set_names()
self._run_simulator()

test_results_dir = os.path.join(self.test_cases_path, self.results_dir_name)
control_results_dir = os.path.join(self.test_cases_path, self.baseline_dir_name)
test_results_dir = os.path.join(self.test_case_path, self.results_dir_name)
control_results_dir = os.path.join(self.test_case_path, self.baseline_dir_name)

output_files = ["bus_detail",
"daily_summary",
Expand All @@ -55,7 +51,7 @@ def setUp(self):

def _run_simulator(self):
"""Runs the simulator for the test data set."""
os.chdir(self.test_cases_path)
os.chdir(self.test_case_path)

simulator_config_filename = self.simulator_config_filename
script, options = runner.parse_commands(simulator_config_filename)
Expand Down Expand Up @@ -129,8 +125,10 @@ def _assert_column_equality(self, filename, column_name):
assert diff, f"Column: '{column_name}' of File: '{filename}.csv' diverges."

# test runner.py with plugin
class TestSimulatorModRtsGmlcCopperSheet(_SimulatorModRTSGMLC, unittest.TestCase):
class TestSimulatorModRtsGmlcCopperSheet(SimulatorRegressionBase, unittest.TestCase):
def _set_names(self):
self.test_case_path = os.path.join(self.this_file_path, 'regression_tests_data')
# in self.test_case_path
self.simulator_config_filename = 'simulate_deterministic.txt'
self.results_dir_name = 'deterministic_simulation_output'
self.baseline_dir_name = 'deterministic_simulation_output_baseline'
Expand All @@ -155,26 +153,30 @@ def _set_names(self):
}

# test csv / text file configuration
class TestSimulatorModRtsGmlcCopperSheet_csv_python_config_file(_SimulatorModRTSGMLC, unittest.TestCase):
class TestSimulatorModRtsGmlcCopperSheet_csv_python_config_file(SimulatorRegressionBase, unittest.TestCase):
def _set_names(self):
self.test_case_path = os.path.join(self.this_file_path, 'regression_tests_data')
# in self.test_case_path
self.simulator_config_filename = 'simulate_deterministic_csv.txt'
self.results_dir_name = 'deterministic_simulation_csv_output'
self.baseline_dir_name = 'deterministic_simulation_output_baseline'

def _run_simulator(self):
os.chdir(self.test_cases_path)
os.chdir(self.test_case_path)
options = {'config_file' : self.simulator_config_filename}
Prescient().simulate(**options)

# test plugin with Python and *.dat files
class TestSimulatorModRtsGmlcNetwork_python(_SimulatorModRTSGMLC, unittest.TestCase):
class TestSimulatorModRtsGmlcNetwork_python(SimulatorRegressionBase, unittest.TestCase):

def _set_names(self):
self.test_case_path = os.path.join(self.this_file_path, 'regression_tests_data')
# in self.test_case_path
self.results_dir_name = 'deterministic_with_network_simulation_output_python'
self.baseline_dir_name = 'deterministic_with_network_simulation_output_baseline'

def _run_simulator(self):
os.chdir(self.test_cases_path)
os.chdir(self.test_case_path)
options = {**base_options}
options['data_path'] = 'deterministic_with_network_scenarios'
options['output_directory'] = 'deterministic_with_network_simulation_output_python'
Expand All @@ -183,45 +185,50 @@ def _run_simulator(self):
Prescient().simulate(**options)

# test options are correctly re-freshed, Python, and network
class TestSimulatorModRtsGmlcNetwork_python_csv(_SimulatorModRTSGMLC, unittest.TestCase):
class TestSimulatorModRtsGmlcNetwork_python_csv(SimulatorRegressionBase, unittest.TestCase):

def _set_names(self):
self.test_case_path = os.path.join(self.this_file_path, 'regression_tests_data')
# in self.test_case_path
self.results_dir_name = 'deterministic_with_network_simulation_output_python_csv'
self.baseline_dir_name = 'deterministic_with_network_simulation_output_baseline'

def _run_simulator(self):
os.chdir(self.test_cases_path)
os.chdir(self.test_case_path)
options = {**base_options}
options['data_path'] = 'deterministic_with_network_scenarios_csv'
options['output_directory'] = 'deterministic_with_network_simulation_output_python_csv'
options['input_format'] = 'rts-gmlc'
Prescient().simulate(**options)

# test shortcut / text file configuration
class TestShortcutSimulator_python_config_file(_SimulatorModRTSGMLC, unittest.TestCase):
class TestShortcutSimulator_python_config_file(SimulatorRegressionBase, unittest.TestCase):
def _set_names(self):
self.test_case_path = os.path.join(self.this_file_path, 'regression_tests_data')
# in self.test_case_path
self.simulator_config_filename = 'simulate_shortcut.txt'
self.results_dir_name = 'deterministic_shortcut_output'
self.baseline_dir_name = 'deterministic_shortcut_output_baseline'

def _run_simulator(self):
os.chdir(self.test_cases_path)
os.chdir(self.test_case_path)
options = {'config_file' : self.simulator_config_filename}
Prescient().simulate(**options)

class TestCustomDataSource(_SimulatorModRTSGMLC, unittest.TestCase):
class TestCustomDataSource(SimulatorRegressionBase, unittest.TestCase):
def _set_names(self):
self.test_case_path = os.path.join(self.this_file_path, 'regression_tests_data')
# in self.test_case_path
self.results_dir_name = 'custom_data_provider_output'
self.baseline_dir_name = 'deterministic_simulation_output_baseline'

def _run_simulator(self):
import custom_data_provider
options = {**base_options}
options['output_directory'] = 'custom_data_provider_output'
options['data_provider'] = custom_data_provider
options['data_provider'] = os.path.join(self.this_file_path, 'custom_data_provider.py')
options['data_path'] = 'custom_data.json'

os.chdir(self.test_cases_path)
os.chdir(self.test_case_path)
Prescient().simulate(**options)


Expand Down
7 changes: 3 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
# ___________________________________________________________________________

#!/bin/usr/env python
import glob
import sys
import os

# We raise an error if trying to install with less than python 3.7
if sys.version_info < (3,7):
Expand All @@ -36,10 +34,11 @@
'populator.py = prescient.scripts.populator:main',
'scenario_creator.py = prescient.scripts.scenario_creator:main',
'simulator.py = prescient.scripts.simulator:main',
#'prescient.py = prescient.simulator.prescient:main'
]
},
package_data={'prescient.downloaders.rts_gmlc_prescient':['runners/*.txt','runners/templates/*']},
package_data={'prescient.downloaders.rts_gmlc_prescient':['runners/*.txt','runners/templates/*'],
'prescient.simulator.tests':['regression_tests_data/**/*'],
},
install_requires=['numpy','matplotlib','pandas','scipy','pyomo>=6.1.2',
'python-dateutil','networkx','jupyter', 'gridx-egret>=0.5.2.dev0',
],
Expand Down

0 comments on commit d7d92be

Please sign in to comment.