Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation of examples of running tests #75

Open
Tracked by #72
griff-rees opened this issue Feb 23, 2023 · 1 comment
Open
Tracked by #72

Documentation of examples of running tests #75

griff-rees opened this issue Feb 23, 2023 · 1 comment

Comments

@griff-rees
Copy link
Collaborator

griff-rees commented Feb 23, 2023

Write out an example of running tests locally via pytest and encourage that for future contributors.

@griff-rees griff-rees changed the title Examples of running tests Documentation of examples of running tests Feb 23, 2023
@kallewesterling
Copy link

To ease our minds a bit, perhaps we could add something about encouragement of implementing pytest in the codebase in a paragraph in the contributor guide, and then link out to some good tutorials or so on best practices around building unit tests with pytest? It seems beyond the scope of the contribution guide for alto2txt to include anything extremely long, but perhaps an example of how we've implemented pytest thus far could be included?

For example, an explanation of this (and how it's using both pytest and icecream?):

def test_output_dir_args(tmp_path):
    # Use the `tmp_path` fixture to ensure that the so-called "non-existant" dirs aren't
    # later inadvertently created within the repo.

    # Test that a non-existant `txt_out_dir` is created, including if it is a very deeply nested dir.
    # output_dir = tmp_path / "non-existant-output-dir"
    output_dirs_list = [
        tmp_path / "non-existant-output-dir",
        tmp_path
        / "a"
        / "b"
        / "c"
        / "d"
        / "very"
        / "deeply"
        / "nested"
        / "nonexistent"
        / "dir",
    ]

    for output_dir in output_dirs_list:
        assert not output_dir.exists()
        sys.argv[1:] = ["demo-files", str(output_dir)]
        extract_publications_text.main()
        assert output_dir.exists()

    # Check that passing a existing file (rather than a dir) is caught
    file_not_dir = tmp_path / "output-file.txt"
    file_not_dir.touch()

    with pytest.raises(AssertionError) as ae:
        sys.argv[1:] = ["demo-files", str(file_not_dir)]
        extract_publications_text.main()

    assert ae.match("output-file.txt")
    assert ae.match("txt_out_dir.+not a directory")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants