tests¶
This file contains test cases for Privex’s Python Helper’s (privex-helpers).
Before running the tests:
Ensure you have any mandatory requirements installed (see setup.py’s install_requires)
You may wish to install any optional requirements listed in README.md for best results
Python 3.7 is recommended at the time of writing this. See README.md in-case this has changed.
To run the tests, simply execute ./tests.py
in your shell:
user@the-matrix ~/privex-helpers $ ./tests.py
............................
----------------------------------------------------------------------
Ran 28 tests in 0.001s
OK
If for some reason you don’t have the executable python3.7
in your PATH, try running by hand with python3
user@the-matrix ~/privex-helpers $ python3 tests.py
............................
----------------------------------------------------------------------
Ran 28 tests in 0.001s
OK
For more verbosity, simply add -v
to the end of the command:
user@the-matrix ~/privex-helpers $ ./tests.py -v
test_empty_combined (__main__.TestBoolHelpers) ... ok
test_isfalse_truthy (__main__.TestBoolHelpers) ... ok
test_v4_arpa_boundary_16bit (__main__.TestIPReverseDNS)
Test generating 16-bit v4 boundary ... ok
test_v4_arpa_boundary_24bit (__main__.TestIPReverseDNS)
Test generating 24-bit v4 boundary ... ok
test_kval_single (__main__.TestParseHelpers)
Test that a single value still returns a list ... ok
test_kval_spaced (__main__.TestParseHelpers)
Test key:val csv parsing with excess outer whitespace, and value whitespace ... ok
# Truncated excess output in this PyDoc example, as there are many more lines showing
# the results of each individual testcase, wasting space and adding bloat...
----------------------------------------------------------------------
Ran 28 tests in 0.001s
OK
You can also use the pytest
tool (used by default for our Travis CI):
user@host: ~/privex-helpers $ pip3 install pytest
# You can add `-v` for more detailed output, just like when running tests.py directly.
user@host: ~/privex-helpers $ pytest tests.py
===================================== test session starts =====================================
platform darwin -- Python 3.7.0, pytest-5.0.1, py-1.8.0, pluggy-0.12.0
rootdir: /home/user/privex-helpers
collected 33 items
tests.py ................................. [100%]
====================================== warnings summary =======================================
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/jinja2/utils.py:485
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/jinja2/utils.py:485:
DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc'
is deprecated, and in 3.8 it will stop working
from collections import MutableMapping
============================ 33 passed, 2 warnings in 0.17 seconds ============================
Copyright:
Copyright 2019 Privex Inc. ( https://www.privex.io )
License: X11 / MIT Github: https://github.com/Privex/python-helpers
Classes
A mock iterable object with zero length for testing empty() |
|
|
Test the boolean check functions is_true, is_false, as well as empty() |
|
Unit testing for the reverse DNS functions in |
|
Test the parsing functions parse_csv and parse_keyval |
|
Base test-case for module test cases to inherit. |
-
class
tests.
PrivexBaseCase
(methodName='runTest')[source]¶ Base test-case for module test cases to inherit.
Contains useful class attributes such as
falsey
andempty_vals
that are used across different unit tests.-
falsey
= ['false', 'FALSE', False, 0, '0', 'no']¶ Normal False-y values, as various types
-
falsey_empty
= ['false', 'FALSE', False, 0, '0', 'no', None, '', 'null']¶ False-y values, plus ‘empty’ values like ‘’ and None
-
truthy
= [True, 'TRUE', 'true', 'yes', 'y', '1', 1]¶ Truthful values, as various types
-
-
class
tests.
TestBoolHelpers
(methodName='runTest')[source]¶ Test the boolean check functions is_true, is_false, as well as empty()
-
class
tests.
TestIPReverseDNS
(methodName='runTest')[source]¶ Unit testing for the reverse DNS functions in
privex.helpers.net
- Covers:
positive resolution tests (generate standard rDNS domain from clean input)
positive boundary tests (confirm valid results with range of boundaries)
negative address tests (ensure errors thrown for invalid v4/v6 addresses)
negative boundary tests (ensure errors thrown for invalid v4/v6 rDNS boundaries)
-
class
tests.
TestParseHelpers
(methodName='runTest')[source]¶ Test the parsing functions parse_csv and parse_keyval
-
test_kval_custom_clean
()[source]¶ Test that a clean key:val csv with custom split characters is parsed correctly (pipe for kv, semi-colon for pair separation)
-
-
class
tests.
TestRedisCache
(methodName='runTest')[source]¶ Unit tests which verify that the decorator
privex.helpers.decorators.r_test()
caches correctly, and also verifies dynamic cache key generation works as expected.-
test_rcache_callable
()[source]¶ Decorate random string function - use a lambda callable to determine a cache key
-