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

Avoid brittle assumptions about preexisting temporary files in tests #1759

Merged
merged 3 commits into from
Dec 8, 2023

Commits on Dec 8, 2023

  1. Avoid unsafe assumptions about tempdir content in tests

    test_new_should_raise_on_invalid_repo_location had previously used
    tempfile.gettempdir() directly to get a path assumed not to be a
    valid repository, assuming more than necessary about the directory
    in which temporary files and directories are created. A newly
    created temporary directory is now used for that check, instead.
    
    test_new_should_raise_on_non_existent_path had assumed no
    repos/foobar existed relative to the current directory. Typically
    there would be no such directory, but is unnecessary for the test
    to rely on this. A newly created temporary directory known to be
    empty is now used in place of the "repos" component, for that test.
    EliahKagan committed Dec 8, 2023
    Configuration menu
    Copy the full SHA
    ad570de View commit details
    Browse the repository at this point in the history
  2. Avoid another tempdir content assumption in test

    test_init was using tempfile.gettempdir() directly to get the
    location where the hard-coded path repos/foo/bar.git would be used
    to test repository creation with relative and absolute paths. That
    reused the same location each time, and also assumed the directory
    would be usable, which could fail due to previous runs or due to
    the path being used separately from GitPython's tests. This commit
    fixes that by using that path inside a temporary directory, known
    at the start of the test to be empty.
    
    Reorganizing the acquision and cleanup logic also has had the
    effect of causing the test no longer to be skipped due to the logic
    in git.util.rmtree due to the final cleanup attempt (after all
    assertions). The directory is now successfully removed on Windows,
    and the test passes on all platforms.
    EliahKagan committed Dec 8, 2023
    Configuration menu
    Copy the full SHA
    9277ff5 View commit details
    Browse the repository at this point in the history
  3. Test InvalidGitRepositoryError in repo subdir

    A Repo object can of course be constructed from a path to a
    directory that is the root of an existing repository, and raises
    InvalidGitRepositoryError on a directory that is outside of any
    repository. Tests intended to show both conditions already exist.
    
    This adds a test to verify that InvalidGitRepositoryError is also
    raised when an attempt is made to construct a Repo object from a
    path to a directory that is not the root of a repository but that
    is known to be located inside an existing git repository.
    EliahKagan committed Dec 8, 2023
    Configuration menu
    Copy the full SHA
    c09ac1a View commit details
    Browse the repository at this point in the history