cafe.drivers.unittest package

cafe.drivers.unittest.datasets module

class cafe.drivers.unittest.datasets.DatasetFileLoader(file_object)[source]

Bases: cafe.drivers.unittest.datasets.DatasetList

Reads a file object’s contents in as json and converts them to lists of Dataset objects. Files should be opened in ‘rb’ (read binady) mode. File should be a list of dictionaries following this format: [{‘name’:”dataset_name”, ‘data’:{key:value, key:value, …}},] if name is ommited, it is replaced with that dataset’s location in the load order, so that not all datasets need to be named.

class cafe.drivers.unittest.datasets.DatasetGenerator(list_of_dicts, base_dataset_name=None)[source]

Bases: cafe.drivers.unittest.datasets.DatasetList

Generates Datasets from a list of dictionaries, which are named numericaly according to the source dictionary’s order in the source list. If a base_dataset_name is provided, that is used as the base name postfix for all tests before they are numbered.

class cafe.drivers.unittest.datasets.DatasetList[source]

Bases: list

Specialized list-like object that holds Dataset objects

append(dataset)[source]
append_new_dataset(name, data_dict, tags=None, decorators=None)[source]

Creates and appends a new Dataset

When including a decorators value (a list), make sure that the functions provided in the list are provided in the order in which they should be executed. When comparing them to typical stacked decorators, order them from bottom to top.

apply_test_decorators(*decorators)[source]

Applies decorators to all tests in dataset list

apply_test_tags(*tags)[source]

Applies tags to all tests in dataset list

dataset_name_map()[source]

Creates a dictionary with key=count and value=dataset name

dataset_names()[source]

Gets a list of dataset names from dataset list

extend(dataset_list)[source]
extend_new_datasets(dataset_list)[source]

Creates and extends a new DatasetList

merge_dataset_tags(*dataset_lists)[source]
static replace_invalid_characters(string, new_char='_')[source]

This functions corrects string so the following is true Identifiers (also referred to as names) are described by the following lexical definitions: identifier ::= (letter|”_”) (letter | digit | “_”)* letter ::= lowercase | uppercase lowercase ::= “a”…”z” uppercase ::= “A”…”Z” digit ::= “0”…”9”

class cafe.drivers.unittest.datasets.DatasetListCombiner(*datasets)[source]

Bases: cafe.drivers.unittest.datasets.DatasetList

Class that can be used to combine multiple DatasetList objects together. Produces the product of combining every dataset from each list together with the names merged together. The data is overridden in a cascading fashion, similar to CSS, where the last dataset takes priority.

class cafe.drivers.unittest.datasets.TestMultiplier(num_range)[source]

Bases: cafe.drivers.unittest.datasets.DatasetList

Creates num_range number of copies of the source test, and names the new tests numerically. Does not generate Datasets.

cafe.drivers.unittest.decorators module

cafe.drivers.unittest.decorators.DataDrivenClass(*dataset_lists)[source]

Use data driven class decorator. designed to be used on a fixture.

cafe.drivers.unittest.decorators.DataDrivenFixture(cls)[source]

Generates new unittest test methods from methods defined in the decorated class

exception cafe.drivers.unittest.decorators.DataDrivenFixtureError[source]

Bases: exceptions.Exception

Error if you apply DataDrivenClass to class that isn’t a TestCase

exception cafe.drivers.unittest.decorators.EmptyDSLError(dsl_namespace, original_test_list)[source]

Bases: exceptions.Exception

Custom exception to allow errors in Datadriven classes with no data.

cafe.drivers.unittest.decorators.data_driven_test(*dataset_sources, **kwargs)[source]

Used to define the data source for a data driven test in a DataDrivenFixture decorated Unittest TestCase class

class cafe.drivers.unittest.decorators.memoized(func)[source]

Bases: object

Decorator. @see: https://wiki.python.org/moin/PythonDecoratorLibrary#Memoize Caches a function’s return value each time it is called. If called later with the same arguments, the cached value is returned (not reevaluated).

Adds and removes handlers to root log for the duration of the function call, or logs return of cached result.

cafe.drivers.unittest.decorators.skip_open_issue(type, bug_id)[source]
cafe.drivers.unittest.decorators.tags(*tags, **attrs)[source]

Adds tags and attributes to tests, which are interpreted by the cafe-runner at run time

cafe.drivers.unittest.fixtures module

@summary: Base Classes for Test Fixtures @note: Corresponds DIRECTLY TO A unittest.TestCase @see: http://docs.python.org/library/unittest.html#unittest.TestCase

