blob: 16342c5c65e7a23248ed0166e90d9b866c7f6143 [file] [log] [blame]
Neels Hofmeyr3531a192017-03-28 14:30:28 +02001#!/usr/bin/env python3
2import os
3import _prep
Pau Espin Pedrol0ffb4142017-05-15 18:24:35 +02004from osmo_gsm_tester import log, suite, config, report
Neels Hofmeyr3531a192017-03-28 14:30:28 +02005
Neels Hofmeyr17c139e2017-04-12 02:42:02 +02006config.ENV_CONF = './suite_test'
Neels Hofmeyr3531a192017-03-28 14:30:28 +02007
8#log.style_change(trace=True)
9
10print('- non-existing suite dir')
11assert(log.run_logging_exceptions(suite.load, 'does_not_exist') == None)
12
13print('- no suite.conf')
14assert(log.run_logging_exceptions(suite.load, 'empty_dir') == None)
15
16print('- valid suite dir')
17example_suite_dir = os.path.join('test_suite')
18s_def = suite.load(example_suite_dir)
19assert(isinstance(s_def, suite.SuiteDefinition))
20print(config.tostr(s_def.conf))
21
22print('- run hello world test')
Neels Hofmeyr2694a9d2017-04-27 19:48:09 +020023s = suite.SuiteRun(None, 'test_suite', s_def)
Neels Hofmeyr3531a192017-03-28 14:30:28 +020024results = s.run_tests('hello_world.py')
Pau Espin Pedrol0ffb4142017-05-15 18:24:35 +020025print(report.suite_to_text(s))
Neels Hofmeyr3531a192017-03-28 14:30:28 +020026
27log.style_change(src=True)
28#log.style_change(trace=True)
29print('\n- a test with an error')
30results = s.run_tests('test_error.py')
Pau Espin Pedrol0ffb4142017-05-15 18:24:35 +020031output = report.suite_to_text(s)
32assert 'FAIL: [test_suite] 1 failed ' in output
33assert 'FAIL: [test_error.py]' in output
34assert "type:'AssertionError' message: AssertionError()" in output
35assert 'assert False' in output
36
37print('\n- a test with a failure')
38results = s.run_tests('test_fail.py')
39output = report.suite_to_text(s)
40assert 'FAIL: [test_suite] 1 failed ' in output
41assert 'FAIL: [test_fail.py]' in output
42assert "type:'EpicFail' message: This failure is expected" in output
43assert "test.set_fail('EpicFail', 'This failure is expected')" in output
44
45print('\n- a test with a raised failure')
46results = s.run_tests('test_fail_raise.py')
47output = report.suite_to_text(s)
48assert 'FAIL: [test_suite] 1 failed ' in output
49assert 'FAIL: [test_fail_raise.py]' in output
50assert "type:'EpicFail' message: This failure is expected" in output
51assert "raise Failure('EpicFail', 'This failure is expected')" in output
Neels Hofmeyr3531a192017-03-28 14:30:28 +020052
53print('\n- graceful exit.')
54# vim: expandtab tabstop=4 shiftwidth=4