~ubuntu-branches/ubuntu/trusty/python-rsa/trusty

« back to all changes in this revision

Viewing changes to run_tests.py

  • Committer: Package Import Robot
  • Author(s): TANIGUCHI Takaki
  • Date: 2013-12-27 16:47:49 UTC
  • Revision ID: package-import@ubuntu.com-20131227164749-zo0at7vx34w0pzuq
Tags: upstream-3.1.2
ImportĀ upstreamĀ versionĀ 3.1.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
# -*- coding: utf-8 -*-
 
3
 
 
4
import os
 
5
import sys
 
6
import unittest2 as unittest
 
7
 
 
8
current_path = os.path.abspath(os.path.dirname(__file__))
 
9
tests_path = os.path.join(current_path, 'tests')
 
10
sys.path[0:0] = [
 
11
    current_path,
 
12
    tests_path,
 
13
]
 
14
 
 
15
all_tests = [f[:-3] for f in os.listdir(tests_path)
 
16
             if f.startswith('test_') and f.endswith(".py")]
 
17
 
 
18
def get_suite(tests):
 
19
    tests = sorted(tests)
 
20
    suite = unittest.TestSuite()
 
21
    loader = unittest.TestLoader()
 
22
    for test in tests:
 
23
        suite.addTest(loader.loadTestsFromName(test))
 
24
    return suite
 
25
 
 
26
if __name__ == '__main__':
 
27
    """
 
28
    To run all tests:
 
29
        $ python run_tests.py
 
30
    To run a single test:
 
31
        $ python run_tests.py app
 
32
    To run a couple of tests:
 
33
        $ python run_tests.py app config sessions
 
34
    To run code coverage:
 
35
        $ coverage run run_tests.py
 
36
        $ coverage report -m
 
37
    """
 
38
    tests = sys.argv[1:]
 
39
    if not tests:
 
40
        tests = all_tests
 
41
    tests = ['%s' % t for t in tests]
 
42
    suite = get_suite(tests)
 
43
    unittest.TextTestRunner(verbosity=1).run(suite)