owmeta_pytest_plugin package

class owmeta_pytest_plugin.BundleData(id, version, source_directory, remote)

Bases: tuple

Create new instance of BundleData(id, version, source_directory, remote)

property id

Alias for field number 0

property remote

Alias for field number 3

property source_directory

Alias for field number 2

property version

Alias for field number 1

class owmeta_pytest_plugin.Data[source]

Bases: object

Object returned by shell_helper and owm_project (and related fixtures). Additional standard attributes may be added by the various fixtures.

Attributes
testdirstr

The temporary directory used for the CWD for sh

test_homedirstr

The temporary home directory for executions of sh

copy(source, dest)[source]

Copy files / directory tries into the test directory

Parameters
sourcestr

Source file or directory

deststr

Target directory. Will be interpreted relative to testdir

make_module(module)[source]

Create a module directory under testdir. Each of the intermediate directories (if there are any) will also be usable as modules (i.e., they’ll have __init__.py files in them).

Parameters
modulestr

Path to the module directory. Must be a relative path

Returns
str

The full path to the module directory

sh(*command, **kwargs)[source]

Execute commands with the working directory set to testdir, the HOME environment variable set to test_homedir, and with testdir prepended to PYTHONPATH.

Parameters
*commandlist of str

Command or commands to execute

**kwargsdict

Additional arguments to subprocess.check_output

Returns
str or list of str

Output of the given command. See subprocess.check_output for details on return values and how they are affected by arguments to that function.

writefile(name, contents=None)[source]

Write a file to the test directory

Parameters
namestr

Path name for the file to write

contentsstr

File name of a file to read from for the content or the literal string contents to write to the file

Returns
str

Full path to the written file

owmeta_pytest_plugin.bundle(request)

A fixture for bundles.

Example usage:

@bundles([('example/aBundle', 1),
          ('_orphans/aBundle', 2),
          ('phoenix/aBundle', 3),])
def test_bundle_with_renames(bundle):
    # do something with versions of aBundle
owmeta_pytest_plugin.bundle_fixture_helper(bundle_id, version=None)[source]

Creates test fixtures for testing with pre-made bundles. These may be for testing against older versions of bundles maintained within the project or for creating a “test fake” of a bundle dependency to test integration short of fetching the full dependency.

The source directory for the bundles follows exactly the same structure as the bundle cache directory in ~/.owmeta/bundles. The location for the directory comes from the TEST_BUNDLES_DIRECTORY environment variable and defaults to bundles in the current working directory if that variable is unset.

If version is omitted, then the version numbers will come from parameters, typically provided by pytest.mark.paremetrize. bundles and bundle_versions help with this.

For example:

my_bundle = pytest.fixture(bundle_fixture_helper('example/my_bundle'))

@bundle_versions('my_bundle', list(range(1, 5)))
def test_my_bundle(my_bundle):
    # do something with my_bundle
Parameters
bundle_idstr

The ID of the bundle

versionint, optional

The version of the bundle

Returns
function

A function to pass to pytest.fixture

owmeta_pytest_plugin.bundle_versions(fixture_name, versions)[source]

Parameterize a bundle fixture with versions of the bundle to test against

Parameters
fixture_namestr

The name of the fixture to parameterize

versionslist of int

Versions of the bundle to test against

owmeta_pytest_plugin.bundles(versions)[source]

Parameterize the bundle fixture with bundle IDs and versions to test against

Parameters
versionslist of int

Versions of the bundle to test against

owmeta_pytest_plugin.owm_project(request)[source]

Returns a shell_helper fixture but with a .owm project directory in the test directory. The helper also gets new methods:

owm(**kwargs): Creates and returns an OWM with its owmdir at the test .owm directory

fetch(bundle_data): Fetches a bundle into the test home directory. bundle_data likely comes from a test fixture created with bundle_fixture_helper

owmeta_pytest_plugin.owm_project_with_customizations(request)[source]

Factory for an owm_project context manager. Accepts a customizations argument, the same as shell_helper_with_customizations.

owmeta_pytest_plugin.shell_helper(request)[source]

Helper for running shell commands from a temporary working directory and home directory. Returns a Data instance.

owmeta_pytest_plugin.shell_helper_with_customizations(request)[source]

Like shell_helper, but returns a context manager instead which accepts a customizations argument, a string that will be written as the contents of sitecustomize.py to be picked up for any executions of sh