Created
October 21, 2016 15:07
-
-
Save tbielawa/7ad844e9f440661c21728a9291548277 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This file is what you're importing from when you do 'from ooinstall.utils import debug_env' | |
import logging | |
installer_log = logging.getLogger('installer') | |
def debug_env(env): | |
for k in sorted(env.keys()): | |
if k.startswith("OPENSHIFT") or k.startswith("ANSIBLE") or k.startswith("OO"): | |
print("Debugging key: %s" % k) | |
installer_log.debug("{key}: {value}".format( | |
key=k, value=env[k])) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Verify debug_env debugs specific env variables ... FAIL | |
====================================================================== | |
FAIL: Verify debug_env debugs specific env variables | |
---------------------------------------------------------------------- | |
Traceback (most recent call last): | |
File "/home/tbielawa/rhat/os/openshift-ansible/utils/test/test_utils.py", line 32, in test_utils_debug_env_all_debugged | |
logger.debug.assert_called_once() | |
File "/home/tbielawa/rhat/os/openshift-ansible/utils/oo-installenv/lib/python2.7/site-packages/mock/mock.py", line 915, in assert_called_once | |
raise AssertionError(msg) | |
AssertionError: Expected 'debug' to have been called once. Called 0 times. | |
-------------------- >> begin captured stdout << --------------------- | |
Debugging key: ANSIBLE_FOO | |
Debugging key: OO_FOO | |
Debugging key: OPENSHIFT_FOO | |
--------------------- >> end captured stdout << ---------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Unittests. | |
""" | |
import unittest | |
# replace inline func def w/ import | |
from ooinstall.utils import debug_env | |
import mock | |
import logging | |
class TestUtils(unittest.TestCase): | |
""" | |
Parent unittest TestCase. | |
""" | |
def setUp(self): | |
self.debug_all_params = { | |
'OPENSHIFT_FOO': 'bar', | |
'ANSIBLE_FOO': 'bar', | |
'OO_FOO': 'bar' | |
} | |
def test_utils_debug_env_all_debugged(self): | |
"""Verify debug_env debugs specific env variables""" | |
with mock.patch('logging.getLogger') as _gl: | |
logger = mock.MagicMock(logging.Logger) | |
_gl.return_value = logger | |
debug_env(self.debug_all_params) | |
# | |
logger.debug.assert_called_once() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment