dulwich.tests.compat.utils module

Utilities for interacting with cgit.

class dulwich.tests.compat.utils.CompatTestCase(methodName='runTest')

Bases: TestCase

Test case that requires git for compatibility checks.

Subclasses can change the git version required by overriding min_git_version.

Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.

assertObjectStoreEqual(store1, store2)
assertReposEqual(repo1, repo2)
assertReposNotEqual(repo1, repo2)
import_repo(name)

Import a repo from a fast-export file in a temporary directory.

Parameters

name – The name of the repository export file, relative to dulwich/tests/data/repos.

Returns: An initialized Repo object that lives in a temporary

directory.

min_git_version: Tuple[int, ...] = (1, 5, 0)
setUp()

Hook method for setting up the test fixture before exercising it.

dulwich.tests.compat.utils.check_for_daemon(limit=10, delay=0.1, timeout=0.1, port=9418)

Check for a running TCP daemon.

Defaults to checking 10 times with a delay of 0.1 sec between tries.

Parameters
  • limit – Number of attempts before deciding no daemon is running.

  • delay – Delay between connection attempts.

  • timeout – Socket timeout for connection attempts.

  • port – Port on which we expect the daemon to appear.

Returns: A boolean, true if a daemon is running on the specified port,

false if not.

dulwich.tests.compat.utils.git_version(git_path='git')

Attempt to determine the version of git currently installed.

Parameters

git_path – Path to the git executable; defaults to the version in the system path.

Returns: A tuple of ints of the form (major, minor, point, sub-point), or

None if no git installation was found.

dulwich.tests.compat.utils.import_repo_to_dir(name)

Import a repo from a fast-export file in a temporary directory.

These are used rather than binary repos for compat tests because they are more compact and human-editable, and we already depend on git.

Parameters

name – The name of the repository export file, relative to dulwich/tests/data/repos.

Returns: The path to the imported repository.

dulwich.tests.compat.utils.require_git_version(required_version, git_path='git')

Require git version >= version, or skip the calling test.

Parameters
  • required_version – A tuple of ints of the form (major, minor, point, sub-point); omitted components default to 0.

  • git_path – Path to the git executable; defaults to the version in the system path.

Raises
  • ValueError – if the required version tuple has too many parts.

  • SkipTest – if no suitable git version was found at the given path.

dulwich.tests.compat.utils.run_git(args, git_path='git', input=None, capture_stdout=False, capture_stderr=False, **popen_kwargs)

Run a git command.

Input is piped from the input parameter and output is sent to the standard streams, unless capture_stdout is set.

Parameters
  • args – A list of args to the git command.

  • git_path – Path to to the git executable.

  • input – Input data to be sent to stdin.

  • capture_stdout – Whether to capture and return stdout.

  • popen_kwargs – Additional kwargs for subprocess.Popen; stdin/stdout args are ignored.

Returns: A tuple of (returncode, stdout contents, stderr contents).

If capture_stdout is False, None will be returned as stdout contents. If capture_stderr is False, None will be returned as stderr contents.

Raises

OSError – if the git executable was not found.

dulwich.tests.compat.utils.run_git_or_fail(args, git_path='git', input=None, **popen_kwargs)

Run a git command, capture stdout/stderr, and fail if git fails.