def test_main(self, _SpecchioEventHandler, _init_logger, _Observer, _time, _sys, _os): _arg2ret = { "whereis ssh": io.StringIO(u"test_msg"), "whereis rsync": io.StringIO(u"test_msg") } _init_logger.return_value = True _os.popen.side_effect = (lambda arg: _arg2ret[arg]) _sys.argv = ["specchio", "/a/", "user@host:/b/a/"] _event_handler = mock.Mock() _SpecchioEventHandler.return_value = _event_handler _observer_object = mock.Mock() _Observer.return_value = _observer_object _time.sleep = mock.PropertyMock(side_effect=KeyboardInterrupt) with LogCapture() as log_capture: main() log_capture.check( ("specchio", "INFO", "Initialize Specchio"), ("specchio", "INFO", "Specchio stopped, have a nice day :)") ) _SpecchioEventHandler.assert_called_once_with( src_path="/a/", dst_ssh="user@host", dst_path="/b/a/" ) _observer_object.schedule.assert_called_once_with( _event_handler, "/a/", recursive=True ) _observer_object.stop.assert_called_once_with() _observer_object.join.assert_called_once_with()
def test_main(self, _SpecchioEventHandler, _init_logger, _Observer, _time, _sys, _os): _arg2ret = { "whereis ssh": io.StringIO(u"test_msg"), "whereis rsync": io.StringIO(u"test_msg") } _init_logger.return_value = True _os.popen.side_effect = (lambda arg: _arg2ret[arg]) _sys.argv = ["specchio", "/a/", "user@host:/b/a/"] _event_handler = mock.Mock() _SpecchioEventHandler.return_value = _event_handler _observer_object = mock.Mock() _Observer.return_value = _observer_object _time.sleep = mock.PropertyMock(side_effect=KeyboardInterrupt) with LogCapture() as log_capture: main() log_capture.check( ("specchio", "INFO", "Initialize Specchio"), ("specchio", "INFO", "Specchio stopped, have a nice day :)")) _SpecchioEventHandler.assert_called_once_with(src_path="/a/", dst_ssh="user@host", dst_path="/b/a/", is_init_remote=False) _observer_object.schedule.assert_called_once_with(_event_handler, "/a/", recursive=True) _observer_object.stop.assert_called_once_with() _observer_object.join.assert_called_once_with()
def test_main_no_ssh(self, _init_logger, _sys, _os): _init_logger.return_value = True _sys.argv = ["specchio"] _arg2ret = {"whereis ssh": io.StringIO(u"")} _os.popen.side_effect = (lambda arg: _arg2ret[arg]) with LogCapture() as log_capture: main() log_capture.check(("specchio", "ERROR", "Specchio need `ssh`, " "but there is no `ssh` in the system"))
def test_main_invalid(self, _SpecchioEventHandler, _sys, _os): _sys.argv = ["specchio"] _arg2ret = { "whereis ssh": io.StringIO(u"test_msg"), "whereis rsync": io.StringIO(u"test_msg") } _os.popen.side_effect = (lambda arg: _arg2ret[arg]) main() self.assertEqual(_SpecchioEventHandler.call_count, 0)
def test_main_with_wrong_options(self, _SpecchioEventHandler, _init_logger, _sys, _os): _arg2ret = { "whereis ssh": io.StringIO(u"test_msg"), "whereis rsync": io.StringIO(u"test_msg") } _init_logger.return_value = True _os.popen.side_effect = (lambda arg: _arg2ret[arg]) _sys.argv = ["specchio", "--test", "/a/", "user@host:/b/a/"] main() self.assertEqual(_SpecchioEventHandler.call_count, 0)
def test_main_no_ssh(self, _init_logger, _sys, _os): _init_logger.return_value = True _sys.argv = ["specchio"] _arg2ret = { "whereis ssh": io.StringIO(u"") } _os.popen.side_effect = (lambda arg: _arg2ret[arg]) with LogCapture() as log_capture: main() log_capture.check( ("specchio", "ERROR", "Specchio need `ssh`, " "but there is no `ssh` in the system") )