Skip to content

Commit

Permalink
Rename warc2zim to main.
Browse files Browse the repository at this point in the history
  • Loading branch information
mgautierfr committed Dec 8, 2023
1 parent 57da2b2 commit 1556717
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/warc2zim/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
logger = logging.getLogger("warc2zim")


def warc2zim(args=None):
def main(args=None):
parser = ArgumentParser(description="Create ZIM files from WARC files")

parser.add_argument("-V", "--version", action="version", version=get_version())
Expand Down Expand Up @@ -114,4 +114,4 @@ def warc2zim(args=None):


if __name__ == "__main__": # pragma: no cover
sys.exit(warc2zim())
sys.exit(main())
34 changes: 16 additions & 18 deletions tests/test_warc_to_zim.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
from warc2zim.url_rewriting import canonicalize
from warc2zim.converter import iter_warc_records
from warc2zim.utils import get_record_url

# Import last to not mask the warc2zim module
from warc2zim.main import warc2zim
from warc2zim.main import main

TEST_DATA_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "data")

Expand Down Expand Up @@ -189,7 +187,7 @@ def test_canonicalize(self):

def test_warc_to_zim_specify_params_and_metadata(self, tmp_path):
zim_output = "zim-out-filename.zim"
warc2zim(
main(
[
"-v",
os.path.join(TEST_DATA_DIR, "example-response.warc"),
Expand Down Expand Up @@ -270,7 +268,7 @@ def test_warc_to_zim(self, cmdline, tmp_path):

cmdline.extend(["--output", str(tmp_path), "--name", filename])

warc2zim(cmdline)
main(cmdline)

zimfile = filename + "_" + time.strftime("%Y-%m") + ".zim"

Expand All @@ -287,7 +285,7 @@ def test_warc_to_zim(self, cmdline, tmp_path):

def test_same_domain_only(self, tmp_path):
zim_output = "same-domain.zim"
warc2zim(
main(
[
os.path.join(TEST_DATA_DIR, "example-revisit.warc.gz"),
"--favicon",
Expand Down Expand Up @@ -315,7 +313,7 @@ def test_same_domain_only(self, tmp_path):

def test_skip_self_redirect(self, tmp_path):
zim_output = "self-redir.zim"
warc2zim(
main(
[
os.path.join(TEST_DATA_DIR, "self-redirect.warc"),
"--output",
Expand All @@ -340,7 +338,7 @@ def test_skip_self_redirect(self, tmp_path):

def test_include_domains_favicon_and_language(self, tmp_path):
zim_output = "spt.zim"
warc2zim(
main(
[
os.path.join(TEST_DATA_DIR, "single-page-test.warc"),
"-i",
Expand Down Expand Up @@ -380,7 +378,7 @@ def test_include_domains_favicon_and_language(self, tmp_path):

def test_all_warcs_root_dir(self, tmp_path):
zim_output = "test-all.zim"
warc2zim(
main(
[
os.path.join(TEST_DATA_DIR),
"--output",
Expand Down Expand Up @@ -418,7 +416,7 @@ def test_all_warcs_root_dir(self, tmp_path):

def test_fuzzy_urls(self, tmp_path, fuzzycheck):
zim_output = fuzzycheck["filename"] + ".zim"
warc2zim(
main(
[
os.path.join(TEST_DATA_DIR, fuzzycheck["filename"]),
"--output",
Expand All @@ -445,7 +443,7 @@ def test_local_replay_viewer_url(self, tmp_path):
with open(tmp_path / "sw.js", "wt") as fh:
fh.write(res.text)

warc2zim(
main(
[
"-v",
os.path.join(TEST_DATA_DIR, "example-response.warc"),
Expand All @@ -465,7 +463,7 @@ def test_local_replay_viewer_url(self, tmp_path):
def test_error_bad_replay_viewer_url(self, tmp_path):
zim_output_not_created = "zim-out-not-created.zim"
with pytest.raises(Exception) as e:
warc2zim(
main(
[
"-v",
os.path.join(TEST_DATA_DIR, "example-response.warc"),
Expand All @@ -486,7 +484,7 @@ def test_error_bad_replay_viewer_url(self, tmp_path):
def test_error_bad_main_page(self, tmp_path):
zim_output_not_created = "zim-out-not-created.zim"
with pytest.raises(Exception) as e:
warc2zim(
main(
[
"-v",
os.path.join(TEST_DATA_DIR, "example-response.warc"),
Expand All @@ -504,15 +502,15 @@ def test_error_bad_main_page(self, tmp_path):
def test_args_only(self):
# error, name required
with pytest.raises(SystemExit) as e:
warc2zim([])
main([])
assert e.code == 2

# error, no such output directory
with pytest.raises(Exception) as e:
warc2zim(["--name", "test", "--output", "/no-such-dir"])
main(["--name", "test", "--output", "/no-such-dir"])

# success, special error code for no output files
assert warc2zim(["--name", "test", "--output", "./"]) == 100
assert main(["--name", "test", "--output", "./"]) == 100

def test_custom_css(self, tmp_path):
custom_css = b"* { background-color: red; }"
Expand All @@ -522,7 +520,7 @@ def test_custom_css(self, tmp_path):

zim_output = "test-css.zim"

warc2zim(
main(
[
os.path.join(TEST_DATA_DIR, "example-response.warc"),
"--output",
Expand All @@ -549,7 +547,7 @@ def test_custom_css_remote(self, tmp_path):
"https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap-reboot.css"
)

warc2zim(
main(
[
os.path.join(TEST_DATA_DIR, "example-response.warc"),
"--output",
Expand Down

0 comments on commit 1556717

Please sign in to comment.