class cafe.drivers.unittest.fixtures.BaseBurnInTestFixture(methodName='runTest')[source]

Bases: cafe.drivers.unittest.fixtures.BaseTestFixture

@summary: Base test fixture that allows for Burn-In tests

classmethod addTest(test_case)[source]

@summary: Adds a test case

classmethod setUpClass()[source]

@summary: inits burning testing variables

class cafe.drivers.unittest.fixtures.BaseTestFixture(methodName='runTest')[source]

Bases: unittest.case.TestCase

@summary: This should be used as the base class for any unittest tests,
meant to be used instead of unittest.TestCase.

@see: http://docs.python.org/library/unittest.html#unittest.TestCase

classmethod addClassCleanup(function, *args, **kwargs)[source]

@summary: Named to match unittest’s addCleanup. ClassCleanup tasks run if setUpClass fails, or after tearDownClass. (They don’t depend on tearDownClass running)

classmethod assertClassSetupFailure(message)[source]
@summary: Use this if you need to fail from a Test Fixture’s
setUpClass() method
classmethod assertClassTeardownFailure(message)[source]
@summary: Use this if you need to fail from a Test Fixture’s
tearUpClass() method
logDescription()[source]

@summary: Returns a formatted description from the _testMethodDoc

setUp()[source]

@summary: Logs test metrics

classmethod setUpClass()[source]

@summary: Adds logging/reporting to Unittest setUpClass

shortDescription()[source]

@summary: Returns a formatted description of the test

tearDown()[source]
@todo: This MUST be upgraded this from resultForDoCleanups into a
better pattern or working with the result object directly. This is related to the todo in L{TestRunMetrics}
classmethod tearDownClass()[source]

@summary: Adds stop reporting to Unittest setUpClass

cafe.drivers.unittest.parsers module

class cafe.drivers.unittest.parsers.Result(test_class_name, test_method_name, failure_trace=None, skipped_msg=None, error_trace=None, test_time=0)[source]

Bases: object

Result object used to create the json and xml results

class cafe.drivers.unittest.parsers.SummarizeResults(result_dict, tests, execution_time, datagen_time=None)[source]

Bases: object

Reads in vars dict from suite and builds a Summarized results obj

gather_results()[source]

Gets a result obj for all tests ran and failed setup classes

get_passed_tests()[source]

Gets a list of results objects for passed tests

summary_result()[source]

Returns a dictionary containing counts of tests and statuses

cafe.drivers.unittest.runner module

class cafe.drivers.unittest.runner.OpenCafeParallelTextTestRunner(stream=<open file '<stderr>', mode 'w'>, descriptions=1, verbosity=1)[source]

Bases: unittest.runner.TextTestRunner

run(test)[source]

Run the given test case or test suite.

class cafe.drivers.unittest.runner.SuiteBuilder(cl_args, test_repo_name)[source]

Bases: object

build_suite(module_path)[source]

loads the found tests and builds the test suite

generate_suite()[source]

creates a single unittest test suite

generate_suite_list()[source]

creates a list containing unittest test suites

get_classes(loaded_module)[source]

finds all the classes in a loaded module calculates full path to class

get_modules()[source]

walks all modules in the test repo, filters by product and module filter. Filter passed in with -m returns a list of module dotpath strings

class cafe.drivers.unittest.runner.UnittestRunner[source]

Bases: object

static dump_results(start, finish, results)[source]
static execute_test(runner, test_id, test, results)[source]
static get_runner(cl_args)[source]
log_errors(label, result, errors)[source]
static print_mug_and_paths(test_env)[source]
run()[source]

loops through all the packages, modules, and methods sent in from the command line and runs them

run_parallel(test_suites, test_runner, result_type=None, results_path=None)[source]
run_serialized(master_suite, test_runner, result_type=None, results_path=None)[source]
cafe.drivers.unittest.runner.entry_point()[source]
cafe.drivers.unittest.runner.tree(directory, padding, print_files=False)[source]

creates an ascii tree for listing files or configs

cafe.drivers.unittest.suite module

Contains a monkeypatched version of unittest’s TestSuite class that supports a version of addCleanup that can be used in classmethods. This allows a more granular approach to teardown to be used in setUpClass and classmethod helper methods

class cafe.drivers.unittest.suite.OpenCafeUnittestTestSuite(tests=())[source]

Bases: unittest.suite.TestSuite