cases – A Toolkit for Developing dtf Cases

class dtf.cases.DtfCase(name, test_spec)

Pass the following two parameters when instantiating DtfCase objects:

  • name (string) – The name of the test, typically derived from the file name of the test specification itself.
  • test_spec (object) – The test_spec object, imported from the term:test specification provided in YAML by the user.

DtfCase is a base class useful for implementing most dtf cases while requiring only limited familiarity with dtf internals.

dump(test_spec, path, keys=None)
  • test_spec (dict) – A dictionary to export to a yaml test specification.
  • path (string) – The path of the output file.
  • keys (list) – Optional. A list of keys to validate using validate().

Writes a test_spec in YAML format to a file specified by path. A thin wrapper around yaml.dump() method, with additional validation and formatting

When keys is not None, dump() will validate the keys in test_spec using validate(). Invalid test_specs always raise a DtfException.

keys = None

A list of top-level keys in the test_spec dictionary. Cases will pass a list of keys to the required_keys() method after creating the object, but before calling. validate().

msg(msg, verbose=None)
Parameters:message (string) – A message to return.

A helper function that returns a message, tagged with name, if VERBOSE is true.

name = None

The name of the test, typically derived from the file name of the test itself.


A stub method, for the passing() method, that case definitions may implement. The intention of the passing() method is that, when called it will take the test_spec for the current test and return a passing variant that the developer/writer can use to update a fixed test.

Raises DtfNotImplemented.


A wrapper for passing() that: - adds comments to the output for increased clarity.

  • only prints the passing specification if the instance attribute return_value is False.
Parameters:keys (list) – A list of top level keys that test_spec must have to be considered valid by validate().

Currently does not implement recursive key checking.

response(result, msg, verbose=False, fatal=False)
  • result (bool) –
  • string (msg) –
  • verbose (bool) – Causes response() a to False.
  • fatal (bool) – Defaults to False.

A helper method that orchestrates test operation. Takes no arguments and preforms the folloing operations:

  1. Calls validate() method, passing VEBOSE and FATAL as appropriate.
  2. Sets return_value to the value of the first element returned by test().
  3. Calls response() passing the results from test() VEBOSE and FATAL as appropriate.

A stub method for the test() method, that case definitions must implement.

test() should return a two-tuple that contains:

  1. A boolean that is True if the test passes and False if the test fails.
  2. A string that contains a message that may be delivered to the users depending on the verbosity settings.
test_spec = None

A dictionary, passed to the class during object creation, that holds the test specification imported from the user-supplied YAML specification.

validate(keys=None, test_keys=None, verbose=None, fatal=None)

All arguments to the validate() method are optional, and if any arguments have the value of None validate() will substitute values from the object instance or user input values.

  • keys (list) – A list of required keys that the test_spec.keys must contain to be valid.
  • test_keys (list) – A list of keys from the test_spec that the must be identical to or a superset of the keys in the keys list. Defaults to the value of test_spec.keys.
  • verbose (bool) – If true, validate() will return output that confirms valid tests in addition to reporting invalid tests. Defaults to the value of VERBOSE.
  • fatal (bool) – If true, validate() will raise an DtfException rather than printing the failure message for invalid tests..

Checks the keys in each test specification to ensure that the test has the required keys.