Test Utilities¶
Helper functions for testing.
New in version 1.2.0.
clean_orphaned_pyc - delete *.pyc files without corresponding *.py
is_pyflakes_available - checks if pyflakes is available
is_pep8_available - checks if pep8 is available
get_stylistic_issues - checks for PEP8 and other stylistic issues
get_pyflakes_issues - static checks for problems via pyflakes
- stem.util.test_tools.clean_orphaned_pyc(paths)[source]¶
Deletes any file with a *.pyc extention without a corresponding *.py. This helps to address a common gotcha when deleting python files...
- You delete module 'foo.py' and run the tests to ensure that you haven't broken anything. They pass, however there are still some 'import foo' statements that still work because the bytecode (foo.pyc) is still around.
- You push your change.
- Another developer clones our repository and is confused because we have a bunch of ImportErrors.
Parameters: paths (list) -- paths to search for orphaned pyc files Returns: list of absolute paths that were deleted
- stem.util.test_tools.is_pyflakes_available()[source]¶
Checks if pyflakes is availalbe.
Returns: True if we can use pyflakes and False otherwise
- stem.util.test_tools.is_pep8_available()[source]¶
Checks if pep8 is availalbe.
Returns: True if we can use pep8 and False otherwise
- stem.util.test_tools.get_stylistic_issues(paths, check_two_space_indents=False, check_newlines=False, check_trailing_whitespace=False, check_exception_keyword=False)[source]¶
Checks for stylistic issues that are an issue according to the parts of PEP8 we conform to. You can suppress PEP8 issues by making a 'test' configuration that sets 'pep8.ignore'.
For example, with a 'test/settings.cfg' of...
# PEP8 compliance issues that we're ignoreing... # # * E111 and E121 four space indentations # * E501 line is over 79 characters pep8.ignore E111 pep8.ignore E121 pep8.ignore E501
... you can then run tests with...
import stem.util.conf test_config = stem.util.conf.get_config('test') test_config.load('test/settings.cfg') issues = get_stylistic_issues('my_project')
If a 'exclude_paths' was set in our test config then we exclude any absolute paths matching those regexes.
Parameters: - paths (list) -- paths to search for stylistic issues
- check_two_space_indents (bool) -- check for two space indentations and that no tabs snuck in
- check_newlines (bool) -- check that we have standard newlines (n), not windows (rn) nor classic mac (r)
- check_trailing_whitespace (bool) -- check that our lines don't end with trailing whitespace
- check_exception_keyword (bool) -- checks that we're using 'as' for exceptions rather than a comma
Returns: dict of the form path => [(line_number, message)...]
- stem.util.test_tools.get_pyflakes_issues(paths)[source]¶
Performs static checks via pyflakes. False positives can be ignored via 'pyflakes.ignore' entries in our 'test' config. For instance...
pyflakes.ignore stem/util/test_tools.py => 'pyflakes' imported but unused pyflakes.ignore stem/util/test_tools.py => 'pep8' imported but unused
If a 'exclude_paths' was set in our test config then we exclude any absolute paths matching those regexes.
Parameters: paths (list) -- paths to search for problems Returns: dict of the form path => [(line_number, message)...]