def test_creator_nocontext(fpath, lipsum_item): """ensure we can use the creator linearily""" creator = Creator(fpath) exc_type, exc_val, exc_tb = None, None, None creator.__enter__() creator.add_metadata("Name", "name") creator.add_item(lipsum_item) with pytest.raises(RuntimeError): creator.config_verbose(True) creator.__exit__(exc_type, exc_val, exc_tb) # now with an exception creator = Creator(fpath) creator.__enter__() creator.add_item(lipsum_item) try: creator.add_redirection("A", HOME_PATH) except Exception: exc_type, exc_val, exc_tb = sys.exc_info() with pytest.raises(TypeError): raise creator.__exit__(exc_type, exc_val, exc_tb)
def test_creator_redirection(fpath, lipsum_item): # ensure we can't add if not started c = Creator(fpath) with pytest.raises(RuntimeError, match="not started"): c.add_redirection("home", "hello", HOME_PATH) del c with Creator(fpath) as c: c.add_item(lipsum_item) c.add_redirection("home", "hello", HOME_PATH) c.add_redirection("accueil", "bonjour", HOME_PATH) zim = Archive(fpath) assert zim.entry_count == 3 assert zim.has_entry_by_path("home") is True assert zim.has_entry_by_path("accueil") is True assert zim.get_entry_by_path("home").is_redirect assert (zim.get_entry_by_path("home").get_redirect_entry().path == zim.get_entry_by_path(HOME_PATH).path) assert zim.get_entry_by_path("accueil").get_item().path == HOME_PATH assert "home" in list(zim.suggest("hello")) assert "accueil" in list(zim.suggest("bonjour"))