def checkGUIModel(self, filename=None): file_path = os.path.join(project_path, "dream", "plugins", "testModels", filename) input_file = open(file_path, "r") input_data = input_file.read() input_file.close() logger = logging.getLogger('myLogger') pluginRegistry=PluginRegistry(logger=logger, data=json.loads(input_data)) result_data=pluginRegistry.run(data=json.loads(input_data)) # Slightly change the output to make it stable try: del result_data['result']['result_list'][0]["general"]["totalExecutionTime"] except KeyError: pass result_data['result']['result_list'][0]["elementList"].sort(key=lambda x: x["id"]) stable_result = json.dumps(result_data['result']['result_list'][0], indent=True, sort_keys=True) dump_path = os.path.join(self.dump_folder_path, "%s.result" % filename) if bool(os.environ.get("dump", False)): dump_file = open(dump_path, 'w') dump_file.write(stable_result) dump_file.close() dump_file = open(dump_path, "r") dump_result = json.dumps(json.loads(dump_file.read()), indent=True, sort_keys=True) dump_file.close() self.assertEquals(stable_result, dump_result, "outputs are different")
def _runSimulation(parameter_dict): try: registry = PluginRegistry(app.logger, parameter_dict) return dict(success=True, data=registry.run(parameter_dict)) except Exception: # Use simpy._compat to format exception chain in python2 if hasattr(simpy._compat, 'format_chain'): exc_type, exc_value, exc_traceback = sys.exc_info() tb = ''.join(simpy._compat.format_chain(exc_type, exc_value, exc_traceback)) else: assert sys.version_info[0] == 3 tb = traceback.format_exc() app.logger.error(tb) return dict(error=tb)