Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | import os |
| 3 | import _prep |
Pau Espin Pedrol | 0ffb414 | 2017-05-15 18:24:35 +0200 | [diff] [blame] | 4 | from osmo_gsm_tester import log, suite, config, report |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 5 | |
Neels Hofmeyr | 17c139e | 2017-04-12 02:42:02 +0200 | [diff] [blame] | 6 | config.ENV_CONF = './suite_test' |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 7 | |
| 8 | #log.style_change(trace=True) |
| 9 | |
| 10 | print('- non-existing suite dir') |
| 11 | assert(log.run_logging_exceptions(suite.load, 'does_not_exist') == None) |
| 12 | |
| 13 | print('- no suite.conf') |
| 14 | assert(log.run_logging_exceptions(suite.load, 'empty_dir') == None) |
| 15 | |
| 16 | print('- valid suite dir') |
| 17 | example_suite_dir = os.path.join('test_suite') |
| 18 | s_def = suite.load(example_suite_dir) |
| 19 | assert(isinstance(s_def, suite.SuiteDefinition)) |
| 20 | print(config.tostr(s_def.conf)) |
| 21 | |
| 22 | print('- run hello world test') |
Neels Hofmeyr | 2694a9d | 2017-04-27 19:48:09 +0200 | [diff] [blame] | 23 | s = suite.SuiteRun(None, 'test_suite', s_def) |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 24 | results = s.run_tests('hello_world.py') |
Pau Espin Pedrol | 0ffb414 | 2017-05-15 18:24:35 +0200 | [diff] [blame] | 25 | print(report.suite_to_text(s)) |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 26 | |
| 27 | log.style_change(src=True) |
| 28 | #log.style_change(trace=True) |
| 29 | print('\n- a test with an error') |
| 30 | results = s.run_tests('test_error.py') |
Pau Espin Pedrol | 0ffb414 | 2017-05-15 18:24:35 +0200 | [diff] [blame] | 31 | output = report.suite_to_text(s) |
| 32 | assert 'FAIL: [test_suite] 1 failed ' in output |
| 33 | assert 'FAIL: [test_error.py]' in output |
| 34 | assert "type:'AssertionError' message: AssertionError()" in output |
| 35 | assert 'assert False' in output |
| 36 | |
| 37 | print('\n- a test with a failure') |
| 38 | results = s.run_tests('test_fail.py') |
| 39 | output = report.suite_to_text(s) |
| 40 | assert 'FAIL: [test_suite] 1 failed ' in output |
| 41 | assert 'FAIL: [test_fail.py]' in output |
| 42 | assert "type:'EpicFail' message: This failure is expected" in output |
| 43 | assert "test.set_fail('EpicFail', 'This failure is expected')" in output |
| 44 | |
| 45 | print('\n- a test with a raised failure') |
| 46 | results = s.run_tests('test_fail_raise.py') |
| 47 | output = report.suite_to_text(s) |
| 48 | assert 'FAIL: [test_suite] 1 failed ' in output |
| 49 | assert 'FAIL: [test_fail_raise.py]' in output |
| 50 | assert "type:'EpicFail' message: This failure is expected" in output |
| 51 | assert "raise Failure('EpicFail', 'This failure is expected')" in output |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 52 | |
| 53 | print('\n- graceful exit.') |
| 54 | # vim: expandtab tabstop=4 shiftwidth=4 |