summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrant Knudson <bknudson@us.ibm.com>2016-01-19 15:28:46 -0600
committerBrant Knudson <bknudson@us.ibm.com>2016-01-19 15:42:58 -0600
commit68d55698549511094612b7206dc2456701aaf087 (patch)
treec5ddfb261c0999afb86192a91371409e8ef90a57
parentf76a96fedcf7abb155b92fdcb401abe0d92eadba (diff)
downloadoslo-utils-68d55698549511094612b7206dc2456701aaf087.tar.gz
Fix coverage
The coverage job was failing because the test code was faking sys.getfilesystemencoding to return a value that didn't work when it was called later by coverage. Change-Id: Iffeebde4a3cb7c59e69c4c3e23ff4e02461169b6
-rw-r--r--oslo_utils/tests/tests_encodeutils.py18
1 files changed, 16 insertions, 2 deletions
diff --git a/oslo_utils/tests/tests_encodeutils.py b/oslo_utils/tests/tests_encodeutils.py
index 84cbd49..984ebc3 100644
--- a/oslo_utils/tests/tests_encodeutils.py
+++ b/oslo_utils/tests/tests_encodeutils.py
@@ -15,6 +15,8 @@
# License for the specific language governing permissions and limitations
# under the License.
+import sys
+
import mock
from oslotest import base as test_base
import six
@@ -121,6 +123,18 @@ class ExceptionToUnicodeTest(test_base.BaseTestCase):
def __str__(self):
return self.value
+ def mock_getfilesystemencoding(test_value):
+ # NOTE(blk-u): sys.getfilesystemencoding is called by coverage
+ # while processing the functions/files called by the test so
+ # mocking getfilesystemencoding was causing the coverage job to
+ # fail since it doesn't know about koi8_r encoding, and the
+ # encoding might be incorrect when set in other cases. The
+ # workaround is to return the test value when it's called by
+ # oslo.utils and the original value when called later by coverage.
+ return mock.patch.object(
+ sys, 'getfilesystemencoding',
+ side_effect=[test_value, sys.getfilesystemencoding()])
+
# On Python 3, an exception which returns bytes with is __str__()
# method (like StrException(bytes)) is probably a bug, but it was not
# harder to support this silly case in exception_to_unicode().
@@ -136,7 +150,7 @@ class ExceptionToUnicodeTest(test_base.BaseTestCase):
u'utf-8 \xe9\u20ac')
# Force the locale encoding to ASCII to test the fallback
- with mock.patch('sys.getfilesystemencoding', return_value='ascii'):
+ with mock_getfilesystemencoding('ascii'):
# Fallback: decode from ISO-8859-1
exc = StrException(b'rawbytes \x80\xff')
self.assertEqual(encodeutils.exception_to_unicode(exc),
@@ -153,7 +167,7 @@ class ExceptionToUnicodeTest(test_base.BaseTestCase):
u'unicode \xe9\u20ac')
# Test the locale encoding
- with mock.patch('sys.getfilesystemencoding', return_value='koi8_r'):
+ with mock_getfilesystemencoding('koi8_r'):
exc = StrException(b'\xf2\xd5\xd3\xd3\xcb\xc9\xca')
# Decode from the locale encoding
# (the message cannot be decoded from ASCII nor UTF-8)