diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 0000000..5e7d51a --- /dev/null +++ b/.coveragerc @@ -0,0 +1,26 @@ +# .coveragerc to control coverage.py +[run] +branch = True +exclude_lines = + # Have to re-enable the standard pragma + pragma: no cover + + # Don't complain about missing debug-only code: + def __repr__ + if self\.debug + + # Don't complain if tests don't hit defensive assertion code: + raise AssertionError + raise NotImplementedError + + # Don't complain if non-runnable code isn't run: + if 0: + if __name__ == .__main__.: +source = + ./certcheck/ + + +[html] +directory = test/output_coverage_html + +[paths] diff --git a/README.md b/README.md index 22317de..9ebaf8c 100644 --- a/README.md +++ b/README.md @@ -140,7 +140,38 @@ test/ directory you can find: - moduletests/ - the unittests themselves - fabric/ - sample input files and test certificates temporary directories - output_coverage_html/ - coverage tests results in a form of an html webpage -- test.py - script to start all the unittests + +Unittests can be started either by using *nosetest* command: + +``` +certcheck/ (master✗) # nosetests +[20:33:02] +...... +---------------------------------------------------------------------- +Ran 6 tests in 0.449s + +OK +``` + +or by issuing the *run_tests.py* command: + +``` +certcheck/ (master✗) # run_tests.py +[20:33:04] +Created test certificate expired_3_days.pem +Created test certificate expire_6_days.pem +Created test certificate expire_21_days.pem +Created test certificate expire_41_days.pem +Created test certificate expire_41_days.der +...... +---------------------------------------------------------------------- +Ran 6 tests in 0.362s + +OK +``` + +The difference is that the *run_tests.py* takes care of generating coverage +reports for you. All the dependencies required for performing the unittests are decribed in debian packaging scripts and are as follows: @@ -148,5 +179,4 @@ packaging scripts and are as follows: - coverage - python-mock - openssl command in the PATH - -Plus all the dependencies mentioned in 'Project Setup' section. +, plus all the dependencies mentioned in 'Project Setup' section. diff --git a/nose.cfg b/nose.cfg deleted file mode 100644 index e13c638..0000000 --- a/nose.cfg +++ /dev/null @@ -1,6 +0,0 @@ -[nosetests] -with-coverage=1 -cover-package=certcheck -cover-erase=1 -cover-html=1 -cover-html-dir=test/output_coverage_html/ diff --git a/run_tests.py b/run_tests.py new file mode 100755 index 0000000..8b4d90e --- /dev/null +++ b/run_tests.py @@ -0,0 +1,48 @@ +#!/usr/bin/python -tt + +#Make it a bit more like python3: +from __future__ import absolute_import +from __future__ import print_function + +import coverage +import os +import shutil +import sys +import unittest + + +def main(): + major, minor, micro, releaselevel, serial = sys.version_info + + if major == 2 and minor < 7: + print("In order to run tests you need at least Python 2.7") + sys.exit(1) + + if major == 3: + print("Tests were not tested on Python 3.X, use at your own risk") + sys.exit(1) + + #Cleanup old html report: + for root, dirs, files in os.walk('test/output_coverage_html/'): + for f in files: + if f == '.gitignore' or f == '.empty_dir': + continue + os.unlink(os.path.join(root, f)) + for d in dirs: + shutil.rmtree(os.path.join(root, d)) + + #Perform coverage analisys: + cov = coverage.coverage() + + cov.start() + #Discover the test and execute them: + loader = unittest.TestLoader() + tests = loader.discover('./test/') + testRunner = unittest.runner.TextTestRunner(descriptions=True, verbosity=1) + testRunner.run(tests) + cov.stop() + + cov.html_report() + +if __name__ == '__main__': + main()