A simple python testing framework for educational purposes
pip install checkpy
Besides installing checkPy, you might want to download some tests along with it. Simply run checkPy with the -d arg as follows:
checkpy -d YOUR_GITHUB_TESTS_URL
usage: checkpy [-h] [-m MODULE] [-d GITHUBLINK] [-clean] [file] checkPy: a simple python testing framework positional arguments: file name of file to be tested optional arguments: -h, --help show this help message and exit -m MODULE provide a module name or path to run all tests from the module, or target a module for a specific test -d GITHUBLINK download tests from a Github repository and exit -clean remove all tests from the tests folder and exit
To simply test a single file, call:
If you are unsure whether multiple tests exist with the same name, you can target a specific test by specifying its module:
checkpy YOUR_FILE_NAME -m YOUR_MODULE_NAME
If you want to test all files from a module within your current working directory, then this is the command for you:
checkpy -m YOUR_MODULE_NAME
Tests in checkPy are collections of abstract methods that you as a test designer need to implement. A test may look something like the following:
0| @t.failed(exact) 1| @t.test(1) 2| def contains(test): 3| test.test = lambda : assertlib.contains(lib.outputOf(_fileName), "100") 4| test.description = lambda : "contains 100 in the output" 5| test.fail = lambda info : "the correct answer (100) cannot be found in the output"
From top to bottom:
Test methods are discovered in checkPy by filename. If one wants to test a file foo.py, the corresponding test must be named fooTest.py. checkPy assumes that all methods in the test file are tests, as such one should not use the from ... import ... statement when importing modules.
A test minimally consists of the following:
import check.test as t @t.test(0) def someTest(test): test.test = lambda : False test.description = lambda : "some description"
Here the method someTest is marked as test by the decorator test. The abstract methods test and description are implemented as these are the only methods that necessarily require implementation. For more information on tests and their abstract methods you should refer to test.py. Note that besides defining the Test class and its abstract methods, test.py also provides several decorators for introducing test dependencies such as failed.
When providing a concrete implementation for the test method one should take a closer look at lib.py and assertlib.py. lib.py provides a collection of useful functions to help implement tests. Most notably getFunction and outputOf. These provide the tester with a function from the source file and the complete print output respectively. Calling getFunction makes checkPy evaluate only import statements and code inside definitions of the to be tested file. Effectively all other parts of code are wrapped by if __name__ == "__main__" and thus ignored. assertlib.py provides a collection of assertions that one may find usefull when implementing tests.
For inspiration inspect some existing collections of tests like the tests for progNS2016.
CheckPy can download tests directly from Github repos. The only requirement is that a folder called tests exists within the repo that contains only tests and folders (which checkpy treats as modules). Simply call checkPy with the optional -d argument and pass your github repo url. Tests will then be automatically downloaded and installed.
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|File Name & Checksum SHA256 Checksum Help||Version||File Type||Upload Date|
|checkPy-0.2.15-py2-none-any.whl (25.5 kB) Copy SHA256 Checksum SHA256||2.7||Wheel||Jan 22, 2017|
|checkPy-0.2.15.zip (21.9 kB) Copy SHA256 Checksum SHA256||–||Source||Jan 22, 2017|