Skip to content

Commit

Permalink
add unit test to verify requirments for all Class
Browse files Browse the repository at this point in the history
  • Loading branch information
syhwawa committed May 18, 2023
1 parent 88c84b6 commit 0336dc9
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion tests/test_2_event_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
from elara.event_handlers import EventHandlerWorkStation, LinkVehicleCounts

from tests.test_helpers import get_vehicle_capacity_from_vehicles_xml_file
from elara.event_handlers import (VehiclePassengerGraph, StopPassengerWaiting, LinkVehicleCounts,
LinkVehicleCapacity, LinkVehicleSpeeds, LinkPassengerCounts,
StopPassengerCounts, StopToStopPassengerCounts,
VehicleStopToStopPassengerCounts, VehicleDepartureLog,
VehicleLinkLog, RoutePassengerCounts, AgentTollsLog,
VehicleLinksAnimate)


# paths in config files etc. assume we're in the repo's root, so make sure we always are
root_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
Expand Down Expand Up @@ -75,6 +82,30 @@ def test_tool_naming(test_config):
assert (str(tool)) == "LinkVehicleCountsAll"


def test_class_requirements(test_config):
# List all class with requirements
class_requirements = {
VehiclePassengerGraph: ['events', 'transit_vehicles', 'attributes', 'vehicles'],
StopPassengerWaiting: ['events', 'transit_schedule', 'attributes', 'vehicles'],
LinkVehicleCounts: ['events', 'network', 'transit_schedule', 'attributes', 'vehicles'],
LinkVehicleCapacity: ['events', 'network', 'transit_schedule', 'transit_vehicles', 'attributes', 'vehicles'],
LinkVehicleSpeeds: ['events', 'network', 'transit_schedule', 'attributes', 'vehicles'],
LinkPassengerCounts: ['events', 'network', 'transit_schedule', 'attributes', 'vehicles'],
StopPassengerCounts: ['events', 'network', 'transit_schedule', 'attributes', 'vehicles'],
StopToStopPassengerCounts: ['events', 'network', 'transit_schedule', 'attributes', 'vehicles'],
VehicleStopToStopPassengerCounts: ['events', 'network', 'transit_schedule', 'attributes', 'vehicles'],
VehicleDepartureLog: ['events', 'transit_schedule', 'vehicles'],
VehicleLinkLog: ['events', 'transit_schedule', 'vehicles'],
RoutePassengerCounts: ['events', 'network', 'transit_schedule', 'attributes', 'vehicles'],
AgentTollsLog: ['events', 'attributes', 'vehicles'],
VehicleLinksAnimate: ['events', 'transit_schedule', 'network', 'vehicles']
}

for cls, requirements in class_requirements.items():
instance = cls(test_config)
assert instance.requirements == requirements, f"Failed for class {cls.__name__}"


def handler_from_config(config_path):
config = Config(config_path)

Expand Down Expand Up @@ -144,7 +175,8 @@ def test_get_veh_mode(base_handler):

@pytest.fixture
def active_mode_handler():
config = os.path.join(test_dir, 'test_fixtures', 'active_modes', 'test_xml_scenario.toml')
config = os.path.join(test_dir, 'test_fixtures',
'active_modes', 'test_xml_scenario.toml')
return handler_from_config(config)


Expand Down Expand Up @@ -1748,3 +1780,4 @@ def test_load_all_event_handler_manager_with_mode_car_and_groupby_subpopulation(
cols = [t for t in range(handler.config.time_periods)]
df = gdf.loc[:, cols]
assert np.sum(df.values)

0 comments on commit 0336dc9

Please sign in to comment.