Skip to content

Fetching

Repository

Bases: ABC

Base class for facilitating fetching of resources for tracing

__init__(project_uri)

Construct an instance with an URI to the requested resource, should be called from deriving classes

Parameters:

Name Type Description Default
project_uri str

URI to the resource

required

fetch(output)

Download the project from the URL specified in the constructor and store it in the path specified by output

factory(project_uri, fmt=None) staticmethod

Factory method for instantiating subtypes of this class with the purpose of fetching the requested resource

Parameters:

Name Type Description Default
project_uri str

URI to the resource

required
fmt str | None

Indicator / Tag for forcing factory to select certain subtype

None

Returns:

Type Description
Repository

An appropriate subtype instance

Raises:

Type Description
LookupError

When no fitting subtype can be chosen

fmt() property abstractmethod

Attribute indicating format of repository. Implement using fmt = "THIS_REPOS_FORMAT" in the derived class.

GitRepository

Bases: Repository

Fetch Git Repositories from .git URIs

ArchiveRepository

Bases: Repository

Fetch archives from specified URI

LocalFolder

Bases: Repository

Use local folders as a basis for a resource. Useful if you want to trace smaller projects or private ones, etc.

TestDetector

Bases: ABC

When given the path to a repo, attempts to detect a specific testing suite and create the appropriate application strategy if there is a match.

factory(proj) staticmethod

Attempt to detect compatible test suites

Parameters:

Name Type Description Default
proj Project

Folder of fetched repository

required

matches() abstractmethod

Detect specific testing suite.

create_strategy(recurse_into_subdirs) abstractmethod

Create application strategy.

PyTestDetector

Bases: TestDetector

Search for signs that a project uses PyTest

ApplicationStrategy

Bases: ABC

Implement for a specific test framework; When given a file that uses the specified framework, parse this file and insert code that will cause the test functions to be traced upon execution.

apply(project)

Apply the subclass-specific strategy to the test files found in the project

Parameters:

Name Type Description Default
project Project

Path to the fetched resource, now a project

required

AppendDecoratorTransformer

Bases: cst.CSTTransformer

Transforms an AST such that the trace decorator is appended on each test function. Additionally, imports are generated in the correct locations so that using the decorator is possible

Project

Represents a downloaded Python repository. Use for more intuitive navigation of the project

test_directories() property cached

Search for directories in the repository that could contain tests

Returns:

Type Description
list[pathlib.Path] | None

List of existing candidate folders, None if none are found