minimal test of 'cmdtest.py' used as module
This commit is contained in:
34
python/t/CMDTEST_as_module.py
Normal file
34
python/t/CMDTEST_as_module.py
Normal file
@ -0,0 +1,34 @@
|
||||
|
||||
from os.path import dirname, abspath, join as path_join
|
||||
|
||||
class TC_as_module(TestCase):
|
||||
|
||||
def setup(self):
|
||||
self.always_ignore_file('subdir/tmp-cmdtest-python/')
|
||||
|
||||
def test_as_module(self):
|
||||
self.create_file("subdir/CMDTEST_foo.py", [
|
||||
'class TC_foo(TestCase):',
|
||||
' def test_01(self):',
|
||||
' with self.cmd("echo hello") as c:',
|
||||
' c.stdout_equal("hello\\n")',
|
||||
' def test_02(self):',
|
||||
' with self.cmd("echo world") as c:',
|
||||
' c.stdout_equal("world\\n")',
|
||||
' def test_03(self):',
|
||||
' with self.cmd("echo hello") as c:',
|
||||
' c.stdout_equal("world\\n")',
|
||||
])
|
||||
|
||||
dpath = dirname(abspath(__file__))
|
||||
command = path_join(dpath, 'as_module.py')
|
||||
with self.cmd(command + ' subdir') as c:
|
||||
c.stdout_match([
|
||||
r'--- ERROR: stdout_equal',
|
||||
r'actual:',
|
||||
r' hello',
|
||||
r'expect:',
|
||||
r' world',
|
||||
r'Statistics\(classes=1, methods=3, command=3, errors=1, fatals=0\)',
|
||||
])
|
||||
c.exit_nonzero()
|
18
python/t/as_module.py
Executable file
18
python/t/as_module.py
Executable file
@ -0,0 +1,18 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import os
|
||||
import sys
|
||||
from os.path import dirname
|
||||
|
||||
# import from 'cmdtest.py' in other directory
|
||||
sys.path.insert(0, dirname(dirname(os.path.abspath(__file__))))
|
||||
from cmdtest import cmdtest_in_dir, Statistics
|
||||
|
||||
def main():
|
||||
dirpath = sys.argv[1]
|
||||
statistics = cmdtest_in_dir(dirpath)
|
||||
print(statistics)
|
||||
exit(0 if statistics.errors == 0 and statistics.fatals == 0 else 1)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
Reference in New Issue
Block a user