Repository: radiasoft/pykern

Issue:
pkre should implement its doc:  actual (object): run-time value
`actual` should be converted to a string. pkcompat should be used for bytes.

Discussion:

Patch:
diff --git a/pykern/pkunit.py b/pykern/pkunit.py
index ad6f94b..6a0ad99 100644
--- a/pykern/pkunit.py
+++ b/pykern/pkunit.py
@@ -6,6 +6,7 @@ u"""Useful operations for unit tests
 """
 from __future__ import absolute_import, division, print_function
 from pykern import pkcollections
+from pykern import pkcompat
 from pykern import pkinspect
 from pykern import pkio
 # defer importing pkconfig
@@ -351,7 +352,7 @@ def pkre(expect_re, actual, flags=re.IGNORECASE + re.DOTALL):
         actual (object): run-time value
         flags: passed on to re.search [IGNORECASE + DOTALL]
     """
-    if not re.search(expect_re, actual, flags=flags):
+    if not re.search(expect_re, pkcompat.from_bytes(actual), flags=flags):
         pkfail('expect_re={} != actual={}', expect_re, actual)
 
 


Test patch:
diff --git a/tests/pkunit_test.py b/tests/pkunit_test.py
index 4c8f078..31acebb 100644
--- a/tests/pkunit_test.py
+++ b/tests/pkunit_test.py
@@ -127,6 +127,13 @@ def test_pkok():
         assert 'pkunit_test.py:{}:test_pkok xyzzy 333 abc'.format(lineno) in str(e.args)
 
 
+def test_pkre_convert():
+    from pykern.pkunit import pkre
+    r = r'A'
+    for s in ('A', b'A', r'A', u'A'):
+        pkre(r, s)
+
+
 def _expect(base):
     import py.path