Skip to content

Commit

Permalink
Remove SBN flag
Browse files Browse the repository at this point in the history
  • Loading branch information
the-other-james committed Sep 22, 2023
1 parent e104750 commit 0e1b79f
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 131 deletions.
1 change: 0 additions & 1 deletion onair/config/default_config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ PluginList = {'generic_plugin':'plugins/generic/generic_plugin.py'}
[RUN_FLAGS]
IO_Flag = true
Dev_Flag = false
SBN_Flag = false
Viz_Flag = false
5 changes: 1 addition & 4 deletions onair/src/run_scripts/execution_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ def __init__(self, config_file='', run_name='', save_flag=False):
# Init Flags
self.IO_Flag = False
self.Dev_Flag = False
self.SBN_Flag = False
self.Viz_Flag = False

# Init Paths
Expand Down Expand Up @@ -101,7 +100,6 @@ def parse_configs(self, config_filepath):
## Parse Optional Data: Flags
self.IO_Flag = config['RUN_FLAGS'].getboolean('IO_Flag')
self.Dev_Flag = config['RUN_FLAGS'].getboolean('Dev_Flag')
self.SBN_Flag = config['RUN_FLAGS'].getboolean('SBN_Flag')
self.Viz_Flag = config['RUN_FLAGS'].getboolean('Viz_Flag')

## Parse Optional Data: Benchmarks
Expand All @@ -115,12 +113,11 @@ def parse_configs(self, config_filepath):
def parse_data(self, parser_name, parser_file_name, data_file_name, metadata_file_name, subsystems_breakdown=False):
parser = importlib.import_module('onair.data_handling.' + parser_file_name)
parser_class = getattr(parser, parser_name) # This could be simplified if the parsers all extend a parser class... but this works for now
# TODO: This will be changed on an OnAIR Data Source
data_parser = parser_class(data_file_name, metadata_file_name, subsystems_breakdown)
self.simDataParser = data_parser

def setup_sim(self):
self.sim = Simulator(self.sim_name, self.simDataParser, self.plugin_list, self.SBN_Flag)
self.sim = Simulator(self.sim_name, self.simDataParser, self.plugin_list)
try:
fls = ast.literal_eval(self.benchmarkFiles)
fp = os.path.dirname(os.path.realpath(__file__)) + '/../..' + self.benchmarkFilePath
Expand Down
15 changes: 2 additions & 13 deletions onair/src/run_scripts/sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,9 @@
DIAGNOSIS_INTERVAL = 100

class Simulator:
def __init__(self, simType, dataParser, plugin_list, SBN_Flag):
def __init__(self, simType, dataParser, plugin_list):
self.simulator = simType

if SBN_Flag:
# TODO: This is ugly, but sbn_client is only available when built for cFS...
# ...from sbn_adapter import AdapterDataSource
sbn_adapter = importlib.import_module('onair.src.run_scripts.sbn_adapter')
AdapterDataSource = getattr(sbn_adapter, 'AdapterDataSource')
self.simData = AdapterDataSource(dataParser.get_just_data())
self.simData.connect() # this also subscribes to the msgIDs

else:
#self.simData = DataSource(dataParser.get_just_data())
self.simData = dataParser
self.simData = dataParser

headers, tests = dataParser.get_vehicle_metadata()
vehicle = VehicleRepresentation(headers, tests)
Expand Down
19 changes: 6 additions & 13 deletions test/onair/src/run_scripts/test_execution_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def test_ExecutionEngine__init__sets_expected_values_but_does_no_calls_when_conf
assert cut.run_name == arg_run_name
assert cut.IO_Flag == False
assert cut.Dev_Flag == False
assert cut.SBN_Flag == False
assert cut.Viz_Flag == False
assert cut.dataFilePath == ''
assert cut.telemetryFile == ''
Expand Down Expand Up @@ -298,7 +297,6 @@ def test_ExecutionEngine_parse_configs_sets_all_items_without_error(mocker):
fake_config_read_result.__len__.return_value = 1
fake_IO_flags = MagicMock()
fake_Dev_flags = MagicMock()
fake_SBN_flags = MagicMock()
fake_Viz_flags = MagicMock()
fake_plugin_dict= MagicMock()
fake_keys = MagicMock()
Expand All @@ -312,7 +310,7 @@ def test_ExecutionEngine_parse_configs_sets_all_items_without_error(mocker):

