def test_add_bookmark(self, monkeypatch): fcontent = '{"123":"abc"}' with mock.patch.object(builtins, 'open', mock.mock_open(read_data=fcontent)): monkeypatch.setattr('sys.argv', ['focli', '-a', '157']) assert focli.main() == 0 monkeypatch.setattr('sys.argv', ['focli', '-a']) assert focli.main() == 1
def test_main_show_stops(self, monkeypatch): monkeypatch.setattr('sys.argv', ['focli', '157', '123', '420']) def mock_return(a): return True monkeypatch.setattr('focli.focli.show_stops', mock_return) assert focli.main() is True
def test_main_list_bookmarks(self, monkeypatch): monkeypatch.setattr('sys.argv', ['focli', '-l']) def mock_return(): return True monkeypatch.setattr('focli.focli.list_bookmarks', mock_return) assert focli.main() is True
def test_main_del_bookmark(self, monkeypatch): monkeypatch.setattr('sys.argv', ['focli', '-d', '157']) def mock_return(a): return True monkeypatch.setattr('focli.focli.del_bookmark', mock_return) assert focli.main() is True
def test_main_exception(self, monkeypatch): monkeypatch.setattr('sys.argv', ['focli', 'nonexistent']) def mock_exception(a): raise FoliStopNameException("message") monkeypatch.setattr('focli.focli.show_stops', mock_exception) assert focli.main() == 1
def test_show_stops(self, monkeypatch): def mock_init(*args, **kwargs): return None def mock_func(*args): return True monkeypatch.setattr('focli.foline.FoliPrint.__init__', mock_init) monkeypatch.setattr('focli.foline.FoliPrint.print_lines', mock_func) monkeypatch.setattr('sys.argv', ['focli', '157']) assert focli.main() == 0 fcontent = '{"123":"abc"}' monkeypatch.setattr('sys.argv', ['focli']) with mock.patch.object(builtins, 'open', mock.mock_open(read_data=fcontent)): assert focli.main() == 0 with mock.patch.object(builtins, 'open', mock.mock_open(read_data="{}")): assert focli.main() == 1
def main(): return focli.main()