Skip to content

Commit

Permalink
Correct bash execution call for windows so that test_wbemcli.py
Browse files Browse the repository at this point in the history
executes correctly in both windows and linux.
Change test_logging.py to use the LogCapture package instead of trying
to work with log files. Eliminates problem with windows and
deleting log files.

Correct slashes on test_wbemcli.py file name for windows back to
linux slashes. They are created on windows but we are executing the
script in cygwin.
  • Loading branch information
KSchopmeyer committed Jul 19, 2017
1 parent 6d74173 commit aa4d16f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 33 deletions.
6 changes: 3 additions & 3 deletions pywbem/_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,9 @@ def create_logger(cls, log_component, log_dest='stderr',
# create named logger
if handler:
handler.setFormatter(logging.Formatter(format_string))
logger_ops = logging.getLogger(logger_name)
logger_ops.addHandler(handler)
logger_ops.setLevel(level)
logger = logging.getLogger(logger_name)
logger.addHandler(handler)
logger.setLevel(level)

# save the detail level in the dict that is part of this class.
# All members of this tuple are just viewing except detail
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ def run(self):
"coverage>=4.3",
"pytest>=2.4",
"pytest-cov",
'testfixtures>=4.13.3',
"Sphinx>=1.3" if sys.version_info[0:2] != (2, 6) else None,
# Pinning GitPython to 2.0.8 max, due to its use of unittest.case
# which is not available on Python 2.6.
Expand Down
29 changes: 13 additions & 16 deletions testsuite/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
# pylint: disable=invalid-name,missing-docstring,too-many-statements
# pylint: disable=too-many-lines,no-self-use
import unittest
from testfixtures import LogCapture, log_capture

from pywbem import PywbemLoggers, LOG_OPS_CALLS_NAME
from pywbem._logging import get_logger
Expand All @@ -43,21 +44,12 @@

class BaseLoggingTests(unittest.TestCase):
"""Base class for logging unit tests"""

def setUp(self):
PywbemLoggers.reset()
if os.path.isfile(TEST_OUTPUT_LOG):
os.remove(TEST_OUTPUT_LOG)

def tearDown(self):
if os.path.isfile(TEST_OUTPUT_LOG):
os.remove(TEST_OUTPUT_LOG)

def loadLogfile(self):
if os.path.isfile(TEST_OUTPUT_LOG):
with open(TEST_OUTPUT_LOG) as f:
lines = f.read().splitlines()
return lines
return None
LogCapture.uninstall_all()


class TestLogParse(BaseLoggingTests):
Expand Down Expand Up @@ -171,7 +163,9 @@ def test_create_single_logger2(self):
expected_result = \
{'pywbem.http': ('min', 'debug', 'file', TEST_OUTPUT_LOG)}

self.assertEqual(PywbemLoggers.loggers, expected_result)
self.assertEqual(PywbemLoggers.loggers, expected_result,
'Actual %s, Expected %s' % (PywbemLoggers.loggers,
expected_result))

def test_create_single_logger3(self):
"""
Expand All @@ -187,7 +181,9 @@ def test_create_single_logger3(self):
expected_result = \
{'pywbem.http': ('min', 'debug', 'stderr', None)}

self.assertEqual(PywbemLoggers.loggers, expected_result)
self.assertEqual(PywbemLoggers.loggers, expected_result,
'Actual %s, Expected %s' % (PywbemLoggers.loggers,
expected_result))

def test_create_single_logger4(self):
"""
Expand Down Expand Up @@ -335,7 +331,8 @@ def test_create_loggers2(self):
class TestLoggerOutput(BaseLoggingTests):
"""Test output from logging"""

def test_log_output(self):
@log_capture()
def test_log_output(self, l):
test_input = 'all=file:all:debug'

print('log filename %s' % TEST_OUTPUT_LOG)
Expand All @@ -359,8 +356,8 @@ def test_log_output(self):

my_logger.debug('%s: %s: %s', return_name, 'FakeMethodName', result)

logged_data = self.loadLogfile()
print('Log file contents:\n%s' % logged_data)
l.check(('pywbem.ops', 'DEBUG',
"Return: FakeMethodName: 'This is fake return data'"))


if __name__ == '__main__':
Expand Down
28 changes: 14 additions & 14 deletions testsuite/test_wbemcli.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,25 +111,27 @@ def test(self): # pylint: disable=missing-docstring
""" The test method that is generated."""
term_script_file = os.path.join(SCRIPT_DIR,
'wbemcli_quit_script.py')

term_script_file = term_script_file.replace('\\', '/')
term_script_param = '-s %s' % term_script_file

command = ('wbemcli http://blah %s %s' %
(test_params.cmd, term_script_param))
scr_name = 'wbemcli.bat' if os.name == 'nt' else 'wbemcli'

cmd = ('%s http://blah %s %s' % (scr_name, test_params.cmd,
term_script_param))
# Disable python warnings for wbemcli call
# because some imports generate deprecated warnings
# that appear in std_err when nothing expected
if os.name == 'nt':
pywarn = 'set PYTHONWARNINGS= &'
else:
pywarn = 'export PYTHONWARNINGS= "" &&'

command = '%s %s' % (pywarn, command)
proc = Popen(command, shell=True, stdout=PIPE, stderr=PIPE)
bash_cmd = 'bash -c "set -o pipefail; PYTHONPATH=. ' \
'PYTHONWARNINGS= %s"' % cmd

proc = Popen(bash_cmd, shell=True, stdout=PIPE, stderr=PIPE)
std_out, std_err = proc.communicate()
exitcode = proc.returncode
print('exitcode %s std_out:\n%s\nstd_err:\n%s' % (exitcode,
std_out,
std_err))
# print('bash_cmd: %s\nexitcode: %s std_out:\n%s\nstd_err:'
# '\n%s' % (bash_cmd, exitcode, std_out, std_err))

if six.PY3:
std_out = std_out.decode()
std_err = std_err.decode()
Expand All @@ -140,12 +142,10 @@ def test(self): # pylint: disable=missing-docstring
'Expected %s: cmd="%s": '
'exitcode %s: stderr=%s' %
(test_name, test_params.expected_exitcode,
command,
cmd,
exitcode, std_err)))

if test_params.expected_stderr is None:
print('searchresult %s' % re.search('ImportWarning',
std_err))
if re.search('ImportWarning', std_err) is None:
self.assertEqual(std_err, "",
'Test %s stderr not empty as '
Expand Down

0 comments on commit aa4d16f

Please sign in to comment.