示例#1
0
def register_name_globally(name: str, obj):
    if name in get_all()['_global_name_dict'] and not id(obj) == id(
            get_all()['_global_name_dict'][name]) and obj.allow_duplicate_name is False and \
            get_all()['_global_name_dict'][
                name].allow_duplicate_name is False and GlobalConfig().DEFAULT_TURN_OFF_GLOBAL_NAME_FLAG is False:
        raise GlobalNameExistedError(
            'name : {} is existed with object: {}'.format(name, get_all()['_global_name_dict'][name]))
    else:
        get_all()['_global_name_dict'][name] = obj
示例#2
0
 def _save_all_obj_final_status(self):
     final_status = dict()
     for obj_name, obj in get_all()['_global_name_dict'].items():
         if hasattr(obj, 'get_status') and callable(
                 getattr(obj, 'get_status')):
             tmp_dict = dict()
             tmp_dict[obj_name] = dict()
             for st in obj.STATUS_LIST:
                 obj.set_status(st)
                 tmp_dict[obj_name][st] = obj.get_status()
             final_status = {**final_status, **tmp_dict}
     ConsoleLogger().print(
         'info', 'save final_status into {}'.format(
             os.path.join(self._record_file_log_dir)))
     self.out_to_file(file_path=os.path.join(self._record_file_log_dir),
                      content=final_status,
                      force_new=True,
                      file_name='final_status.json')
     ConsoleLogger().print(
         'info', 'save global_config into {}'.format(
             os.path.join(self._record_file_log_dir)))
     self.out_to_file(file_path=os.path.join(self._record_file_log_dir),
                      content=GlobalConfig().return_all_as_dict(),
                      force_new=True,
                      file_name='global_config.json')
示例#3
0
def get_global_arg_dict():
    return get_all()['_global_obj_arg_dict']
示例#4
0
 def wrap_with_self(self, *args, **kwargs):
     get_all()['_global_obj_arg_dict'][self] = dict(args=args,
                                                    kwargs=kwargs,
                                                    cls=type(self))
     res = fn(self, *args, **kwargs)
     return res
示例#5
0
 def setUp(self):
     reset_all()
     reset_global_status_collect()
     for key, val in get_all().items():
         self.assertTrue(len(val) == 0)