mocker.patch(execution_engine.__name__ + '.configparser.ConfigParser', return_value=fake_config)
mocker.patch.object(fake_config, 'read', return_value=fake_config_read_result)
mocker.patch.object(fake_run_flags, 'getboolean', side_effect=[fake_IO_flags, fake_Dev_flags, fake_SBN_flags, fake_Viz_flags])
mocker.patch.object(fake_run_flags, 'getboolean', side_effect=[fake_IO_flags, fake_Dev_flags, fake_Viz_flags])
mocker.patch.object(cut, 'ast_parse_eval', return_value=fake_plugin_list)
mocker.patch(execution_engine.__name__ + '.isinstance', return_value=True)
mocker.patch(execution_engine.__name__ + '.ast.literal_eval', return_value=fake_temp_plugin_list)
Expand All @@ -338,14 +336,12 @@ def test_ExecutionEngine_parse_configs_sets_all_items_without_error(mocker):
assert cut.parser_name == fake_default['ParserName']
assert cut.sim_name == fake_default['SimName']
assert cut.plugin_list == fake_temp_plugin_list
assert fake_run_flags.getboolean.call_count == 4
assert fake_run_flags.getboolean.call_count == 3
assert fake_run_flags.getboolean.call_args_list[0].args == ('IO_Flag', )
assert cut.IO_Flag == fake_IO_flags
assert fake_run_flags.getboolean.call_args_list[1].args == ('Dev_Flag', )
assert cut.Dev_Flag == fake_Dev_flags
assert fake_run_flags.getboolean.call_args_list[2].args == ('SBN_Flag', )
assert cut.SBN_Flag == fake_SBN_flags
assert fake_run_flags.getboolean.call_args_list[3].args == ('Viz_Flag', )
assert fake_run_flags.getboolean.call_args_list[2].args == ('Viz_Flag', )
assert cut.Viz_Flag == fake_Viz_flags

def test_ExecutionEngine_parse_configs_bypasses_benchmarks_when_access_raises_error(mocker):
Expand All @@ -370,7 +366,6 @@ def test_ExecutionEngine_parse_configs_bypasses_benchmarks_when_access_raises_er
fake_config_read_result.__len__.return_value = 1
fake_IO_flags = MagicMock()
fake_Dev_flags = MagicMock()
fake_SBN_flags = MagicMock()
fake_Viz_flags = MagicMock()
fake_plugin_dict = MagicMock()
fake_keys = MagicMock()
Expand All @@ -384,7 +379,7 @@ def test_ExecutionEngine_parse_configs_bypasses_benchmarks_when_access_raises_er

mocker.patch(execution_engine.__name__ + '.configparser.ConfigParser', return_value=fake_config)
mocker.patch.object(fake_config, 'read', return_value=fake_config_read_result)
mocker.patch.object(fake_run_flags, 'getboolean', side_effect=[fake_IO_flags, fake_Dev_flags, fake_SBN_flags, fake_Viz_flags])
mocker.patch.object(fake_run_flags, 'getboolean', side_effect=[fake_IO_flags, fake_Dev_flags, fake_Viz_flags])
mocker.patch('ast.literal_eval',return_value=fake_plugin_dict)
mocker.patch.object(fake_plugin_dict, 'keys', return_value=fake_keys)
mocker.patch.object(fake_plugin_dict, '__getitem__', return_value=fake_path)
Expand Down Expand Up @@ -520,7 +515,6 @@ def test_ExecutionEngine_setup_sim_sets_self_sim_to_new_Simulator_and_sets_bench
cut = ExecutionEngine.__new__(ExecutionEngine)
cut.sim_name = MagicMock()
cut.simDataParser = MagicMock()
cut.SBN_Flag = MagicMock()
cut.benchmarkFiles = MagicMock()
cut.benchmarkFilePath = MagicMock()
cut.benchmarkIndices = MagicMock()
Expand All @@ -546,7 +540,7 @@ def test_ExecutionEngine_setup_sim_sets_self_sim_to_new_Simulator_and_sets_bench

