def test_build_clean(draft_dir: Path, work_dir: Path, data_dir: Path, book_name: str): """Run the build command on a known-clean book and verify that the correct number and type of output files are generated. """ text_dir = data_dir / "build" / "text" book_dir = assemble_book(draft_dir, work_dir, text_dir) must_run(f"se build --kindle --kobo --check {book_dir}") for suffix in [".epub", "_advanced.epub", ".azw3", ".kepub.epub"]: file = work_dir / (book_name + suffix) assert file.is_file()
def test_text_cmds(data_dir: Path, draft_dir: Path, work_dir: Path, cmd_name: str, cmd_args: str, update_golden: bool): """Run each command on the input content and validate that the tranformed text matches the expected output content.""" in_dir = data_dir / cmd_name / "in" book_dir = assemble_book(draft_dir, work_dir, in_dir) must_run(f"se {cmd_name} {cmd_args} {book_dir}") text_dir = book_dir / "src" / "epub" / "text" golden_dir = data_dir / cmd_name / "out" assert files_are_golden(in_dir, text_dir, golden_dir, update_golden)
def test_print_toc(data_dir: Path, draft_dir: Path, work_dir: Path, update_golden: bool, capfd): """Verify the expected TOC is generated from test book""" text_dir = data_dir / "print-toc" / "in" book_dir = assemble_book(draft_dir, work_dir, text_dir) must_run(f"se print-toc {book_dir}") out, err = capfd.readouterr() assert err == "" golden_file = data_dir / "print-toc" / "toc-out.txt" assert output_is_golden(out, golden_file, update_golden)
def test_lint(data_dir: Path, draft_dir: Path, work_dir: Path, capfd, test_name: str, update_golden: bool): """Run lint command on several books with different expected lint output: clean - No errors expected content - Errors for a default content.opf """ text_dir = data_dir / "lint" / test_name book_dir = assemble_book(draft_dir, work_dir, text_dir) result = run(f"se lint --plain {book_dir}") # All books with errors should return a non-zero return code if test_name != "clean": assert result.returncode != 0 # Output of stderr should always be empty out, err = capfd.readouterr() assert err == "" # Update golden output files if flag is set golden_file = data_dir / "lint" / f"{test_name}-out.txt" assert output_is_golden(out, golden_file, update_golden)