From 428f4ad530c7f8fd3d7e36fadbcc865b796b604f Mon Sep 17 00:00:00 2001 From: Mark Wiebe Date: Fri, 31 Aug 2012 12:18:26 -0700 Subject: [PATCH] Fix debug print test, make it account for some system printf variations --- test_print.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/test_print.py b/test_print.py index fb4a784..510161a 100644 --- a/test_print.py +++ b/test_print.py @@ -37,15 +37,23 @@ def main_debugprint(): class TestPrint(unittest.TestCase): def test_debugprint(self): - p = Popen(["python", __file__, "-child"], stdout=PIPE) + p = Popen([sys.executable, __file__, "-child"], stdout=PIPE) p.wait() - lines = p.stdout.read().decode().splitlines(False) + # The encode(utf-8) is for Python 3 compatibility + lines = p.stdout.read().encode('utf-8').splitlines(False) - expect = [ - 'Show 123 1.234 1.000e-31', - 'an_int = 123 a_float = 1.234000e+00 a_double = 1.000000e-31', - ] + # Try to account for variations in the system printf + if lines[0].find('e-031') >= 0: + expect = [ + 'Show 123 1.234 1.000e-031', + 'an_int = 123 a_float = 1.234000e+000 a_double = 1.000000e-031', + ] + else: + expect = [ + 'Show 123 1.234 1.000e-31', + 'an_int = 123 a_float = 1.234000e+00 a_double = 1.000000e-31', + ] self.assertEqual(expect, lines) p.stdout.close()