Пример #1
0
        }

    return scenario_data


# collect template path
file_path = os.path.join(config.PROJECT_PATH,
                         'flow/utils/aimsun/aimsun_template_path')
with open(file_path, 'r') as f:
    template_path = f.readline()
os.remove(file_path)

# open template in Aimsun
print('[load.py] Loading template ' + template_path)
model = AimsunTemplate(GKSystem, GKGUISystem)
model.load(template_path)

# collect the simulation parameters
params_file = 'flow/core/kernel/scenario/data.json'
params_path = os.path.join(config.PROJECT_PATH, params_file)
with open(params_path) as f:
    data = json.load(f)

# retrieve replication by name
replication_name = data['replication_name']
replication = model.find_by_name(model.replications, replication_name)

if replication is None:
    print('[load.py] ERROR: Replication ' + replication_name +
          ' does not exist.')
    def test_new_and_load(self):
        """Tests that the new/load/save functions call the correct Aimsun
        methods and in the right order
        """
        class TestGUI(object):
            """Substitution for Aimsun's GGui class"""
            def __init__(self):
                self.called = []

            def getActiveModel(self):
                self.called += ['getActiveModel']

            def loadNetwork(self, path):
                self.called += ['loadNetwork']

            def newDoc(self, path):
                self.called += ['newDoc']

            def newSimpleDoc(self):
                self.called += ['newSimpleDoc']

            def saveAs(self, path):
                self.called += ['saveAs']

            def reset(self):
                self.called = []

        class TestGUISystem(object):
            """Substitution for Aimsun's GKGUISystem class"""
            def __init__(self):
                self.active_gui = None

            def getActiveGui(self):
                if self.active_gui is None:
                    self.active_gui = TestGUI()
                return self.active_gui

            def getGUISystem(self):
                return self

        test_gui_system = TestGUISystem()
        model = AimsunTemplate(GKSystem=None, GKGUISystem=test_gui_system)
        test_gui = test_gui_system.active_gui

        self.assertIsNotNone(test_gui)
        self.assertEqual(test_gui.called, ['getActiveModel'])

        test_gui.reset()
        model.load('path')
        self.assertEqual(test_gui.called, ['loadNetwork', 'getActiveModel'])

        test_gui.reset()
        model.new_duplicate('path')
        self.assertEqual(test_gui.called, ['newDoc', 'getActiveModel'])

        test_gui.reset()
        model.new_empty()
        self.assertEqual(test_gui.called, ['newSimpleDoc', 'getActiveModel'])

        test_gui.reset()
        model.save('path')
        self.assertEqual(test_gui.called, ['saveAs'])