summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEli Bendersky <eliben@gmail.com>2023-01-07 08:50:39 -0800
committerEli Bendersky <eliben@gmail.com>2023-01-07 08:50:39 -0800
commit4fffa23c4efeaf1a84694fb398eafd1766d70a1b (patch)
tree5b5cb0e84dcd5fa7cb74ae07299eb3b47757f269
parent85a40529d4fda2e4eb59c9bd619aabe2f55851e3 (diff)
downloadpycparser-4fffa23c4efeaf1a84694fb398eafd1766d70a1b.tar.gz
Update test_examples.py to use subTest now that we have modern Pythons
simplify it to use f-strings while we're at it
-rw-r--r--tests/test_examples.py20
1 files changed, 5 insertions, 15 deletions
diff --git a/tests/test_examples.py b/tests/test_examples.py
index 7fb2ad3..b6f36db 100644
--- a/tests/test_examples.py
+++ b/tests/test_examples.py
@@ -6,8 +6,6 @@ import unittest
sys.path.insert(0, '.')
from tests.test_util import run_exe, cpp_supported
-EMIT_ELAPSED_TIME = False
-
# Runs all pycparser examples with no command-line arguments and makes sure they
# run successfully (return code = 0), without actually verifying their output.
class TestExamplesSucceed(unittest.TestCase):
@@ -16,19 +14,11 @@ class TestExamplesSucceed(unittest.TestCase):
root = './examples'
for filename in os.listdir(root):
if os.path.splitext(filename)[1] == '.py':
- # TODO: It would be nice to use subTest here, but that's not
- # available in Python 2.7
- # Use it when we finally drop Python 2...
- path = os.path.join(root, filename)
- t1 = time.time()
- rc, stdout, stderr = run_exe(path)
- elapsed = time.time() - t1
- if EMIT_ELAPSED_TIME:
- print('{}... elapsed: {}'.format(filename, elapsed))
- self.assertEqual(
- rc, 0, 'example "{}" failed with stdout =\n{}\nstderr =\n{}'.format(filename, stdout, stderr))
-
+ with self.subTest(name=filename):
+ path = os.path.join(root, filename)
+ rc, stdout, stderr = run_exe(path)
+ self.assertEqual(
+ rc, 0, f'example "{filename}" failed with stdout =\n{stdout}\nstderr =\n{stderr}')
if __name__ == '__main__':
- EMIT_ELAPSED_TIME = True
unittest.main()