Skip to content
This repository has been archived by the owner on Jul 17, 2019. It is now read-only.

Commit

Permalink
Fix documentation reg. unittest, add run_tests.py
Browse files Browse the repository at this point in the history
There is a problem with running nosetest - the previous html coverage reports
are not properly removed thus subsequent runs of nosetest --with-coverage...
result in "File exists error".

The old run_tests.py file was restored and put into the main directory. It takes
care of removing old html reports and running the tests.
  • Loading branch information
Vespian committed Mar 9, 2014
1 parent 47e80bc commit 957d555
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 9 deletions.
26 changes: 26 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -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]
36 changes: 33 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,43 @@ 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:
- unittests2
- 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.
6 changes: 0 additions & 6 deletions nose.cfg

This file was deleted.

48 changes: 48 additions & 0 deletions run_tests.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 957d555

Please sign in to comment.