File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change 20
20
from collections import defaultdict
21
21
import functools
22
22
import math
23
+ import os
23
24
import sys
24
25
import threading
25
26
import time
@@ -190,6 +191,9 @@ def random_func_name():
190
191
If a name is passed, returns this as a decorator, otherwise returns the
191
192
decorated function.
192
193
"""
194
+ if os .environ .get ("SC2_NO_STOPWATCH" ):
195
+ return name_or_func if callable (name_or_func ) else lambda func : func
196
+
193
197
def decorator (name , func ):
194
198
@functools .wraps (func )
195
199
def _stopwatch (* args , ** kwargs ):
@@ -236,6 +240,7 @@ def merge(self, other):
236
240
237
241
@staticmethod
238
242
def parse (s ):
243
+ """Parse the output below to create a new StopWatch."""
239
244
stopwatch = StopWatch ()
240
245
for line in s .splitlines ():
241
246
if line .strip ():
Original file line number Diff line number Diff line change 18
18
from __future__ import division
19
19
from __future__ import print_function
20
20
21
+ import os
22
+
21
23
from absl .testing import absltest
22
24
from future .builtins import range # pylint: disable=redefined-builtin
23
25
@@ -103,6 +105,18 @@ def testDivideZero(self):
103
105
# Just make sure this doesn't have a divide by 0 for when the total is 0.
104
106
self .assertIn ("zero" , str (sw ))
105
107
108
+ @mock .patch .dict (os .environ , {"SC2_NO_STOPWATCH" : "1" })
109
+ def testDecoratorDisabled (self ):
110
+ sw = stopwatch .StopWatch ()
111
+ self .assertEqual (round , sw .decorate (round ))
112
+ self .assertEqual (round , sw .decorate ("name" )(round ))
113
+
114
+ @mock .patch .dict (os .environ , {"SC2_NO_STOPWATCH" : "" })
115
+ def testDecoratorEnabled (self ):
116
+ sw = stopwatch .StopWatch ()
117
+ self .assertNotEqual (round , sw .decorate (round ))
118
+ self .assertNotEqual (round , sw .decorate ("name" )(round ))
119
+
106
120
def testSpeed (self ):
107
121
count = 1000
108
122
You can’t perform that action at this time.
0 commit comments