# Assert
assert execution_engine.Simulator.call_count == 1
assert execution_engine.Simulator.call_args_list[0].args == (cut.sim_name, cut.simDataParser, cut.plugin_list, cut.SBN_Flag)
assert execution_engine.Simulator.call_args_list[0].args == (cut.sim_name, cut.simDataParser, cut.plugin_list)
assert cut.sim == fake_sim
assert execution_engine.ast.literal_eval.call_count == 2
assert execution_engine.ast.literal_eval.call_args_list[0].args == (cut.benchmarkFiles, )
Expand All @@ -561,7 +555,6 @@ def test_ExecutionEngine_setup_sim_sets_self_sim_to_new_Simulator_but_does_not_s
cut = ExecutionEngine.__new__(ExecutionEngine)
cut.sim_name = MagicMock()
cut.simDataParser = MagicMock()
cut.SBN_Flag = MagicMock()
cut.benchmarkFiles = MagicMock()
cut.benchmarkFilePath = MagicMock()
cut.benchmarkIndices = MagicMock()
Expand All @@ -586,7 +579,7 @@ def test_ExecutionEngine_setup_sim_sets_self_sim_to_new_Simulator_but_does_not_s

# Assert
assert execution_engine.Simulator.call_count == 1
assert execution_engine.Simulator.call_args_list[0].args == (cut.sim_name, cut.simDataParser, cut.plugin_list, cut.SBN_Flag)
assert execution_engine.Simulator.call_args_list[0].args == (cut.sim_name, cut.simDataParser, cut.plugin_list)
assert cut.sim == fake_sim
assert execution_engine.ast.literal_eval.call_count == 1
assert execution_engine.ast.literal_eval.call_args_list[0].args == (cut.benchmarkFiles, )
Expand Down
102 changes: 2 additions & 100 deletions test/onair/src/run_scripts/test_sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,75 +17,25 @@
from math import ceil, floor

# __init__ tests
def test_Simulator__init__creates_Vehicle_and_AdapterDataSource_from_parsed_data_and_Agent_with_vehicle_when_SBN_Flag_resolves_to_True(mocker):
def test_Simulator__init__creates_Vehicle_and_Agent(mocker):
# Arrange
arg_simType = MagicMock()
arg_dataParser = MagicMock()
arg_SBN_Flag = True if (pytest.gen.randint(0,1) == 0) else MagicMock()

class FakeDataAdapterSource:
def __init__(self, sim_data):
FakeDataAdapterSource.simData = self
FakeDataAdapterSource.sim_data = sim_data

def connect(self):
if hasattr(FakeDataAdapterSource, 'connect_call_count'):
FakeDataAdapterSource.connect_call_count += 1
else:
FakeDataAdapterSource.connect_call_count = 1

fake_vehicle_metadata = [MagicMock(), MagicMock()]
fake_vehicle = MagicMock()
fake_sim_data = MagicMock()
fake_sbn_adapter = MagicMock()
fake_simData = MagicMock()
fake_agent = MagicMock()

cut = Simulator.__new__(Simulator)

mocker.patch.object(arg_dataParser, 'get_vehicle_metadata', return_value=fake_vehicle_metadata)
mocker.patch(sim.__name__ + '.vehicle', return_value=fake_vehicle)
mocker.patch(sim.__name__ + '.importlib.import_module', return_value=fake_sbn_adapter)
mocker.patch(sim.__name__ + '.getattr', return_value=FakeDataAdapterSource)
mocker.patch.object(arg_dataParser, 'get_just_data', return_value=fake_sim_data)
mocker.patch(sim.__name__ + '.Agent', return_value=fake_agent)

# Act
cut.__init__(arg_simType, arg_dataParser, arg_SBN_Flag)

# Assert
assert cut.simulator == arg_simType
assert sim.vehicle.call_count == 1
assert sim.vehicle.call_args_list[0].args == (fake_vehicle_metadata[0], fake_vehicle_metadata[1], )
assert FakeDataAdapterSource.simData == cut.simData
assert FakeDataAdapterSource.sim_data == fake_sim_data
assert FakeDataAdapterSource.connect_call_count == 1
assert sim.Agent.call_count == 1
assert sim.Agent.call_args_list[0].args == (fake_vehicle, )
assert cut.agent == fake_agent

