module pycode.unittestclass

Inheritance diagram of pyquickhelper.pycode.unittestclass

Short summary

module pyquickhelper.pycode.unittestclass

Overwrites unit test class with additional testing functions.

source on GitHub

Classes

class

truncated documentation

ExtTestCase

Overwrites unit test class with additional testing functions. Unless setUp is overwritten, warnings FutureWarning

Functions

function

truncated documentation

assert_almost_equal_detailed

Calls numpy.testing.assert_almost_equal. Add more informations in the exception message.

ignore_warnings

Catches warnings.

skipif_appveyor

Skips a unit test if it runs on appveyor.

skipif_azure

Skips a unit test if it runs on azure pipeline.

skipif_azure_linux

Skips a unit test if it runs on azure pipeline on linux.

skipif_azure_macosx

Skips a unit test if it runs on azure pipeline on linux.

skipif_circleci

Skips a unit test if it runs on circleci.

skipif_linux

Skips a unit test if it runs on linux.

skipif_travis

Skips a unit test if it runs on travis.

skipif_vless

Skips a unit test if the version is stricly below version (tuple).

testlog

Logs before and after a function is called.

unittest_require_at_least

Skips a unit test if the version of one module is not at least the provided version.

Static Methods

staticmethod

truncated documentation

_format_str

Returns s or 's' depending on the type.

abs_path_join

Returns an absolute and normalized path from this location.

profile

Profiles the execution of a function with function profile.

setUpClass

Filters out FutureWarning, PendingDeprecationWarning.

tearDownClass

Stops filtering out FutureWarning, PendingDeprecationWarning.

Methods

method

truncated documentation

assertCallable

Checks that fct is callable.

assertEmpty

Checks that x is empty.

assertEndsWith

Checks that string sub ends with whole.

assertEqual

Checks that a == b.

assertEqualArray

Checks that two arrays are equal. Relies on numpy.testing.assert_almost_equal.

assertEqualDataFrame

Checks that two dataframes are equal. Calls pandas.testing.assert_frame_equal.

assertEqualDict

Checks that a == b.

assertEqualFloat

Checks that abs(a-b) < precision.

assertEqualNumber

Checks that two numbers are equal.

assertEqualSparseArray

assertExists

Checks that name exists.

assertGreater

Checks that x >= y.

assertHasNoNan

Checks that there is no NaN in a.

assertIn

Checks that substring sub is in text.

assertLesser

Checks that x <= y.

assertLogging

Returns the logged information in a logger defined by its name.

assertNotEmpty

Checks that x is not empty.

assertNotEndsWith

Checks that string sub does not end with whole.

assertNotEqual

Checks that a != b.

assertNotEqualArray

Checks that two arrays are equal. Relies on numpy.testing.assert_almost_equal.

assertNotEqualDataFrame

Checks that two dataframes are different. Calls pandas.testing.assert_frame_equal.

assertNotExists

Checks that name does not exist.

assertNotStartsWith

Checks that string sub does not start with whole.

assertRaise

Checks that function fct with no parameter raises an exception of a given type.

assertStartsWith

Checks that string sub starts with whole.

assertWarning

Returns the list of warnings raised while executing function fct.

capture

Runs a function and capture standard output and error.

fLOG

Prints out some information. fLOG().

read_file

Returns the content of a file.

write_file

Writes the content of a file.

Documentation

Overwrites unit test class with additional testing functions.

source on GitHub

class pyquickhelper.pycode.unittestclass.ExtTestCase(methodName='runTest')[source]

Bases: TestCase

Overwrites unit test class with additional testing functions. Unless setUp is overwritten, warnings FutureWarning and PendingDeprecationWarning are filtered out.

source on GitHub

Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.

static _format_str(s)[source]

Returns s or 's' depending on the type.

source on GitHub

static abs_path_join(filename, *args)[source]

Returns an absolute and normalized path from this location.

Parameters:
  • filename – filename, the folder which contains it is used as the base

  • args – list of subpaths to the previous path

Returns:

absolute and normalized path

source on GitHub

assertCallable(fct)[source]

Checks that fct is callable.

source on GitHub

assertEmpty(x, none_allowed=True)[source]

Checks that x is empty.

source on GitHub

assertEndsWith(sub, whole)[source]

Checks that string sub ends with whole.

source on GitHub

assertEqual(a, b)[source]

Checks that a == b.

source on GitHub

assertEqualArray(d1, d2, squeeze=False, **kwargs)[source]

Checks that two arrays are equal. Relies on numpy.testing.assert_almost_equal.

source on GitHub

assertEqualDataFrame(d1, d2, **kwargs)[source]

Checks that two dataframes are equal. Calls pandas.testing.assert_frame_equal.

source on GitHub

assertEqualDict(a, b)[source]

Checks that a == b.

source on GitHub

assertEqualFloat(a, b, precision=1e-05)[source]

Checks that abs(a-b) < precision.

source on GitHub

assertEqualNumber(d1, d2, **kwargs)[source]

Checks that two numbers are equal.

source on GitHub

assertExists(name)[source]

Checks that name exists.

source on GitHub

assertGreater(x, y, strict=False)[source]

Checks that x >= y.

source on GitHub

assertHasNoNan(a)[source]

Checks that there is no NaN in a.

source on GitHub

assertIn(sub, ensemble, msg=None)[source]

