module documentation

Utility functions common to Dulwich tests.

Function build_commit_graph Build a commit graph from a concise specification.
Function build_pack Write test pack data from a concise spec.
Function ext_functest_builder Generate a test method that tests the given extension function.
Function functest_builder Generate a test method that tests the given function.
Function make_commit Make a Commit object with a default set of members.
Function make_object Make an object for testing and assign some members.
Function make_tag Make a Tag object with a default set of values.
Function open_repo Open a copy of a repo in a temporary directory.
Function setup_warning_catcher Wrap warnings.showwarning with code that records warnings.
Function tear_down_repo Tear down a test repository.
Constant F Undocumented
Type Variable T Undocumented
def build_commit_graph(object_store: BaseObjectStore, commit_spec: list[list[int]], trees: dict[int, list[tuple[bytes, ShaFile] | tuple[bytes, ShaFile, int]]] | None = None, attrs: dict[int, dict[str, Any]] | None = None) -> list[Commit]:

Build a commit graph from a concise specification.

Sample usage: >>> c1, c2, c3 = build_commit_graph(store, [[1], [2, 1], [3, 1, 2]]) >>> store[store[c3].parents[0]] == c1 True >>> store[store[c3].parents[1]] == c2 True

If not otherwise specified, commits will refer to the empty tree and have commit times increasing in the same order as the commit spec.

Returns: The list of commit objects created.

Parameters
object_store:BaseObjectStoreAn ObjectStore to commit objects to.
commit_spec:list[list[int]]An iterable of iterables of ints defining the commit graph. Each entry defines one commit, and entries must be in topological order. The first element of each entry is a commit number, and the remaining elements are its parents. The commit numbers are only meaningful for the call to make_commits; since real commit objects are created, they will get created with real, opaque SHAs.
trees:dict[int, list[tuple[bytes, ShaFile] | tuple[bytes, ShaFile, int]]] | NoneAn optional dict of commit number -> tree spec for building trees for commits. The tree spec is an iterable of (path, blob, mode) or (path, blob) entries; if mode is omitted, it defaults to the normal file mode (0100644).
attrs:dict[int, dict[str, Any]] | NoneA dict of commit number -> (dict of attribute -> value) for assigning additional values to the commits.
Returns
list[Commit]Undocumented
Raises
ValueErrorIf an undefined commit identifier is listed as a parent.
def build_pack(f: BinaryIO, objects_spec: list[tuple[int, Any]], store: BaseObjectStore | None = None) -> list[tuple[int, int, bytes, bytes, int]]:

Write test pack data from a concise spec.

Returns: A list of tuples in the order specified by objects_spec:
(offset, type num, data, sha, CRC32)
Parameters
f:BinaryIOA file-like object to write the pack to.
objects_spec:list[tuple[int, Any]]

A list of (type_num, obj). For non-delta types, obj is the string of that object's data. For delta types, obj is a tuple of (base, data), where:

  • base can be either an index in objects_spec of the base for that
  • delta; or for a ref delta, a SHA, in which case the resulting pack
  • will be thin and the base will be an external ref.
  • data is a string of the full, non-deltified data for that object.

Note that offsets/refs and deltas are computed within this function.

store:BaseObjectStore | NoneAn optional ObjectStore for looking up external refs.
Returns
list[tuple[int, int, bytes, bytes, int]]Undocumented
def ext_functest_builder(method: Callable[[Any, Any], None], func: Any) -> Callable[[Any], None]:

Generate a test method that tests the given extension function.

This is intended to generate test methods that test both a pure-Python version and an extension version using common test code. The extension test will raise SkipTest if the extension is not found.

Sample usage:

class MyTest(TestCase);
def _do_some_test(self, func_impl):
self.assertEqual('foo', func_impl())

test_foo = functest_builder(_do_some_test, foo_py) test_foo_extension = ext_functest_builder(_do_some_test, _foo_c)

Parameters
method:Callable[[Any, Any], None]The method to run. It must must two parameters, self and the function implementation to test.
func:AnyThe function implementation to pass to method.
Returns
Callable[[Any], None]Undocumented
def functest_builder(method: Callable[[Any, Any], None], func: Any) -> Callable[[Any], None]:

Generate a test method that tests the given function.

def make_commit(**attrs: Any) -> Commit:

Make a Commit object with a default set of members.

Returns: A newly initialized Commit object.

Parameters
**attrs:Anydict of attributes to overwrite from the default values.
Returns
CommitUndocumented
def make_object(cls: type[T], **attrs: Any) -> T:

Make an object for testing and assign some members.

This method creates a new subclass to allow arbitrary attribute reassignment, which is not otherwise possible with objects having __slots__.

Returns: A newly initialized object of type cls.

Parameters
cls:type[T]The class to create an instance of
**attrs:Anydict of attributes to set on the new object.
Returns
TUndocumented
def make_tag(target: ShaFile, **attrs: Any) -> Tag:

Make a Tag object with a default set of values.

Returns: A newly initialized Tag object.

Parameters
target:ShaFileobject to be tagged (Commit, Blob, Tree, etc)
**attrs:Anydict of attributes to overwrite from the default values.
Returns
TagUndocumented
def open_repo(name: str, temp_dir: str | None = None) -> Repo:

Open a copy of a repo in a temporary directory.

Use this function for accessing repos in dulwich/tests/data/repos to avoid accidentally or intentionally modifying those repos in place. Use tear_down_repo to delete any temp files created.

Returns: An initialized Repo object that lives in a temporary directory.

Parameters
name:strThe name of the repository, relative to dulwich/tests/data/repos
temp_dir:str | Nonetemporary directory to initialize to. If not provided, a temporary directory will be created.
Returns
RepoUndocumented
def setup_warning_catcher() -> tuple[list[Warning], Callable[[], None]]:

Wrap warnings.showwarning with code that records warnings.

def tear_down_repo(repo: Repo):

Tear down a test repository.

F: int =

Undocumented

Value
33188
T =

Undocumented

Value
TypeVar('T',
        bound=ShaFile)