coalib.testing package

Submodules

coalib.testing.BaseTestHelper module

class coalib.testing.BaseTestHelper.BaseTestHelper[source]

Bases: object

This is a base class for all Bears’ tests of coala’s testing API.

assert_result_equal(observed_result, expected_result)[source]

Asserts that an observed result from a bear is exactly same as the expected result from the bear.

Parameters:
  • observed_result – The observed result from a bear
  • expected_result – The expected result from a bear

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!

assertComparableObjectsEqual(observed_result, expected_result)[source]
check_invalidity(local_bear, lines, filename=None, force_linebreaks=True, create_tempfile=True, tempfile_kwargs={}, settings={})[source]

Asserts that a check of the given lines with the given local bear yields results.

Parameters:
  • local_bear – The local bear to check with.
  • lines – The lines to check. (List of strings)
  • 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().
check_line_result_count(local_bear, lines, results_num, filename=None, force_linebreaks=True, create_tempfile=True, tempfile_kwargs={}, settings={})[source]

Check many results for each line.

Parameters:
  • local_bear – The local bear to check with.
  • lines – The lines to check. (List of strings)
  • results_num – The expected list of many results each line.
  • 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_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.
  • check_order – Whether to check that the elements of results and that of the actual list generated are in the same order 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().
  • 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={}, settings={})[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.get_results(local_bear, lines, filename=None, force_linebreaks=True, create_tempfile=True, tempfile_kwargs={}, settings={})[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