diff --git a/appveyor.yml b/appveyor.yml index 8f9b427ba..5b56bf4eb 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -9,9 +9,9 @@ environment: UNIX_PATH: none PYTHON_CMD: python -# - TOX_ENV: win64_py27_64 -# UNIX_PATH: none -# PYTHON_CMD: python + - TOX_ENV: win64_py27_64 + UNIX_PATH: none + PYTHON_CMD: python # - TOX_ENV: win64_py34_32 # UNIX_PATH: none @@ -49,9 +49,9 @@ environment: # UNIX_PATH: none # PYTHON_CMD: python -# - TOX_ENV: win64_py38_64 -# UNIX_PATH: none -# PYTHON_CMD: python + - TOX_ENV: win64_py38_64 + UNIX_PATH: none + PYTHON_CMD: python # Note: On CygWin with Python 3.x, LC_ALL/LANG need to be set to utf-8 for Click to install/work diff --git a/pywbemtools/pywbemcli/_cimvalueformatter.py b/pywbemtools/pywbemcli/_cimvalueformatter.py index 653ac7618..174ff0f83 100644 --- a/pywbemtools/pywbemcli/_cimvalueformatter.py +++ b/pywbemtools/pywbemcli/_cimvalueformatter.py @@ -184,7 +184,11 @@ def _scalar_value_tomof(value, type, indent, maxline, line_pos=0, end_space=0, val = six.text_type(value) return _mofstr(val, indent, maxline, line_pos, end_space, avoid_splits) elif type == 'reference': - val = value.to_wbem_uri() + try: + # requires pywbem >= 1.0.0 + val = value.to_wbem_uri(format='sorted') + except ValueError: + val = value.to_wbem_uri(format='standard') return _mofstr(val, indent, maxline, line_pos, end_space, avoid_splits) elif isinstance(value, (CIMFloat, CIMInt, int, _Longint)): val = six.text_type(value) diff --git a/tests/unit/test_common.py b/tests/unit/test_common.py index af57e1fd3..5bb775cba 100755 --- a/tests/unit/test_common.py +++ b/tests/unit/test_common.py @@ -23,6 +23,7 @@ from datetime import datetime import unittest +from packaging.version import parse as parse_version import click from mock import patch import pytest @@ -34,7 +35,7 @@ from pywbem import CIMClass, CIMProperty, CIMQualifier, CIMInstance, \ CIMQualifierDeclaration, CIMInstanceName, Uint8, Uint32, Uint64, Sint32, \ - CIMDateTime, CIMClassName + CIMDateTime, CIMClassName, __version__ from tests.unit.pytest_extensions import simplified_test_function @@ -58,6 +59,10 @@ FAIL = False # Any test currently FAILING or not tested yet SKIP = False # mark tests that are to be skipped. +_PYWBEM_VERSION = parse_version(__version__) +# pywbem 1.0.0 beta or final (but not dev) +PYWBEM_1_0_0_NON_DEV = _PYWBEM_VERSION.release >= (1, 0, 0) and \ + _PYWBEM_VERSION.dev is None TESTCASES_ISCLASSNAME = [ # TESTCASES for is_classname @@ -2664,7 +2669,7 @@ def test_format_insts_as_rows(testcase, args, kwargs, exp_rtn): # * kwargs: Keyword arguments for the test function: # * args: CIMInstance(s) object to be tested, col_width field, ouput_fmt # * kwargs: Dict of input args for tocimxml(). - # * exp_tbl: Expected Table to be output. + # * exp_out: Expected output on stdout. # * exp_exc_types: Expected exception type(s), or None. # * exp_warn_types: Expected warning type(s), or None. # * condition: Boolean condition for testcase to run, or 'pdb' for debugger @@ -2675,27 +2680,33 @@ def test_format_insts_as_rows(testcase, args, kwargs, exp_rtn): dict( args=([simple_instance()], None, 'simple'), kwargs=dict(), - exp_tbl=[ - 'Pbt Pbf Pint32 Pint64 Pdt ' - 'Pstr1\n' - '----- ----- -------- -------- --------------------- ' - '-------------\n' - 'true false 99 9999 "20140922104920.5247"' - ' "Test String"\n' - ' "89+000"\n' - ], + exp_stdout="""\ +Instances: CIM_Foo +Pbt Pbf Pint32 Pint64 Pdt Pstr1 +----- ----- -------- -------- ----------------------- ------------- +true false 99 9999 "20140922104920.524789" "Test String" + "+000" +""", ), - None, None, True, ), - + None, None, True + ), ( "Verify print of simple instance to table with col limit", dict( args=([simple_instance2()], 80, 'simple'), kwargs=dict(), - exp_tbl=[ - ["true", "false", "99", '"Test String"']], + exp_stdout="""\ +Instances: CIM_Foo +Pbt Pbf Puint32 Psint32 Pint64 Pdt Pstr1 +----- ----- ---------- ----------- -------- --------- -------- +true false 4294967295 -2147483648 9999 "2014092" "Test " + "2104920" "String" + ".524789" + "+000" +""", ), - None, None, True, ), + None, None, True + ), ( "Verify print of instance with reference property", dict( @@ -2710,38 +2721,51 @@ def test_format_insts_as_rows(testcase, args, kwargs, exp_rtn): k2=32)))])], 80, 'simple'), kwargs=dict(), - exp_tbl=[ - ["/:REF_CLN.k2=32,k1=\"v1\""]], + exp_stdout="""\ +Instances: CIM_Foo +P +--------------------------- +"/:REF_CLN.k1=\\"v1\\",k2=32" +""", ), - None, None, True, ), + None, None, PYWBEM_1_0_0_NON_DEV, + ), ] @pytest.mark.parametrize( "desc, kwargs, exp_exc_types, exp_warn_types, condition", TESTCASES_PRINT_INSTANCE_AS_TABLE) -@simplified_test_function -def test_print_insts_as_table(testcase, args, kwargs, exp_tbl): +def test_print_insts_as_table( + desc, kwargs, exp_exc_types, exp_warn_types, condition, capsys): """ Test the output of the print_insts_as_table function. This primarily tests for overall format and the ability of the function to output to stdout. The previous test tests the row formatting and handling of multiple instances. """ - # TODO fix simplified_test_function so we can use so we capture output. - # capsys in a builtin fixture that must be passed to this function. - # Currently the simplified_test_function does not allow any other - # parameters so we cannot use pytest capsys - mock_echo_func = 'pywbemtools.pywbemcli.click.echo' - with patch(mock_echo_func): - # The code to be tested - _print_instances_as_table(*args, **kwargs) - # stdout, stderr = capsys.readouterr() - # Ensure that exceptions raised in the remainder of this function - # are not mistaken as expected exceptions - assert testcase.exp_exc_types is None + if not condition: + pytest.skip("Testcase condition not satisfied") + + # This logic only supports successful testcases without warnings + assert exp_exc_types is None + assert exp_warn_types is None - # TODO: assert exp_tbl, stdout, testcase.desc + args = kwargs['args'] + kwargs_ = kwargs['kwargs'] + exp_stdout = kwargs['exp_stdout'] + + # The code to be tested + _print_instances_as_table(*args, **kwargs_) + + stdout, stderr = capsys.readouterr() + assert exp_stdout == stdout, \ + "Unexpected output in test case: {}\n" \ + "Actual:\n" \ + "{}\n" \ + "Expected:\n" \ + "{}\n" \ + "End\n".format(desc, stdout, exp_stdout) # TODO Test compare and failure in compare_obj diff --git a/tests/unit/test_error_click.py b/tests/unit/test_error_click.py new file mode 100644 index 000000000..021f6dba3 --- /dev/null +++ b/tests/unit/test_error_click.py @@ -0,0 +1,17 @@ +""" +Temporary module to reproduce error with click.echo() and capsys on Windows +""" + +import click +import pytest # noqa: F401 + + +def myfunc(): + """Function to be tested""" + click.echo('bla') + + +def test_myfunc(capsys): + myfunc() + stdout, stderr = capsys.readouterr() + assert stdout == 'bla\n'