Checks that substring sub is in text.

Parameters:
  • sub – sub set

  • ensemble – full set

  • msg – error message

@raises AssertionError

source on GitHub

assertLesser(x, y, strict=False)[source]

Checks that x <= y.

source on GitHub

assertLogging(fct, logger_name, level=20, log_sphinx=False, console=False)[source]

Returns the logged information in a logger defined by its name.

Parameters:
  • fct – function to run

  • logger_name – logger name

  • level – level to intercept

  • log_sphinx – logging from sphinx

  • console – shows the log on console

Returns:

tuple(result, logged information)

source on GitHub

assertNotEmpty(x)[source]

Checks that x is not empty.

source on GitHub

assertNotEndsWith(sub, whole)[source]

Checks that string sub does not end with whole.

source on GitHub

assertNotEqual(a, b)[source]

Checks that a != b.

source on GitHub

assertNotEqualArray(d1, d2, squeeze=False, **kwargs)[source]

Checks that two arrays are equal. Relies on numpy.testing.assert_almost_equal.

source on GitHub

assertNotEqualDataFrame(d1, d2, **kwargs)[source]

Checks that two dataframes are different. Calls pandas.testing.assert_frame_equal.

source on GitHub

assertNotExists(name)[source]

Checks that name does not exist.

source on GitHub

assertNotStartsWith(sub, whole)[source]

Checks that string sub does not start with whole.

source on GitHub

assertRaise(fct, exc=None, msg=None)[source]

Checks that function fct with no parameter raises an exception of a given type.

Parameters:
  • fct – function to test (no parameter)

  • exc – exception type to catch (None for all)

  • msg – error message to check (None for no message to check)

source on GitHub

assertStartsWith(sub, whole)[source]

Checks that string sub starts with whole.

source on GitHub

assertWarning(fct)[source]

Returns the list of warnings raised while executing function fct.

Parameters:

fct – function to run

Returns:

result, list of warnings

source on GitHub

capture(fct)[source]

Runs a function and capture standard output and error.

Parameters:

fct – function to run

Returns:

result of fct, output, error

source on GitHub

fLOG(*args, **kwargs)[source]

Prints out some information. fLOG.

source on GitHub

static profile(fct, sort='cumulative', rootrem=None, return_results=False)[source]

Profiles the execution of a function with function profile.

Parameters:
  • fct – function to profile

  • sort – see pstats.Stats.sort_stats()

  • rootrem – root to remove in filenames

  • return_results – return the results as well

Returns:

statistics text dump

source on GitHub

read_file(filename, mode='r', encoding='utf-8')[source]

Returns the content of a file.

Parameters:
  • filename – filename

  • encoding – encoding

  • mode – reading mode

Returns:

content

source on GitHub

classmethod setUpClass()[source]

Filters out FutureWarning, PendingDeprecationWarning.

source on GitHub

classmethod tearDownClass()[source]

Stops filtering out FutureWarning, PendingDeprecationWarning.

source on GitHub

write_file(filename, content, mode='w', encoding='utf-8')[source]

Writes the content of a file.

Parameters:
  • filename – filename

  • content – content to write

  • encoding – encoding

  • mode – reading mode

Returns:

content

source on GitHub

pyquickhelper.pycode.unittestclass.assert_almost_equal_detailed(expected, value, **kwargs)[source]

Calls numpy.testing.assert_almost_equal. Add more informations in the exception message.

Parameters:
  • expected – expected value

  • value – value

Raises:

AssertionError

source on GitHub

pyquickhelper.pycode.unittestclass.ignore_warnings(warns)[source]

Catches warnings.

Parameters:

warns – warnings to ignore

source on GitHub

pyquickhelper.pycode.unittestclass.skipif_appveyor(msg)[source]

Skips a unit test if it runs on appveyor.

source on GitHub

pyquickhelper.pycode.unittestclass.skipif_azure(msg)[source]

Skips a unit test if it runs on azure pipeline.

source on GitHub

pyquickhelper.pycode.unittestclass.skipif_azure_linux(msg)[source]

Skips a unit test if it runs on azure pipeline on linux.

source on GitHub

pyquickhelper.pycode.unittestclass.skipif_azure_macosx(msg)[source]

Skips a unit test if it runs on azure pipeline on linux.

source on GitHub

pyquickhelper.pycode.unittestclass.skipif_circleci(msg)[source]

Skips a unit test if it runs on circleci.

source on GitHub

pyquickhelper.pycode.unittestclass.skipif_linux(msg)[source]

Skips a unit test if it runs on linux.

source on GitHub

pyquickhelper.pycode.unittestclass.skipif_travis(msg)[source]

Skips a unit test if it runs on travis.

source on GitHub

pyquickhelper.pycode.unittestclass.skipif_vless(version, msg)[source]

Skips a unit test if the version is stricly below version (tuple).

source on GitHub

pyquickhelper.pycode.unittestclass.testlog(logtype='print')[source]

Logs before and after a function is called.

Parameters:

logtype – kind of logging, only ‘print’ is implemented and None to disable it

source on GitHub

pyquickhelper.pycode.unittestclass.unittest_require_at_least(mod, version, msg='')[source]

Skips a unit test if the version of one module is not at least the provided version.

Parameters:
  • mod – module (the module must have an attribute __version__)

  • version – expected version or more recent

  • msg – message

source on GitHub