def build(self): #基于类名自动创建初始文件 print('系统配置文件存储位置为:' + str(App.get_application_config(self))) #config = self.config return SystemLayout()
class MyDevoirsTestCase(GraphicUnitTest): TIMER = False def setUp(self, no_db=False): super().setUp() if not hasattr(self, "app"): self.app = App() Path(self.app.get_application_config()).unlink(missing_ok=True) if not self.app.config: self.app.config = ConfigParser() self.app.build_config(self.app.config) config = self.app.config for section, values in DEFAULT_SETTINGS.items(): config.setdefaults(section, values) if not no_db: init_update_matiere(db, reset=True) with db_session: for entity in db.entities.values(): if entity.__name__ != "Matiere": delete(e for e in entity) self.T = TempFile() EventLoop.ensure_window() self.window = EventLoop.window if self.TIMER: self.debut_time = time.time() def tearDown(self): super().tearDown() self.T.cleanup() self.unschedule_all() self.clear_window() if self.TIMER: print(f"durée: {(time.time()-self.debut_time)*1000}") if self.app.__class__.__name__ == App: del self.app def unschedule_all(self): for e in Clock.get_events(): Clock.unschedule(e) def clear_window(self): self.window.clear() [self.window.remove_widget(x) for x in self.window.children] def check_super_init(self, parent, enfant, *args, fn="__init__", **kwargs): module = self.__module__.split("_")[-1] full_parent = ".".join((APP_NAME.lower(), module, parent, fn)) with patch(full_parent) as m: try: enfant(*args, **kwargs) except Exception: pass assert m.called del enfant def add_to_window(self, w, clear=False): if clear: self.window.clear() self.window.add_widget(w) def press_key(self, key, scancode=None, codepoint=None, modifier=None, **kwargs): if isinstance(key, str): key = Keyboard.keycodes[key] self.window.dispatch("on_key_down", key, scancode, codepoint, modifier, **kwargs) def click(self, widget): t = get_touch(widget) t.click() # def move(self, widget, dx, dy): # t = get_touch(widget) # t.touch_down() # t.touch_move(dx,dy) # t.touch_up() def popup_click(self, choix): popup = self.window.children[0] popup.content.ids[choix].trigger_action(0)