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