From 2694a9d329dfefc01e5e8d0477177589781d9585 Mon Sep 17 00:00:00 2001 From: Neels Hofmeyr Date: Thu, 27 Apr 2017 19:48:09 +0200 Subject: [PATCH] fix 'make check' Apply various fixes that arose from test case code rot. These tests will now be used to verify patches submitted to gerrit, so they need to be up to par. Change-Id: I5277be0c434226d9d02e038f0bc72fd2557350c1 Related: OS#2215 --- selftest/conf/resources.conf | 4 ++-- selftest/config_test.py | 2 +- selftest/resource_test.ok | 8 ++++---- selftest/suite_test.ok | 4 ++++ selftest/suite_test.py | 2 +- selftest/suite_test/resources.conf | 4 ++-- selftest/template_test.py | 2 +- src/osmo_gsm_tester/log.py | 14 +++++++++++--- 8 files changed, 26 insertions(+), 14 deletions(-) diff --git a/selftest/conf/resources.conf b/selftest/conf/resources.conf index c17acf52..178e13cf 100644 --- a/selftest/conf/resources.conf +++ b/selftest/conf/resources.conf @@ -17,7 +17,7 @@ bts: ipa_unit_id: 5 addr: 10.42.42.115 band: GSM-1800 - trx: + trx_list: - hw_addr: 00:0c:90:32:b5:8a - label: nanoBTS 1900 @@ -25,7 +25,7 @@ bts: ipa_unit_id: 1902 addr: 10.42.42.190 band: GSM-1900 - trx: + trx_list: - hw_addr: 00:02:95:00:41:b3 arfcn: diff --git a/selftest/config_test.py b/selftest/config_test.py index ce4d939a..61ec73aa 100755 --- a/selftest/config_test.py +++ b/selftest/config_test.py @@ -14,7 +14,7 @@ example_config_file = 'test.cfg' example_config = os.path.join(_prep.script_dir, 'config_test', example_config_file) cfg = config.read(example_config) -pprint.pprint(cfg) +pprint.pprint(cfg, width=81) test_schema = { 'modems[].dbus_path': schema.STR, diff --git a/selftest/resource_test.ok b/selftest/resource_test.ok index ae31d3b4..413e5d0e 100644 --- a/selftest/resource_test.ok +++ b/selftest/resource_test.ok @@ -51,14 +51,14 @@ ok, caused exception: RuntimeError('Refusing to drop a list of resources from it 'band': 'GSM-1800', 'ipa_unit_id': '5', 'label': 'octBTS 3000', - 'trx': [{'hw_addr': '00:0c:90:32:b5:8a'}], + 'trx_list': [{'hw_addr': '00:0c:90:32:b5:8a'}], 'type': 'oct'}, {'_hash': '0b7fabd512b36aec43d7d496abd00af4e193b0f8', 'addr': '10.42.42.190', 'band': 'GSM-1900', 'ipa_unit_id': '1902', 'label': 'nanoBTS 1900', - 'trx': [{'hw_addr': '00:02:95:00:41:b3'}], + 'trx_list': [{'hw_addr': '00:02:95:00:41:b3'}], 'type': 'nanobts'}], 'modem': [{'_hash': '19c69e45aa090fb511446bd00797690aa82ff52f', 'imsi': '901700000007801', @@ -168,7 +168,7 @@ ok, caused exception: RuntimeError('Refusing to drop a list of resources from it band: GSM-1800 ipa_unit_id: '5' label: octBTS 3000 - trx: + trx_list: - hw_addr: 00:0c:90:32:b5:8a type: oct --- (want='modem'): DBG: Looking for 2 x modem , candidates: 16 @@ -209,7 +209,7 @@ bts: band: GSM-1800 ipa_unit_id: '5' label: octBTS 3000 - trx: + trx_list: - hw_addr: 00:0c:90:32:b5:8a type: oct modem: diff --git a/selftest/suite_test.ok b/selftest/suite_test.ok index fe7fbcb1..2fad8b36 100644 --- a/selftest/suite_test.ok +++ b/selftest/suite_test.ok @@ -16,7 +16,10 @@ resources: - times: '1' - run hello world test +tst test_suite: Suite run start tst test_suite: reserving resources... +tst test_suite: DBG: {combining='resources'} [test_suite↪test_suite] +tst test_suite: DBG: {definition_conf={bts=[{'times': '1'}], modem=[{'times': '2'}], nitb_iface=[{'times': '1'}]}} [test_suite↪(combining_scenarios='resources')↪test_suite] --- (want='bts'): DBG: Looking for 1 x bts , candidates: 3 --- (want='bts'): DBG: Picked - _hash: 07d9c8aaa940b674efcbbabdd69f58a6ce4e94f9 addr: 10.42.42.114 @@ -48,6 +51,7 @@ tst hello_world.py: PASS [test_suite↪hello_world.py] pass: all 1 tests passed. - a test with an error +tst test_suite: Suite run start [suite.py:191] tst test_error.py: START [test_suite↪test_error.py] [suite.py:96] tst test_error.py:3: I am 'test_suite' / 'test_error.py:3' [test_suite↪test_error.py:3] [test_error.py:3] tst test_error.py:5: FAIL [test_suite↪test_error.py:5] [suite.py:108] diff --git a/selftest/suite_test.py b/selftest/suite_test.py index cbbd6be3..315c6836 100755 --- a/selftest/suite_test.py +++ b/selftest/suite_test.py @@ -20,7 +20,7 @@ assert(isinstance(s_def, suite.SuiteDefinition)) print(config.tostr(s_def.conf)) print('- run hello world test') -s = suite.SuiteRun(None, s_def) +s = suite.SuiteRun(None, 'test_suite', s_def) results = s.run_tests('hello_world.py') print(str(results)) diff --git a/selftest/suite_test/resources.conf b/selftest/suite_test/resources.conf index c17acf52..178e13cf 100644 --- a/selftest/suite_test/resources.conf +++ b/selftest/suite_test/resources.conf @@ -17,7 +17,7 @@ bts: ipa_unit_id: 5 addr: 10.42.42.115 band: GSM-1800 - trx: + trx_list: - hw_addr: 00:0c:90:32:b5:8a - label: nanoBTS 1900 @@ -25,7 +25,7 @@ bts: ipa_unit_id: 1902 addr: 10.42.42.190 band: GSM-1900 - trx: + trx_list: - hw_addr: 00:02:95:00:41:b3 arfcn: diff --git a/selftest/template_test.py b/selftest/template_test.py index 2b44ae56..31d9e80a 100755 --- a/selftest/template_test.py +++ b/selftest/template_test.py @@ -19,7 +19,7 @@ mock_timeslot_list=( ) mock_bts = { - 'type': 'val_type', + 'osmobsc_bts_type': 'val_type', 'band': 'val_band', 'location_area_code': 'val_bts.location_area_code', 'base_station_id_code': 'val_bts.base_station_id_code', diff --git a/src/osmo_gsm_tester/log.py b/src/osmo_gsm_tester/log.py index 3e969994..b581e2cb 100644 --- a/src/osmo_gsm_tester/log.py +++ b/src/osmo_gsm_tester/log.py @@ -24,6 +24,8 @@ import traceback import contextlib from inspect import getframeinfo, stack +from .util import is_dict + L_ERR = 30 L_LOG = 20 L_DBG = 10 @@ -512,14 +514,20 @@ def run_logging_exceptions(func, *func_args, return_on_failure=None, **func_kwar log_exn() return return_on_failure +def _compose_named_items(item): + 'make sure dicts are output sorted, for test expectations' + if is_dict(item): + return '{%s}' % (', '.join( + ['%s=%s' % (k, _compose_named_items(v)) + for k,v in sorted(item.items())])) + return repr(item) + def compose_message(messages, named_items): msgs = [str(m) for m in messages] if named_items: # unfortunately needs to be sorted to get deterministic results - msgs.append('{%s}' % - (', '.join(['%s=%r' % (k,v) - for k,v in sorted(named_items.items())]))) + msgs.append(_compose_named_items(named_items)) return ' '.join(msgs)