Skip to content

Commit

Permalink
Merge 22a07d8 into c1c427d
Browse files Browse the repository at this point in the history
  • Loading branch information
andy-maier committed Jun 17, 2020
2 parents c1c427d + 22a07d8 commit cff244d
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 42 deletions.
12 changes: 6 additions & 6 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
6 changes: 5 additions & 1 deletion pywbemtools/pywbemcli/_cimvalueformatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ pywbem>=0.17.0

six>=1.10.0
# Click 7.1 has a bug with output capturing
Click>=7.0,!=7.1
# Click>=7.0,!=7.1
git+https://github.com/andy-maier/click.git@andy/fix-unsupportedoperation#egg=Click
click-spinner>=0.1.8
click-repl>=0.1.6
asciitree>=0.3.3
Expand Down
92 changes: 58 additions & 34 deletions tests/unit/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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(
Expand All @@ -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
Expand Down
17 changes: 17 additions & 0 deletions tests/unit/test_error_click.py
Original file line number Diff line number Diff line change
@@ -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'

0 comments on commit cff244d

Please sign in to comment.