def test_current_unset(self, tmpdir): sess_man = sessions.SessionManager(str(tmpdir)) with pytest.raises(cmdexc.CommandError) as excinfo: sess_man.session_save(0, current=True) assert str(excinfo.value) == "No session loaded currently!"
def test_session_not_found(self, tmpdir): sess_man = sessions.SessionManager(str(tmpdir)) with pytest.raises(cmdexc.CommandError) as excinfo: sess_man.session_delete('foo') assert str(excinfo.value) == "Session foo not found!"
def test_internal_without_force(self, tmpdir): sess_man = sessions.SessionManager(str(tmpdir)) with pytest.raises(cmdexc.CommandError) as excinfo: sess_man.session_save(0, '_foo') expected_text = ("_foo is an internal session, use --force to " "save anyways.") assert str(excinfo.value) == expected_text assert not (tmpdir / '_foo.yml').exists()
def test_inexistent(self, tmpdir, absolute): man = sessions.SessionManager(str(tmpdir)) if absolute: name = str(tmpdir / 'foo') else: name = 'foo' assert not man.exists(name)
def test_deletion_error(self, caplog, tmpdir): sess_man = sessions.SessionManager(str(tmpdir)) (tmpdir / 'foo.yml').ensure() tmpdir.chmod(0o555) # unwritable with pytest.raises(cmdexc.CommandError) as excinfo: with caplog.at_level(logging.ERROR): sess_man.session_delete('foo') assert str(excinfo.value).startswith('Error while deleting session: ') assert len(caplog.records) == 1 assert caplog.records[0].message == 'Error while deleting session!'
def test_internal_without_force(self, tmpdir): sess_man = sessions.SessionManager(str(tmpdir)) sess_file = tmpdir / '_foo.yml' sess_file.ensure() with pytest.raises(cmdexc.CommandError) as excinfo: sess_man.session_delete('_foo') expected_text = ("_foo is an internal session, use --force to " "delete anyways.") assert str(excinfo.value) == expected_text assert sess_file.exists()
def test_existent(self, tmp_path, absolute): session_dir = tmp_path / 'sessions' abs_session = tmp_path / 'foo.yml' rel_session = session_dir / 'foo.yml' session_dir.mkdir() abs_session.touch() rel_session.touch() man = sessions.SessionManager(str(session_dir)) if absolute: name = str(abs_session) else: name = 'foo' assert man.exists(name)
def test_existent(self, tmpdir, absolute): session_dir = tmpdir / 'sessions' abs_session = tmpdir / 'foo.yml' rel_session = session_dir / 'foo.yml' session_dir.ensure(dir=True) abs_session.ensure() rel_session.ensure() man = sessions.SessionManager(str(session_dir)) if absolute: name = str(abs_session) else: name = 'foo' assert man.exists(name)
def test_no_sessions(self, tmpdir): sess_man = sessions.SessionManager(str(tmpdir)) assert not sess_man.list_sessions()
def test_with_other_files(self, tmp_path): (tmp_path / 'foo.yml').touch() (tmp_path / 'bar.html').touch() sess_man = sessions.SessionManager(str(tmp_path)) assert sess_man.list_sessions() == ['foo']
def sess_man(): """Fixture providing a SessionManager with no session dir.""" return sessions.SessionManager(base_path=None)
def test_current_set(self, tmpdir, fake_windows): sess_man = sessions.SessionManager(str(tmpdir)) sess_man._current = 'foo' sess_man.session_save(0, current=True, quiet=True) assert (tmpdir / 'foo.yml').exists()
def test_internal_with_force(self, tmpdir, fake_windows): sess_man = sessions.SessionManager(str(tmpdir)) sess_man.session_save(0, '_foo', force=True, quiet=True) assert (tmpdir / '_foo.yml').exists()
def test_with_sessions(self, tmpdir): (tmpdir / 'foo.yml').ensure() (tmpdir / 'bar.yml').ensure() sess_man = sessions.SessionManager(str(tmpdir)) assert sorted(sess_man.list_sessions()) == ['bar', 'foo']
def test_with_other_files(self, tmpdir): (tmpdir / 'foo.yml').ensure() (tmpdir / 'bar.html').ensure() sess_man = sessions.SessionManager(str(tmpdir)) assert sess_man.list_sessions() == ['foo']
def sess_man(tmpdir): """Fixture providing a SessionManager.""" return sessions.SessionManager(base_path=str(tmpdir))
def test_internal_with_force(self, tmpdir): sess_man = sessions.SessionManager(str(tmpdir)) sess_file = tmpdir / '_foo.yml' sess_file.ensure() sess_man.session_delete('_foo', force=True) assert not tmpdir.listdir()
def test_normal_delete(self, tmpdir): sess_man = sessions.SessionManager(str(tmpdir)) sess_file = tmpdir / 'foo.yml' sess_file.ensure() sess_man.session_delete('foo') assert not tmpdir.listdir()
def __init__(self, webview): self.sess_man = sessions.SessionManager(base_path=None) self.webview = webview