jasper package

Submodules

jasper.context module

The context module.

class jasper.context.Context(**kwargs)

Bases: object

A dictionary-like object where attributes can be accessed using the ‘.’ operator.

Initialize a new Context object.

Parameters:kwargs – Keys and values to store into this Context on creation.
copy()

Get a deep copy of this Context.

Returns:A new Context object which is a copy of this Context.

jasper.display module

The display module.

class jasper.display.Display(force_ansi=True, verbosity_level=0)

Bases: object

The class responsible for displaying the results of a suites, features, scenarios, and steps.

Initialize a new Display object.

Parameters:
  • force_ansi – Flag for whether or not to force the display to use ansi escape sequences. default is True.
  • verbosity_level – The verbosity level for the display to use. default is 0, maxes out at 2.
cyan(text)

Color some text cyan.

If the displays color is disabled the text will not be colorized.

Parameters:text – The text to color.
Returns:The colored text
display()

Print the prepared data to the screen.

grey(text)

Color some text grey.

If the displays color is disabled the text will not be colorized.

Parameters:text – The text to color.
Returns:The colored text
static indent(text, amount)

Indent some text by the given amount.

Parameters:
  • text – The text to indent.
  • amount – The amount of spaces to indent the text with.
Returns:

The indented text.

prepare_border(color, length)

Prepare a border to be displayed.

Parameters:
  • color – The color to give the border.
  • length – The length of the border.
prepare_exception(exception)

Prepare an exception to be displayed.

Parameters:exception – The exception to prepare.
prepare_feature(feature)

Prepare a Feature object to be displayed.

Parameters:feature – The Feature to prepare.
prepare_scenario(scenario)

Prepare a Scenario object to be displayed.

Parameters:scenario – The Scenario to prepare.
prepare_statistics(suite)

Prepare the statistics of a Suite object to be displayed.

Parameters:suite – The Suite object to prepare the statistics for.
prepare_step(step, step_name)

Prepare a Step object to be displayed.

Parameters:
  • step – The Step to prepare.
  • step_name – A name to represent the step with.
prepare_suite(suite)

Prepare a Suite object to be displayed.

Parameters:suite – The Suite to prepare.
red(text)

Color some text red.

If the displays color is disabled the text will not be colorized.

Parameters:text – The text to color.
Returns:The colored text
yellow(text)

Color some text yellow.

If the displays color is disabled the text will not be colorized.

Parameters:text – The text to color.
Returns:The colored text

jasper.entrypoints module

The entrypoints module.

jasper.exceptions module

The exceptions module.

exception jasper.exceptions.ExpectationException(actual, expected, operator)

Bases: Exception

An Exception that is thrown when an expectation fails in the Expect class.

Initialize this ExpectationException object.

Parameters:
  • actual – The actual data used during the expectation.
  • expected – The expected data used during the expectation.
  • operator – The operator used during the expectation.
exception jasper.exceptions.ValidationException

Bases: Exception

An Exception that is thrown when an object fails validation during construction.

jasper.expect module

The expect module.

class jasper.expect.Expect(actual_data)

Bases: object

A class for making assertions on data.

Initialize a new Expect object.

Parameters:actual_data – The actual data to make assertions against.
not_()

Negate any future expectations.

Returns:This Expect object.
to_be(expected_data)

Make an assertion that this objects actual data is the expected data.

Parameters:expected_data – The data to expect the actual data to be.
Raises:ExpectationException – If the expectation fails.
to_be_greater_than(expected_data)

Make an assertion that this objects actual data is greater than the expected data.

Parameters:expected_data – The data to expect the actual data to be less than.
Raises:ExpectationException – If the expectation fails.
to_be_greater_than_or_equal_to(expected_data)

Make an assertion that this objects actual data is greater than or equal to the expected data

Parameters:expected_data – The data to expect the actual data to be greater than or equal to.
Raises:ExpectationException – If the expectation fails.
to_be_less_than(expected_data)

