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 | 9d489c8 | 2019-09-18 18:43:45 +0200 | [diff] [blame] | 4 | import shutil |
| 5 | from osmo_gsm_tester import log, suite, config, report, util |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 6 | |
Neels Hofmeyr | 17c139e | 2017-04-12 02:42:02 +0200 | [diff] [blame] | 7 | config.ENV_CONF = './suite_test' |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 8 | |
Pau Espin Pedrol | 9d489c8 | 2019-09-18 18:43:45 +0200 | [diff] [blame] | 9 | example_trial_dir = os.path.join('test_trial_tmp') |
| 10 | |
| 11 | class FakeTrial(log.Origin): |
| 12 | def __init__(self): |
| 13 | super().__init__(log.C_TST, 'trial') |
| 14 | self.dir = util.Dir(example_trial_dir) |
| 15 | self._run_dir = None |
| 16 | |
| 17 | def get_run_dir(self): |
| 18 | if self._run_dir is not None: |
| 19 | return self._run_dir |
| 20 | self._run_dir = util.Dir(self.dir.new_child('test_run')) |
| 21 | self._run_dir.mkdir() |
| 22 | return self._run_dir |
| 23 | |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 24 | #log.style_change(trace=True) |
| 25 | |
| 26 | print('- non-existing suite dir') |
| 27 | assert(log.run_logging_exceptions(suite.load, 'does_not_exist') == None) |
| 28 | |
| 29 | print('- no suite.conf') |
| 30 | assert(log.run_logging_exceptions(suite.load, 'empty_dir') == None) |
| 31 | |
| 32 | print('- valid suite dir') |
| 33 | example_suite_dir = os.path.join('test_suite') |
| 34 | s_def = suite.load(example_suite_dir) |
| 35 | assert(isinstance(s_def, suite.SuiteDefinition)) |
| 36 | print(config.tostr(s_def.conf)) |
| 37 | |
| 38 | print('- run hello world test') |
Pau Espin Pedrol | 9d489c8 | 2019-09-18 18:43:45 +0200 | [diff] [blame] | 39 | trial = FakeTrial() |
Neels Hofmeyr | 6ccda11 | 2017-06-06 19:41:17 +0200 | [diff] [blame] | 40 | s = suite.SuiteRun(trial, 'test_suite', s_def) |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 41 | results = s.run_tests('hello_world.py') |
Pau Espin Pedrol | 0ffb414 | 2017-05-15 18:24:35 +0200 | [diff] [blame] | 42 | print(report.suite_to_text(s)) |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 43 | |
| 44 | log.style_change(src=True) |
| 45 | #log.style_change(trace=True) |
| 46 | print('\n- a test with an error') |
| 47 | results = s.run_tests('test_error.py') |
Pau Espin Pedrol | 0ffb414 | 2017-05-15 18:24:35 +0200 | [diff] [blame] | 48 | output = report.suite_to_text(s) |
Neels Hofmeyr | 6ccda11 | 2017-06-06 19:41:17 +0200 | [diff] [blame] | 49 | print(output) |
Pau Espin Pedrol | 0ffb414 | 2017-05-15 18:24:35 +0200 | [diff] [blame] | 50 | |
| 51 | print('\n- a test with a failure') |
| 52 | results = s.run_tests('test_fail.py') |
| 53 | output = report.suite_to_text(s) |
Neels Hofmeyr | 6ccda11 | 2017-06-06 19:41:17 +0200 | [diff] [blame] | 54 | print(output) |
Pau Espin Pedrol | 0ffb414 | 2017-05-15 18:24:35 +0200 | [diff] [blame] | 55 | |
| 56 | print('\n- a test with a raised failure') |
| 57 | results = s.run_tests('test_fail_raise.py') |
| 58 | output = report.suite_to_text(s) |
Neels Hofmeyr | 6ccda11 | 2017-06-06 19:41:17 +0200 | [diff] [blame] | 59 | print(output) |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 60 | |
Pau Espin Pedrol | 0b30279 | 2017-09-10 16:33:10 +0200 | [diff] [blame] | 61 | print('- test with half empty scenario') |
Pau Espin Pedrol | 9d489c8 | 2019-09-18 18:43:45 +0200 | [diff] [blame] | 62 | trial = FakeTrial() |
Pau Espin Pedrol | 0b30279 | 2017-09-10 16:33:10 +0200 | [diff] [blame] | 63 | scenario = config.Scenario('foo', 'bar') |
Pau Espin Pedrol | cbc7242 | 2017-09-14 15:55:49 +0200 | [diff] [blame] | 64 | scenario['resources'] = { 'bts': [{'type': 'osmo-bts-trx'}] } |
Pau Espin Pedrol | 0b30279 | 2017-09-10 16:33:10 +0200 | [diff] [blame] | 65 | s = suite.SuiteRun(trial, 'test_suite', s_def, [scenario]) |
| 66 | results = s.run_tests('hello_world.py') |
| 67 | print(report.suite_to_text(s)) |
| 68 | |
| 69 | print('- test with scenario') |
Pau Espin Pedrol | 9d489c8 | 2019-09-18 18:43:45 +0200 | [diff] [blame] | 70 | trial = FakeTrial() |
Pau Espin Pedrol | 0b30279 | 2017-09-10 16:33:10 +0200 | [diff] [blame] | 71 | scenario = config.Scenario('foo', 'bar') |
| 72 | scenario['resources'] = { 'bts': [{ 'times': '2', 'type': 'osmo-bts-trx', 'trx_list': [{'nominal_power': '10'}, {'nominal_power': '12'}]}, {'type': 'sysmo'}] } |
| 73 | s = suite.SuiteRun(trial, 'test_suite', s_def, [scenario]) |
| 74 | results = s.run_tests('hello_world.py') |
| 75 | print(report.suite_to_text(s)) |
| 76 | |
Pau Espin Pedrol | aab5692 | 2018-08-21 14:58:29 +0200 | [diff] [blame] | 77 | print('- test with scenario and modifiers') |
Pau Espin Pedrol | 9d489c8 | 2019-09-18 18:43:45 +0200 | [diff] [blame] | 78 | trial = FakeTrial() |
Pau Espin Pedrol | aab5692 | 2018-08-21 14:58:29 +0200 | [diff] [blame] | 79 | scenario = config.Scenario('foo', 'bar') |
| 80 | scenario['resources'] = { 'bts': [{ 'times': '2', 'type': 'osmo-bts-trx', 'trx_list': [{'nominal_power': '10'}, {'nominal_power': '12'}]}, {'type': 'sysmo'}] } |
| 81 | scenario['modifiers'] = { 'bts': [{ 'times': '2', 'trx_list': [{'nominal_power': '20'}, {'nominal_power': '20'}]}, {'type': 'sysmo'}] } |
| 82 | s = suite.SuiteRun(trial, 'test_suite', s_def, [scenario]) |
| 83 | s.reserve_resources() |
| 84 | print(repr(s.reserved_resources)) |
| 85 | results = s.run_tests('hello_world.py') |
| 86 | print(report.suite_to_text(s)) |
| 87 | |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 88 | print('\n- graceful exit.') |
Pau Espin Pedrol | 9d489c8 | 2019-09-18 18:43:45 +0200 | [diff] [blame] | 89 | #deleting generated tmp trial dir: |
| 90 | shutil.rmtree(example_trial_dir, ignore_errors=True) |
| 91 | |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 92 | # vim: expandtab tabstop=4 shiftwidth=4 |