|
| 1 | +import colorama |
1 | 2 | import logging |
2 | 3 | import math |
| 4 | +import sys |
3 | 5 | import time |
4 | 6 | import warnings |
5 | 7 | from contextlib import contextmanager |
6 | 8 | from functools import wraps |
7 | 9 | from seleniumbase.common.exceptions import TimeoutException |
8 | 10 |
|
| 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 | + |
9 | 16 |
|
10 | 17 | @contextmanager |
11 | 18 | def print_runtime(description=None, limit=None): |
@@ -44,19 +51,20 @@ def my_method(): |
44 | 51 | end_time = time.time() |
45 | 52 | run_time = end_time - start_time |
46 | 53 | name = description |
| 54 | + info = c1 + "<info>" + cr |
47 | 55 | # Print times with a statistically significant number of decimal places |
48 | 56 | 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)) |
50 | 58 | 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)) |
52 | 60 | 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)) |
54 | 62 | 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)) |
56 | 64 | 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)) |
58 | 66 | else: |
59 | | - print("<info> - {%s} ran for %.2f seconds." % (name, run_time)) |
| 67 | + print("%s - {%s} ran for %.2f seconds." % (info, name, run_time)) |
60 | 68 | if limit and limit > 0 and run_time > limit: |
61 | 69 | message = ( |
62 | 70 | "\n {%s} duration of %.2fs exceeded the time limit of %.2fs!" |
|
0 commit comments