Make an assertion that this objects actual data is less than the expected data.

Parameters:expected_data – The data to expect the actual data to be less than.
Raises:ExpectationException – If the expectation fails.
to_be_less_than_or_equal_to(expected_data)

Make an assertion that this objects actual data is less than or equal to the expected data

Parameters:expected_data – The data to expect the actual data to be less than or equal to.
Raises:ExpectationException – If the expectation fails.
to_equal(expected_data)

Make an assertion that this objects actual data is equal to the expected data.

Parameters:expected_data – The data to expect the actual data to be equal to.
Raises:ExpectationException – If the expectation fails.

jasper.feature module

The feature module.

class jasper.feature.Feature(description, scenarios, before_each=[], before_all=[], after_each=[], after_all=[])

Bases: object

A class used for testing the high level features of an application.

Initialize a new Feature object.

Parameters:
  • description – A description of this Feature.
  • scenarios – A list of scenarios for testing various parts of the feature this object represents.
  • before_each – Steps that will run before each of the scenarios.
  • before_all – Steps that will run before all other steps.
  • after_each – Steps that will run after each of the scenarios.
  • after_all – Steps that will run after all other steps.
num_scenarios_failed

The number of scenarios that failed after running this feature.

num_scenarios_passed

The number of scenarios that passed after running this feature.

run()

Run all the steps and scenarios of this Feature.

jasper.runner module

The runner module.

class jasper.runner.Runner(test_directory)

Bases: object

The class responsible for finding, building, and running features.

Initialize a new Runner object.

Parameters:test_directory – The directory to search for feature files in.
build_suite()

Build a Suite object out of the Features contained within the found feature files.

discover()

Find any feature files within the given test directory.

run()

Discover the feature files, build the suite, and run the tests.

Returns:The Suite that has been built and run.

jasper.scenario module

The scenario module.

class jasper.scenario.Scenario(description, given, when, then, before_each=[], before_all=[], after_each=[], after_all=[])

Bases: object

A class used for testing different parts of an applications features.

Initialize a new Scenario object.

Parameters:
  • description – A description of this scenario.
  • given – Steps for supplying this scenario with something to test with.
  • when – Steps that should run whatever it is this scenario is testing.
  • then – Steps that should make assertions against the results of the test.
  • before_each – Steps that will run before each of the given, when, and then steps.
  • before_all – Steps that will run before all other steps.
  • after_each – Steps that will run after each of the given, when, and then steps.
  • after_all – Steps that will run after all other steps.
run(context)

Run all the steps of this Scenario.

Parameters:context – A Context object to pass into each step of this Scenario.
Returns:

jasper.steps module

The steps module.

class jasper.steps.Step(function, **kwargs)

Bases: object

The Step class is used as a wrapper around functions for testing behaviours.

Initialize a new Step object.

Parameters:
  • function – The function this step will call when this step is run.
  • kwargs – Kwargs to call the given function with.
run(context)

Run this step and record the results.

Parameters:context – A context object too pass into this steps function.
jasper.steps.step(func)

A decorator for wrapping a function into a Step object.

Parameters:func – The function to create a step out of.
Returns:A function which when called will return a new instance of a Step object.

jasper.suite module

The suite module.

class jasper.suite.Suite

Bases: object

An internal class for running a collection of Feature of objects and collecting results.

Initialize a new Suite object.

add_feature(feature)

Add a feature to this suite.

Parameters:feature – The Feature object to add to this suite.
num_features_failed

The number of features that failed after running this suite.

num_features_passed

The number of features that passed after running this suite.

num_scenarios_failed

The number of scenarios that failed after running this suite.

num_scenarios_passed

The number of scenarios that passed running this suite.

run()

Run all the features of this suite.

jasper.utility module

The utility module.

jasper.utility.extract_traceback(exception)

Utility function for extracting the traceback from an exception.

Parameters:exception – The exception to extract the traceback from.
Returns:The extracted traceback.

Module contents