run-tests: pre instantiate pygments objects
authorMatthieu Laneuville <matthieu.laneuville@octobus.net>
Tue, 22 Aug 2017 11:00:00 +0200
changeset 33866 4e8a46c25fac
parent 33865 af20468eb0a4
child 33867 252fb66ee5bb
run-tests: pre instantiate pygments objects Pre instantiate pygments objects to minimize overhead (cf. 20436925e080)
tests/run-tests.py
--- a/tests/run-tests.py	Mon Aug 21 21:35:06 2017 -0700
+++ b/tests/run-tests.py	Tue Aug 22 11:00:00 2017 +0200
@@ -136,6 +136,9 @@
             ]
         }
 
+    runnerformatter = formatters.Terminal256Formatter(style=TestRunnerStyle)
+    runnerlexer = TestRunnerLexer()
+
 if sys.version_info > (3, 5, 0):
     PYTHON3 = True
     xrange = range # we use xrange in one place, and we'd rather not use range
@@ -1637,9 +1640,8 @@
                         if self.color:
                             formatted = pygments.highlight(
                                 formatted,
-                                TestRunnerLexer(),
-                                formatters.Terminal256Formatter(
-                                            style=TestRunnerStyle))
+                                runnerlexer,
+                                runnerformatter)
                         self.stream.write(formatted)
                     self.stream.write('!')
 
@@ -2046,18 +2048,16 @@
                     if result.color:
                         formatted = pygments.highlight(
                             formatted,
-                            TestRunnerLexer(),
-                            formatters.Terminal256Formatter(
-                                            style=TestRunnerStyle)).strip("\n")
+                            runnerlexer,
+                            runnerformatter).strip("\n")
                     self.stream.writeln(formatted)
             for test, msg in result.failures:
                 formatted = 'Failed %s: %s' % (test.name, msg)
                 if result.color:
                     formatted = pygments.highlight(
                         formatted,
-                        TestRunnerLexer(),
-                        formatters.Terminal256Formatter(
-                                        style=TestRunnerStyle)).strip("\n")
+                        runnerlexer,
+                        runnerformatter).strip("\n")
                 self.stream.writeln(formatted)
             for test, msg in result.errors:
                 self.stream.writeln('Errored %s: %s' % (test.name, msg))