Skip to content

Commit 347a97f

Browse files
committed
Update decorators
1 parent 189daf3 commit 347a97f

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

seleniumbase/common/decorators.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
1+
import colorama
12
import logging
23
import math
4+
import sys
35
import time
46
import warnings
57
from contextlib import contextmanager
68
from functools import wraps
79
from seleniumbase.common.exceptions import TimeoutException
810

11+
c1 = colorama.Fore.BLUE + colorama.Back.LIGHTYELLOW_EX
12+
cr = colorama.Style.RESET_ALL
13+
if "linux" in sys.platform:
14+
c1 = cr = ""
15+
916

1017
@contextmanager
1118
def print_runtime(description=None, limit=None):
@@ -44,19 +51,20 @@ def my_method():
4451
end_time = time.time()
4552
run_time = end_time - start_time
4653
name = description
54+
info = c1 + "<info>" + cr
4755
# Print times with a statistically significant number of decimal places
4856
if run_time < 0.0001:
49-
print("<info> - {%s} ran for %.7f seconds." % (name, run_time))
57+
print("%s - {%s} ran for %.7f seconds." % (info, name, run_time))
5058
elif run_time < 0.001:
51-
print("<info> - {%s} ran for %.6f seconds." % (name, run_time))
59+
print("%s - {%s} ran for %.6f seconds." % (info, name, run_time))
5260
elif run_time < 0.01:
53-
print("<info> - {%s} ran for %.5f seconds." % (name, run_time))
61+
print("%s - {%s} ran for %.5f seconds." % (info, name, run_time))
5462
elif run_time < 0.1:
55-
print("<info> - {%s} ran for %.4f seconds." % (name, run_time))
63+
print("%s - {%s} ran for %.4f seconds." % (info, name, run_time))
5664
elif run_time < 1:
57-
print("<info> - {%s} ran for %.3f seconds." % (name, run_time))
65+
print("%s - {%s} ran for %.3f seconds." % (info, name, run_time))
5866
else:
59-
print("<info> - {%s} ran for %.2f seconds." % (name, run_time))
67+
print("%s - {%s} ran for %.2f seconds." % (info, name, run_time))
6068
if limit and limit > 0 and run_time > limit:
6169
message = (
6270
"\n {%s} duration of %.2fs exceeded the time limit of %.2fs!"

0 commit comments

Comments
 (0)