Rename relative_time to elapsed_time

This commit is contained in:
iory 2020-04-17 22:04:45 +09:00 committed by Ram Rachum
parent 73c2816121
commit d94b0214f9
3 changed files with 14 additions and 10 deletions

View File

@ -72,12 +72,12 @@ Or if you don't want to trace an entire function, you can wrap the relevant part
import pysnooper
import random
def foo(relative_time=False):
def foo(elapsed_time=False):
lst = []
for i in range(10):
lst.append(random.randrange(1, 1000))
with pysnooper.snoop(relative_time=relative_time):
with pysnooper.snoop(elapsed_time=elapsed_time):
lower = min(lst)
upper = max(lst)
mid = (lower + upper) / 2
@ -102,18 +102,18 @@ New var:....... mid = 453.0
Total elapsed time: 00:00:00.000344
```
If `relative_time` is `True`, print time format will be relative.
If `elapsed_time` is `True`, print elapsed time format.
```python
import pysnooper
import random
def foo(relative_time=False):
def foo(elapsed_time=False):
lst = []
for i in range(10):
lst.append(random.randrange(1, 1000))
with pysnooper.snoop(relative_time=relative_time):
with pysnooper.snoop(elapsed_time=elapsed_time):
lower = min(lst)
upper = max(lst)
mid = (lower + upper) / 2

View File

@ -198,11 +198,15 @@ class Tracer:
You can also use `max_variable_length=None` to never truncate them.
Print time in elapsed time format::
@pysnooper.snoop(elapsed_time=True)
'''
def __init__(self, output=None, watch=(), watch_explode=(), depth=1,
prefix='', overwrite=False, thread_info=False, custom_repr=(),
max_variable_length=100, normalize=False,
relative_time=False):
elapsed_time=False):
self._write = get_write_function(output, overwrite)
self.watch = [
@ -228,7 +232,7 @@ class Tracer:
self.last_source_path = None
self.max_variable_length = max_variable_length
self.normalize = normalize
self.relative_time = relative_time
self.elapsed_time = elapsed_time
def __call__(self, function_or_class):
if DISABLED:
@ -359,7 +363,7 @@ class Tracer:
# #
### Finished checking whether we should trace this line. ##############
if self.relative_time:
if self.elapsed_time:
duration = datetime_module.datetime.now() - self.start_time
now_string = pycompat.timedelta_isoformat(
duration, timespec='microseconds') if not self.normalize else ' ' * 15

View File

@ -50,10 +50,10 @@ def test_string_io():
)
def test_relative_time():
def test_elapsed_time():
string_io = io.StringIO()
@pysnooper.snoop(string_io, relative_time=True)
@pysnooper.snoop(string_io, elapsed_time=True)
def my_function(foo):
x = 7
y = 8