Skip to content

Commit 704e757

Browse files
kschopmeyerandy-maier
kschopmeyer
authored andcommitted
Fix issue where tests fail if keys not sorted
In order to create consistent table output for test of instances names as table, the keys must be sorted. Otherwise the column orders are not consistent across different test targets, etc. This simply sorts the CIMInstanceName keys before the headers and rows are created for the table. Add tests for the changes where it caused test failures Fixed test issue whee we were not completing all tests in one unit test.
1 parent c771afd commit 704e757

File tree

4 files changed

+15
-14
lines changed

4 files changed

+15
-14
lines changed

pywbemtools/pywbemcli/_display_cimobjects.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,9 @@ def _display_paths_as_table(objects, table_width, table_format):
362362
for key_names, inst_names in objs_by_key_set.items():
363363
# Build headers for this table with the common elements and key
364364
# names for each key in the object. We use inst_names[0] to
365-
# restore original case to key strings.
366-
inst_keys = original_keys[key_names]
365+
# restore original case to key strings. We sort keys for
366+
# consistent table output.
367+
inst_keys = sorted(original_keys[key_names])
367368

368369
rows = []
369370
for instname in inst_names:

tests/unit/pywbemcli/test_display_cimobjects.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242

4343
from ..pytest_extensions import simplified_test_function
4444

45-
OK = False # mark tests OK when they execute correctly
45+
OK = True # mark tests OK when they execute correctly
4646
RUN = True # Mark OK = False and current test case being created RUN
4747
FAIL = False # Any test currently FAILING or not tested yet
4848
SKIP = False # mark tests that are to be skipped.
@@ -459,7 +459,7 @@ def string_instance(tst_str):
459459
4),
460460
kwargs={},
461461
exp_rtn=[
462-
['\n"AB"\n"CD"']],
462+
['"AB"\n"CD"']],
463463
),
464464
None, None, OK),
465465

@@ -504,7 +504,7 @@ def string_instance(tst_str):
504504
20),
505505
kwargs={},
506506
exp_rtn=[
507-
['\n"20140922104920.524"\n"789+000"']],
507+
['"20140922104920.524"\n"789+000"']],
508508
),
509509
None, None, OK),
510510

tests/unit/pywbemcli/test_instance_cmds.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -957,17 +957,17 @@ def GET_TEST_PATH_STR(filename): # pylint: disable=invalid-name
957957
'test': 'linesnows'},
958958
SIMPLE_MOCK_FILE, OK],
959959

960-
['Verify command enumerate with ssociation class inst name table output',
960+
['Verify command enumerate with association class inst name table output',
961961
{'args': ['enumerate', 'TST_A3', '--names-only'],
962962
'general': ['--output-format', 'table']},
963963
{'stdout': """InstanceNames: TST_A3
964964
+--------+-------------+---------+---------------------------------+---------------------------------+---------------------------------+
965965
| host | namespace | class | key= | key= | key= |
966-
| | | | Initiator | Target | LogicalUnit |
966+
| | | | Initiator | LogicalUnit | Target |
967967
|--------+-------------+---------+---------------------------------+---------------------------------+---------------------------------|
968-
| | root/cimv2 | TST_A3 | /root/cimv2:TST_EP.InstanceID=1 | /root/cimv2:TST_EP.InstanceID=2 | /root/cimv2:TST_LD.InstanceID=3 |
969-
| | root/cimv2 | TST_A3 | /root/cimv2:TST_EP.InstanceID=1 | /root/cimv2:TST_EP.InstanceID=5 | /root/cimv2:TST_LD.InstanceID=6 |
970-
| | root/cimv2 | TST_A3 | /root/cimv2:TST_EP.InstanceID=1 | /root/cimv2:TST_EP.InstanceID=7 | /root/cimv2:TST_LD.InstanceID=8 |
968+
| | root/cimv2 | TST_A3 | /root/cimv2:TST_EP.InstanceID=1 | /root/cimv2:TST_LD.InstanceID=3 | /root/cimv2:TST_EP.InstanceID=2 |
969+
| | root/cimv2 | TST_A3 | /root/cimv2:TST_EP.InstanceID=1 | /root/cimv2:TST_LD.InstanceID=6 | /root/cimv2:TST_EP.InstanceID=5 |
970+
| | root/cimv2 | TST_A3 | /root/cimv2:TST_EP.InstanceID=1 | /root/cimv2:TST_LD.InstanceID=8 | /root/cimv2:TST_EP.InstanceID=7 |
971971
+--------+-------------+---------+---------------------------------+---------------------------------+---------------------------------+
972972
""", # noqa: E501
973973
'rc': 0,

tests/unit/pywbemcli/test_subscription_cmds.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -785,8 +785,7 @@ def GET_TEST_PATH_STR(filename): # pylint: disable=invalid-name
785785
' Protocol = 2;',
786786
# Result -o plain subscription list-destinations --names-only
787787
'host namespace class key= key= key=',
788-
'interop CIM_ListenerDestinationCIMXML CIM_ComputerSystem '
789-
'MockSystem_WBEMServerTest CIM_ListenerDestinationCIMXML',
788+
'interop CIM_ListenerDestinationCIMXML CIM_ListenerDestinationCIMXML pywbemdestination:defaultpywbemcliSubMgr:odest1 CIM_ComputerSystem MockSystem_WBEMServerTest', # noqa: E501
790789
# Result list
791790
'1 CIMInstance(s) returned',
792791
'};'],
@@ -836,7 +835,7 @@ def GET_TEST_PATH_STR(filename): # pylint: disable=invalid-name
836835
'1 CIMInstance(s) returned',
837836
# Result from -o plain subscription list-filters --names-only
838837
'host namespace class key= key= key= key=',
839-
'interop CIM_IndicationFilter CIM_ComputerSystem MockSystem_WBEMServerTest CIM_IndicationFilter pywbemfilter:defaultpywbemcliSubMgr:ofilter1', ], # noqa: E501
838+
'interop CIM_IndicationFilter CIM_IndicationFilter pywbemfilter:defaultpywbemcliSubMgr:ofilter1 CIM_ComputerSystem MockSystem_WBEMServerTest', ], # noqa: E501
840839
'stderr': [],
841840
'test': 'innows'},
842841
None, OK],
@@ -868,7 +867,8 @@ def GET_TEST_PATH_STR(filename): # pylint: disable=invalid-name
868867
' Filter =',
869868
'interop:CIM_IndicationFilter.CreationClassName=', 'CIM_IndicationFilter', # noqa: E501
870869
'pywbemfilter:defaultpywbemcliSubMgr:ofilter1',
871-
'SystemCreationClassName=', 'CIM_ComputerSystem', 'SystemName=', 'MockSystem_WBEMServerTest', # noqa: E501
870+
'SystemCreationClassName=', 'CIM_ComputerSystem', 'SystemName=', # noqa: E501
871+
'MockSystem_WBEMServerTest',
872872
' Handler =',
873873
' OnFatalErrorPolicy = 2;',
874874
' RepeatNotificationPolicy = 2;',

0 commit comments

Comments
 (0)