/usr/lib/python3/dist-packages/pyutilib/autotest/tests/test_driver.py is in python3-pyutilib 5.3.5-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | #
# Unit Tests for pyutilib.autotest
#
#
import os
import sys
from os.path import abspath, dirname
currdir = dirname(abspath(__file__))+os.sep
bindir = dirname(abspath(sys.executable))+os.sep
import pyutilib.th as unittest
from pyutilib.misc import setup_redirect, reset_redirect
import pyutilib.autotest
import pyutilib.subprocess
try:
import yaml
yaml_available=True
except ImportError:
yaml_available=False
try:
import json
json_available=True
except ImportError:
json_available=False
def filter(str):
return 'currdir' in str or \
'Ran' in str or \
'UserWarning' in str
def filter_t1(str):
return 'options' in str or \
'Options' in str or \
'usage' in str or \
'Usage' in str
class TestYaml(pyutilib.th.TestCase):
def setUp(self):
#if not yaml_available:
#self.skipTest("Skipping tests because YAML is not available")
self.t1 = os.environ.get('PYUTILIB_AUTOTEST_CATEGORIES',None)
self.t2 = os.environ.get('PYUTILIB_UNITTEST_CATEGORIES',None)
if not self.t1 is None:
del os.environ['PYUTILIB_AUTOTEST_CATEGORIES']
if not self.t2 is None:
del os.environ['PYUTILIB_UNITTEST_CATEGORIES']
def driver(self, *args):
tmp = ['autotest']
tmp += list(args)
pyutilib.autotest.run(tmp, {})
def tearDown(self):
if not self.t1 is None:
os.environ['PYUTILIB_AUTOTEST_CATEGORIES'] = self.t1
if not self.t2 is None:
os.environ['PYUTILIB_UNITTEST_CATEGORIES'] = self.t2
def test1(self):
"""run --help"""
setup_redirect(currdir+'test1.out')
self.driver('--help')
reset_redirect()
self.assertFileEqualsBaseline(currdir+'test1.out', currdir+'test1.txt', filter=filter_t1)
def test2(self):
"""run --help-suites example1.yml"""
setup_redirect(currdir+'test2.out')
self.driver('--help-suites',currdir+'example1.yml')
reset_redirect()
self.assertFileEqualsBaseline(currdir+'test2.out', currdir+'test2.txt')
def test3(self):
"""run --help-categories example1.yml"""
setup_redirect(currdir+'test3.out')
self.driver('--help-categories',currdir+'example1.yml')
reset_redirect()
self.assertFileEqualsBaseline(currdir+'test3.out', currdir+'test3.txt')
def test4(self):
"""run --help-tests suite1 example1.yml"""
setup_redirect(currdir+'test4.out')
self.driver('--help-tests','suite1',currdir+'example1.yml')
reset_redirect()
self.assertFileEqualsBaseline(currdir+'test4.out', currdir+'test4.txt')
def test5(self):
"""run example1.yml"""
pyutilib.subprocess.run(bindir+'pyutilib_test_driver '+currdir+'example1.yml', outfile=currdir+'test5.out')
self.assertFileEqualsBaseline(currdir+'test5.out', currdir+'test5.txt', filter=filter)
def test6(self):
"""run --cat x_suite2 --cat x_suite1 example1.yml"""
pyutilib.subprocess.run(bindir+'pyutilib_test_driver --cat x_suite2 --cat x_suite1 '+currdir+'example1.yml', outfile=currdir+'test6.out')
self.assertFileEqualsBaseline(currdir+'test6.out', currdir+'test6.txt', filter=filter)
class TestJson(pyutilib.th.TestCase):
def setUp(self):
if not json_available:
self.skipTest("Skipping tests because JSON is not available")
self.t1 = os.environ.get('PYUTILIB_AUTOTEST_CATEGORIES',None)
self.t2 = os.environ.get('PYUTILIB_UNITTEST_CATEGORIES',None)
if not self.t1 is None:
del os.environ['PYUTILIB_AUTOTEST_CATEGORIES']
if not self.t2 is None:
del os.environ['PYUTILIB_UNITTEST_CATEGORIES']
def driver(self, *args):
tmp = ['autotest']
tmp += list(args)
pyutilib.autotest.run(tmp, {})
def tearDown(self):
if not self.t1 is None:
os.environ['PYUTILIB_AUTOTEST_CATEGORIES'] = self.t1
if not self.t2 is None:
os.environ['PYUTILIB_UNITTEST_CATEGORIES'] = self.t2
def test1(self):
"""run --help"""
setup_redirect(currdir+'test1.out')
self.driver('--help')
reset_redirect()
self.assertFileEqualsBaseline(currdir+'test1.out', currdir+'test1.txt', filter=filter_t1)
def test2(self):
"""run --help-suites example1.json"""
setup_redirect(currdir+'test2.out')
self.driver('--help-suites',currdir+'example1.json')
reset_redirect()
self.assertFileEqualsBaseline(currdir+'test2.out', currdir+'test2.txt')
def test3(self):
"""run --help-categories example1.json"""
setup_redirect(currdir+'test3.out')
self.driver('--help-categories',currdir+'example1.json')
reset_redirect()
self.assertFileEqualsBaseline(currdir+'test3.out', currdir+'test3.txt')
def test4(self):
"""run --help-tests suite1 example1.json"""
setup_redirect(currdir+'test4.out')
self.driver('--help-tests','suite1',currdir+'example1.json')
reset_redirect()
self.assertFileEqualsBaseline(currdir+'test4.out', currdir+'test4.txt')
def test5(self):
"""run example1.json"""
pyutilib.subprocess.run(bindir+'pyutilib_test_driver '+currdir+'example1.json', outfile=currdir+'test5.out')
self.assertFileEqualsBaseline(currdir+'test5.out', currdir+'test5.txt', filter=filter)
def test6(self):
# run --cat x_suite2 --cat x_suite1 example1.json
pyutilib.subprocess.run(bindir+'pyutilib_test_driver --cat x_suite2 --cat x_suite1 '+currdir+'example1.json', outfile=currdir+'test6.out')
self.assertFileEqualsBaseline(currdir+'test6.out', currdir+'test6.txt', filter=filter)
if __name__ == "__main__":
unittest.main()
|