def test_specchio_init_with_init_remote(self): with mock.patch.object(SpecchioEventHandler, "init_gitignore") as _init_gitignore: with mock.patch.object(SpecchioEventHandler, "init_remote") as _init_remote: _init_gitignore.return_value = True _init_remote.return_value = True SpecchioEventHandler(src_path="/a/", dst_ssh="user@host", dst_path="/b/a/", is_init_remote=True) _init_remote.assert_called_once_with()
def setUp(self): with mock.patch.object(SpecchioEventHandler, "init_gitignore") as _init_gitignore: _init_gitignore.return_value = True self.handler = SpecchioEventHandler(src_path="/a/", dst_ssh="user@host", dst_path="/b/a/") self.handler.init_gitignore = mock.Mock() self.handler.gitignore_dict = { "/a/.gitignore": { 1: [], 2: [re.compile(fnmatch.translate("1.py"))], 3: [ re.compile(fnmatch.translate("test.py")), re.compile(fnmatch.translate("t_folder/")) ] } } self.handler.gitignore_list = ["/a/"]
def main(): """Main function for specchio Example: specchio test/ user@host:test/ :return: None """ init_logger() _popen_str = os.popen("whereis ssh").read().strip() if _popen_str == "" or _popen_str == "ssh:": return logger.error("Specchio need `ssh`, " "but there is no `ssh` in the system") _popen_str = os.popen("whereis rsync").read().strip() if _popen_str == "" or _popen_str == "rsync:": return logger.error("Specchio need `rsync`, " "but there is no `rsync` in the system") if len(sys.argv) >= 3: src_path = sys.argv[-2].strip() dst_ssh, dst_path = sys.argv[-1].strip().split(":") option_valid = all((option in GENERAL_OPTIONS) for option in sys.argv[1:-2]) if option_valid: logger.info("Initialize Specchio") is_init_remote = "--init-remote" in sys.argv[1:-2] event_handler = SpecchioEventHandler( src_path=src_path, dst_ssh=dst_ssh, dst_path=dst_path, is_init_remote=is_init_remote ) observer = Observer() observer.schedule(event_handler, src_path, recursive=True) observer.start() try: while True: time.sleep(1) except KeyboardInterrupt: observer.stop() observer.join() logger.info("Specchio stopped, have a nice day :)") else: print(MANUAL) else: print(MANUAL)
def test_init_gitignore(self, _get_all_re, _walk_get_gitignore): _walk_get_gitignore.return_value = ["/a/.gitignore"] _get_all_re.return_value = { "/a/.gitignore": { 1: [], 2: [re.compile(fnmatch.translate("1.py"))], 3: [re.compile(fnmatch.translate("test.py"))] } } handler = SpecchioEventHandler(src_path="/a/", dst_ssh="user@host", dst_path="/b/a/") _walk_get_gitignore.called_once_with("/a/") self.assertEqual(handler.gitignore_list, ["/a/"]) self.assertEqual( handler.gitignore_dict, { "/a/.gitignore": { 1: [], 2: [re.compile(fnmatch.translate("1.py"))], 3: [re.compile(fnmatch.translate("test.py"))] } })