mirror of
				https://github.com/Telecominfraproject/oopt-gnpy.git
				synced 2025-10-31 18:18:00 +00:00 
			
		
		
		
	tests: requests: rely on pytest's own dict support
When `pytest` is run with `-vv`, it shows a diff of multiline strings
and dict just fine. The only drawback is that there's the raw string
with newlines shown as "\n", however, *then* the nice diff pretty
printing kicks in, and the result is:
 E                 Common items:
 E                 {'response-id': '5'}
 E                 Differing items:
 E                 {'path-properties': {'path-metric': [{'accumulative-value': 21.68, 'metric-type': 'SNR-bandwidth'}, {'accumulative-val...EDFA', 'link-tp-id': 'east edfa in Rennes_STA to Stbrieuc', 'node-id': 'east edfa in Rennes_STA to Stbrieuc'}}}, ...]}} != {'path-properties': {'path-metric': [{'accumulative-value': 21.68, 'metric-type': 'SNR-bandwidth'}, {'accumulative-val...EDFA', 'link-tp-id': 'east edfa in Rennes_STA to Stbrieuc', 'node-id': 'east edfa in Rennes_STA to Stbrieuc'}}}, ...]}}
 E                 Full diff:
 E                   {
 E                    'path-properties': {'path-metric': [{'accumulative-value': 21.68,
 E                                                         'metric-type': 'SNR-bandwidth'},
 E                                                        {'accumulative-value': 28.77,
 E                                                         'metric-type': 'SNR-0.1nm'},
 E                                                        {'accumulative-value': 23.7,
 E                                                         'metric-type': 'OSNR-bandwidth'},
 E                                                        {'accumulative-value': 30.79,
 E                                                         'metric-type': 'OSNR-0.1nm'},
 E                                                        {'accumulative-value': 0.0019952623149688794,
 E                                                         'metric-type': 'reference_power'},
 E                                                        {'accumulative-value': 20000000000.0,
 E                                                         'metric-type': 'path_bandwidth'}],
 ...
 ... now, it's a bit annoying that there's too much output, but
 ... that's just for context; the offending lines will be properly
 ... marked, see --\
 ...               |
 ...               v
 ...
 E                                                               {'path-route-object': {'index': 17,
 E                 -                                                                    'num-unnum-hop': {'gnpy-node-type': 'transceiver',
 E                 ?                                                                                       ^ ^^^^^^^  - ^      ^^^^^^^^^ -
 E                 +                                                                    'num-unnum-hop': {'link-tp-id': 'trx '
 E                 ?                                                                                       ^^ ^   ^^^      ^^
 E                 -                                                                                      'link-tp-id': 'trx '
 E                                                                                                                      'Lannion_CAS',
 E                                                                                                        'node-id': 'trx '
 E                                                                                                                   'Lannion_CAS'}}},
 E                                                               {'path-route-object': {'index': 18,
 E                                                                                      'label-hop': {'M': 6,
 E                                                                                                    'N': -274}}},
 E                                                               {'path-route-object': {'index': 19,
 E                                                                                      'transponder': {'transponder-mode': 'mode '
 E                                                                                                                          '2',
 E                                                                                                      'transponder-type': 'vendorA_trx-type1'}}}]},
 E                    'response-id': '5',
 E                   }
 tests/test_parser.py:312: AssertionError
Change-Id: I60b4e3bfa432a720a381bf2c0a9f0288e989dab2
			
			
This commit is contained in:
		| @@ -243,35 +243,6 @@ def test_csv_response_generation(tmpdir, json_input): | ||||
|         print(type(list(resp[column])[-1])) | ||||
|  | ||||
|  | ||||
| def compare_response(exp_resp, act_resp): | ||||
|     """ False if the keys are different in the nested dicts as well | ||||
|     """ | ||||
|     print(exp_resp) | ||||
|     print(act_resp) | ||||
|     test = True | ||||
|     for key in act_resp.keys(): | ||||
|         if key not in exp_resp.keys(): | ||||
|             print(f'{key} is not expected') | ||||
|             return False | ||||
|         if isinstance(act_resp[key], dict): | ||||
|             test = compare_response(exp_resp[key], act_resp[key]) | ||||
|     if test: | ||||
|         for key in exp_resp.keys(): | ||||
|             if key not in act_resp.keys(): | ||||
|                 print(f'{key} is expected') | ||||
|                 return False | ||||
|             if isinstance(exp_resp[key], dict): | ||||
|                 test = compare_response(exp_resp[key], act_resp[key]) | ||||
|  | ||||
|     # at this point exp_resp and act_resp have the same keys. Check if their values are the same | ||||
|     for key in act_resp.keys(): | ||||
|         if not isinstance(act_resp[key], dict): | ||||
|             if exp_resp[key] != act_resp[key]: | ||||
|                 print(f'expected value :{exp_resp[key]}\n actual value: {act_resp[key]}') | ||||
|                 return False | ||||
|     return test | ||||
|  | ||||
|  | ||||
| # test json answers creation | ||||
| @pytest.mark.parametrize('xls_input, expected_response_file', { | ||||
|     DATA_DIR / 'testTopology.xls': DATA_DIR / 'testTopology_response.json', | ||||
| @@ -327,7 +298,7 @@ def test_json_response_generation(xls_input, expected_response_file): | ||||
|         if i == 2: | ||||
|             # compare response must be False because z-a metric is missing | ||||
|             # (request with bidir option to cover bidir case) | ||||
|             assert not compare_response(expected['response'][i], response) | ||||
|             assert expected['response'][i] != response | ||||
|             print(f'response {response["response-id"]} should not match') | ||||
|             expected['response'][2]['path-properties']['z-a-path-metric'] = [ | ||||
|                 {'metric-type': 'SNR-bandwidth', 'accumulative-value': 22.809999999999999}, | ||||
| @@ -338,8 +309,7 @@ def test_json_response_generation(xls_input, expected_response_file): | ||||
|                 {'metric-type': 'path_bandwidth', 'accumulative-value': 60000000000.0}] | ||||
|             # test should be OK now | ||||
|         else: | ||||
|             assert compare_response(expected['response'][i], response) | ||||
|             print(f'response {response["response-id"]} is not correct') | ||||
|             assert expected['response'][i] == response | ||||
|  | ||||
| # test the correspondance names dict in case of excel input | ||||
| # test that using the created json network still works with excel input | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Jan Kundrát
					Jan Kundrát