coalib.testing package

Submodules

coalib.testing.BearTestHelper module

coalib.testing.BearTestHelper.generate_skip_decorator(bear)[source]

Creates a skip decorator for a unittest module test from a bear.

check_prerequisites is used to determine a test skip.

Parameters:bear – The bear whose prerequisites determine the test skip.
Returns:A decorator that skips the test if appropriate.

coalib.testing.LocalBearTestHelper module

class coalib.testing.LocalBearTestHelper.LocalBearTestHelper(methodName='runTest')[source]

Bases: unittest.case.TestCase

This is a helper class for simplification of testing of local bears.

Please note that all abstraction will prepare the lines so you don’t need to do that if you use them.

If you miss some methods, get in contact with us, we’ll be happy to help!

check_results(local_bear, lines, results, filename=None, check_order=False, force_linebreaks=True, create_tempfile=True, tempfile_kwargs={}, settings={})[source]

Asserts that a check of the given lines with the given local bear does yield exactly the given results.

Parameters:
  • local_bear – The local bear to check with.
  • lines – The lines to check. (List of strings)
  • results – The expected list of results.
  • filename – The filename, if it matters.
  • force_linebreaks – Whether to append newlines at each line if needed. (Bears expect a n for every line)
  • create_tempfile – Whether to save lines in tempfile if needed.
  • tempfile_kwargs – Kwargs passed to tempfile.mkstemp().
  • settings – A dictionary of keys and values (both strings) from which settings will be created that will be made available for the tested bear.
check_validity(local_bear, lines, filename=None, valid=True, force_linebreaks=True, create_tempfile=True, tempfile_kwargs={})[source]

Asserts that a check of the given lines with the given local bear either yields or does not yield any results.

Parameters:
  • local_bear – The local bear to check with.
  • lines – The lines to check. (List of strings)
  • filename – The filename, if it matters.
  • valid – Whether the lines are valid or not.
  • force_linebreaks – Whether to append newlines at each line if needed. (Bears expect a n for every line)
  • create_tempfile – Whether to save lines in tempfile if needed.
  • tempfile_kwargs – Kwargs passed to tempfile.mkstemp().
coalib.testing.LocalBearTestHelper.execute_bear(bear, *args, **kwargs)[source]
coalib.testing.LocalBearTestHelper.verify_local_bear(bear, valid_files, invalid_files, filename=None, settings={}, force_linebreaks=True, create_tempfile=True, timeout=None, tempfile_kwargs={})[source]

Generates a test for a local bear by checking the given valid and invalid file contents. Simply use it on your module level like:

YourTestName = verify_local_bear(YourBear, ([‘valid line’],),
([‘invalid line’],))
Parameters:
  • bear – The Bear class to test.
  • valid_files – An iterable of files as a string list that won’t yield results.
  • invalid_files – An iterable of files as a string list that must yield results.
  • filename – The filename to use for valid and invalid files.
  • settings – A dictionary of keys and values (both string) from which settings will be created that will be made available for the tested bear.
  • force_linebreaks – Whether to append newlines at each line if needed. (Bears expect a n for every line)
  • create_tempfile – Whether to save lines in tempfile if needed.
  • timeout – The total time to run the test for.
  • tempfile_kwargs – Kwargs passed to tempfile.mkstemp() if tempfile needs to be created.
Returns:

A unittest.TestCase object.

Module contents