def test_Simulator__init__creates_Vehicle_and_DataSource_from_parsed_data_and_Agent_with_vehicle_when_SBN_Flag_resolves_to_False(mocker):
# Arrange
arg_simType = MagicMock()
arg_dataParser = MagicMock()
arg_SBN_Flag = False if (pytest.gen.randint(0,1) == 0) else None
arg_plugin_list = MagicMock()

fake_vehicle_metadata = [MagicMock(), MagicMock()]
fake_vehicle = MagicMock()
fake_sim_data = MagicMock()
fake_simData = MagicMock()
fake_agent = MagicMock()

cut = Simulator.__new__(Simulator)

mocker.patch.object(arg_dataParser, 'get_vehicle_metadata', return_value=fake_vehicle_metadata)
mocker.patch(sim.__name__ + '.VehicleRepresentation', return_value=fake_vehicle)
mocker.patch.object(arg_dataParser, 'get_just_data', return_value=fake_sim_data)
mocker.patch(sim.__name__ + '.Agent', return_value=fake_agent)

# Act
cut.__init__(arg_simType, arg_dataParser, arg_plugin_list, arg_SBN_Flag)
cut.__init__(arg_simType, arg_dataParser, arg_plugin_list)

# Assert
assert cut.simulator == arg_simType
Expand All @@ -96,54 +46,6 @@ def test_Simulator__init__creates_Vehicle_and_DataSource_from_parsed_data_and_Ag
assert sim.Agent.call_args_list[0].args == (fake_vehicle, arg_plugin_list)
assert cut.agent == fake_agent

def test_Simulator__init__creates_Vehicle_and_AdapterDataSource_from_parsed_data_and_Agent_with_vehicle_when_SBN_Flag_resolves_to_True(mocker):
# Arrange
arg_simType = MagicMock()
arg_dataParser = MagicMock()
arg_SBN_Flag = True if (pytest.gen.randint(0,1) == 0) else MagicMock()

class FakeDataAdapterSource:
def __init__(self, sim_data):
FakeDataAdapterSource.simData = self
FakeDataAdapterSource.sim_data = sim_data

def connect(self):
if hasattr(FakeDataAdapterSource, 'connect_call_count'):
FakeDataAdapterSource.connect_call_count += 1
else:
FakeDataAdapterSource.connect_call_count = 1

fake_vehicle_metadata = [MagicMock(), MagicMock()]
fake_vehicle = MagicMock()
fake_sim_data = MagicMock()
fake_sbn_adapter = MagicMock()
fake_simData = MagicMock()
fake_agent = MagicMock()
fake_plugin_list = MagicMock()

cut = Simulator.__new__(Simulator)

mocker.patch.object(arg_dataParser, 'get_vehicle_metadata', return_value=fake_vehicle_metadata)
mocker.patch(sim.__name__ + '.VehicleRepresentation', return_value=fake_vehicle)
mocker.patch(sim.__name__ + '.importlib.import_module', return_value=fake_sbn_adapter)
mocker.patch(sim.__name__ + '.getattr', return_value=FakeDataAdapterSource)
mocker.patch.object(arg_dataParser, 'get_just_data', return_value=fake_sim_data)
mocker.patch(sim.__name__ + '.Agent', return_value=fake_agent)

# Act
cut.__init__(arg_simType, arg_dataParser, fake_plugin_list, arg_SBN_Flag)

# Assert
assert cut.simulator == arg_simType
assert sim.VehicleRepresentation.call_count == 1
assert sim.VehicleRepresentation.call_args_list[0].args == (fake_vehicle_metadata[0], fake_vehicle_metadata[1], )
assert FakeDataAdapterSource.simData == cut.simData
assert FakeDataAdapterSource.sim_data == fake_sim_data
assert FakeDataAdapterSource.connect_call_count == 1
assert sim.Agent.call_count == 1
assert sim.Agent.call_args_list[0].args == (fake_vehicle, fake_plugin_list)
assert cut.agent == fake_agent

# run_sim tests
def test_Simulator_run_sim_simData_never_has_more_so_loop_does_not_run_and_diagnosis_list_is_empty_but_filled_with_agent_diagnose_and_returns_last_diagnosis(mocker):
# Arrange
Expand Down

0 comments on commit 0e1b79f

Please sign in to comment.