Skip to content

Commit

Permalink
Restructure tests to eliminate need for code to add new ones
Browse files Browse the repository at this point in the history
  • Loading branch information
vr8hub committed Feb 29, 2024
1 parent 5fdcc0e commit 60fbfc4
Show file tree
Hide file tree
Showing 154 changed files with 1,398 additions and 821 deletions.
87 changes: 45 additions & 42 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,60 +11,63 @@

pytest.register_assert_rewrite("helpers")

from helpers import must_run # pylint: disable=wrong-import-position


def pytest_addoption(parser):
"""Additional pytest command-line options."""
"""
Additional pytest command-line options.
"""
parser.addoption("--lint-subset", action="store", dest="lint_subset", choices=("css","filesystem","metadata","semantics","typography","typos","xhtml"), help="Specify a subset of lint tests to be performed")
parser.addoption("--save-golden-files", action="store_true", default=False, help="Save updated versions of all golden output files")
parser.addoption("--save-new-draft", action="store_true", default=False, help="Update draft ebook used as base for other tests")
parser.addoption("--save-new-draft", action="store_true", default=False, help="Update draft ebook used as base for ebookcmd tests")

@pytest.fixture(name="book_name", scope="session")
def fixture_book_name():
"""Return name of draft book generated by '--save-new-draft' option."""
return "jane-austen_unknown-novel"
@pytest.fixture(name="draftbook__name", scope="session")
def fixture_draftbook__name():
"""
Return name of draft book.
"""
return "jane-austen_draft-novel"

@pytest.fixture(name="testbook__name", scope="session")
def fixture_testbook__name():
"""
Return name of test book.
"""
return "jane-austen_test-novel"

@pytest.fixture(scope="session")
def draft_dir(tmp_path_factory, data_dir: Path, book_name: str, update_draft: bool) -> Generator:
"""Return the Path object for a temporary copy of the draft book content."""
base_dir = data_dir / "draft"
src_dir = base_dir / book_name
if update_draft:
shutil.rmtree(src_dir)
old_wd = os.getcwd()
os.chdir(base_dir)
try:
must_run("se create-draft -a 'Jane Austen' -t 'Unknown Novel'")
must_run(f"se build-images {src_dir}")
finally:
os.chdir(old_wd)
dest_dir = tmp_path_factory.getbasetemp() / "draft-book"
shutil.copytree(src_dir, dest_dir)
shutil.copy(dest_dir / "images" / "cover.jpg", dest_dir / "images" / "cover.source.jpg")
yield dest_dir
def draftbook__directory(tmp_path_factory, draftbook__name: str) -> Generator:
"""
Return the Path object for a temporary copy of the draft book content.
"""
base_directory = Path(__file__).parent / "data" / "draftbook"
src_directory = base_directory / draftbook__name
dest_directory = tmp_path_factory.getbasetemp() / "draftbook"
shutil.copytree(src_directory, dest_directory)
yield dest_directory

@pytest.fixture(name="data_dir", scope="session")
def fixture_data_dir() -> Path:
"""Return the Path object for the test data directory."""
return Path(__file__).parent / "data"
@pytest.fixture(scope="session")
def testbook__directory(tmp_path_factory, testbook__name: str) -> Generator:
"""
Return the Path object for a temporary copy of the test book content.
"""
base_directory = Path(__file__).parent / "data" / "testbook"
src_directory = base_directory / testbook__name
dest_directory = tmp_path_factory.getbasetemp() / "testbook"
shutil.copytree(src_directory, dest_directory)
yield dest_directory

@pytest.fixture
def work_dir(tmp_path: Path) -> Generator:
"""Return the Path object for a temporary working directory. The current
working directory is updated to this temporary directory until the test
returns.
def work__directory(tmp_path: Path) -> Generator:
"""Return the Path object for a temporary working directory. The current working
directory is updated to this temporary directory until the test returns.
"""
old_wd = os.getcwd()
old_working_directory = os.getcwd()
os.chdir(tmp_path)
yield tmp_path
os.chdir(old_wd)
os.chdir(old_working_directory)

@pytest.fixture(scope="session")
def update_golden(pytestconfig) -> bool:
"""Save updated versions of all golden output files when this flag is True."""
"""
Save updated versions of all golden output files when this flag is True.
"""
return pytestconfig.getoption("--save-golden-files")

@pytest.fixture(name="update_draft", scope="session")
def fixture_update_draft(pytestconfig) -> bool:
"""Save updated draft ebook when this flag is True."""
return pytestconfig.getoption("--save-new-draft")
92 changes: 0 additions & 92 deletions tests/data/build-manifest/in/content.opf

This file was deleted.

14 changes: 0 additions & 14 deletions tests/data/build-spine/in/chapter-1.xhtml

This file was deleted.

92 changes: 0 additions & 92 deletions tests/data/build-spine/in/content.opf

This file was deleted.

Loading

0 comments on commit 60fbfc4

Please sign in to comment.