module pycode.unittestclass
¶
Short summary¶
module pyquickhelper.pycode.unittestclass
Overwrites unit test class with additional testing functions.
Classes¶
class |
truncated documentation |
---|---|
Overwrites unit test class with additional testing functions. Unless setUp is overwritten, warnings FutureWarning … |
Functions¶
function |
truncated documentation |
---|---|
Calls numpy.testing.assert_almost_equal. Add more informations in the exception message. |
|
Catches warnings. |
|
Skips a unit test if it runs on appveyor. |
|
Skips a unit test if it runs on azure pipeline. |
|
Skips a unit test if it runs on azure pipeline on linux. |
|
Skips a unit test if it runs on azure pipeline on linux. |
|
Skips a unit test if it runs on circleci. |
|
Skips a unit test if it runs on linux. |
|
Skips a unit test if it runs on travis. |
|
Skips a unit test if the version is stricly below version (tuple). |
|
Logs before and after a function is called. |
|
Skips a unit test if the version of one module is not at least the provided version. |
Static Methods¶
staticmethod |
truncated documentation |
---|---|
Returns |
|
Returns an absolute and normalized path from this location. |
|
Profiles the execution of a function with function |
|
Filters out FutureWarning, PendingDeprecationWarning. |
|
Stops filtering out FutureWarning, PendingDeprecationWarning. |
Methods¶
method |
truncated documentation |
---|---|
Checks that fct is callable. |
|
Checks that x is empty. |
|
Checks that string sub ends with whole. |
|
Checks that |
|
Checks that two arrays are equal. Relies on numpy.testing.assert_almost_equal. |
|
Checks that two dataframes are equal. Calls pandas.testing.assert_frame_equal. |
|
Checks that |
|
Checks that |
|
Checks that two numbers are equal. |
|
|
|
Checks that name exists. |
|
Checks that |
|
Checks that there is no NaN in |
|
Checks that substring sub is in text. |
|
Checks that |
|
Returns the logged information in a logger defined by its name. |
|
Checks that x is not empty. |
|
Checks that string sub does not end with whole. |
|
Checks that |
|
Checks that two arrays are equal. Relies on numpy.testing.assert_almost_equal. |
|
Checks that two dataframes are different. Calls pandas.testing.assert_frame_equal. |
|
Checks that name does not exist. |
|
Checks that string sub does not start with whole. |
|
Checks that function fct with no parameter raises an exception of a given type. |
|
Checks that string sub starts with whole. |
|
Returns the list of warnings raised while executing function fct. |
|
Runs a function and capture standard output and error. |
|
Prints out some information. |
|
Returns the content of a file. |
|
Writes the content of a file. |
Documentation¶
Overwrites unit test class with additional testing functions.
- 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.
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 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
- assertEqualArray(d1, d2, squeeze=False, **kwargs)[source]¶
Checks that two arrays are equal. Relies on numpy.testing.assert_almost_equal.
- assertEqualDataFrame(d1, d2, **kwargs)[source]¶
Checks that two dataframes are equal. Calls pandas.testing.assert_frame_equal.
- 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
- 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)
- assertNotEqualArray(d1, d2, squeeze=False, **kwargs)[source]¶
Checks that two arrays are equal. Relies on numpy.testing.assert_almost_equal.
- assertNotEqualDataFrame(d1, d2, **kwargs)[source]¶
Checks that two dataframes are different. Calls pandas.testing.assert_frame_equal.
- 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)
- assertWarning(fct)[source]¶
Returns the list of warnings raised while executing function fct.
- Parameters:
fct – function to run
- Returns:
result, list of warnings
- capture(fct)[source]¶
Runs a function and capture standard output and error.
- Parameters:
fct – function to run
- Returns:
result of fct, output, error
- 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
- 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
- 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
- pyquickhelper.pycode.unittestclass.ignore_warnings(warns)[source]¶
Catches warnings.
- Parameters:
warns – warnings to ignore
- pyquickhelper.pycode.unittestclass.skipif_appveyor(msg)[source]¶
Skips a unit test if it runs on appveyor.
- pyquickhelper.pycode.unittestclass.skipif_azure(msg)[source]¶
Skips a unit test if it runs on azure pipeline.
- pyquickhelper.pycode.unittestclass.skipif_azure_linux(msg)[source]¶
Skips a unit test if it runs on azure pipeline on linux.
- pyquickhelper.pycode.unittestclass.skipif_azure_macosx(msg)[source]¶
Skips a unit test if it runs on azure pipeline on linux.
- pyquickhelper.pycode.unittestclass.skipif_circleci(msg)[source]¶
Skips a unit test if it runs on circleci.
- pyquickhelper.pycode.unittestclass.skipif_linux(msg)[source]¶
Skips a unit test if it runs on linux.
- pyquickhelper.pycode.unittestclass.skipif_travis(msg)[source]¶
Skips a unit test if it runs on travis.
- pyquickhelper.pycode.unittestclass.skipif_vless(version, msg)[source]¶
Skips a unit test if the version is stricly below version (tuple).
- 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
- 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