Patchwork run-tests: pre instantiate pygments objects

login
register
mail settings
Submitter Matthieu Laneuville
Date Aug. 22, 2017, 9:29 a.m.
Message ID <8f0443200c166b82d420.1503394149@carbon>
Download mbox | patch
Permalink /patch/23201/
State Accepted
Headers show

Comments

Matthieu Laneuville - Aug. 22, 2017, 9:29 a.m.
# HG changeset patch
# User Matthieu Laneuville <matthieu.laneuville@octobus.net>
# Date 1503392400 -7200
#      Tue Aug 22 11:00:00 2017 +0200
# Node ID 8f0443200c166b82d42078362d6908f73c7fb58a
# Parent  3cfc9070245fbaa8c4c010327f24d579a416370f
run-tests: pre instantiate pygments objects

Pre instantiate pygments objects to minimize overhead (cf. 20436925e080)
Yuya Nishihara - Aug. 22, 2017, 2:39 p.m.
On Tue, 22 Aug 2017 11:29:09 +0200, mlaneuville@gmail.com wrote:
> # HG changeset patch
> # User Matthieu Laneuville <matthieu.laneuville@octobus.net>
> # Date 1503392400 -7200
> #      Tue Aug 22 11:00:00 2017 +0200
> # Node ID 8f0443200c166b82d42078362d6908f73c7fb58a
> # Parent  3cfc9070245fbaa8c4c010327f24d579a416370f
> run-tests: pre instantiate pygments objects

Queued, thanks.

Patch

diff -r 3cfc9070245f -r 8f0443200c16 tests/run-tests.py
--- a/tests/run-tests.py	Wed Aug 16 10:44: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))