mirror of
https://github.com/cool-RR/PySnooper.git
synced 2026-01-23 10:15:11 +00:00
Test arbitrary expression evaluation.
This commit is contained in:
parent
e97cdd2b6c
commit
c9a51de674
2 changed files with 14 additions and 7 deletions
|
|
@ -52,7 +52,11 @@ def test_variables():
|
|||
def square(self):
|
||||
self.x **= 2
|
||||
|
||||
@pysnooper.snoop(variables=('foo.x', 'io'))
|
||||
@pysnooper.snoop(variables=(
|
||||
'foo.x',
|
||||
'io.__name__',
|
||||
'len(foo.__dict__["x"] * "abc")',
|
||||
))
|
||||
def my_function():
|
||||
foo = Foo()
|
||||
for i in range(2):
|
||||
|
|
@ -66,20 +70,23 @@ def test_variables():
|
|||
assert_output(
|
||||
output,
|
||||
(
|
||||
VariableEntry(),
|
||||
VariableEntry(),
|
||||
VariableEntry('Foo'),
|
||||
VariableEntry('io.__name__', 'io'),
|
||||
CallEntry('def my_function():'),
|
||||
LineEntry('foo = Foo()'),
|
||||
VariableEntry(),
|
||||
VariableEntry(),
|
||||
VariableEntry('foo'),
|
||||
VariableEntry('foo.x', '2'),
|
||||
VariableEntry('len(foo.__dict__["x"] * "abc")', 6),
|
||||
LineEntry(),
|
||||
VariableEntry('i', '0'),
|
||||
LineEntry(),
|
||||
VariableEntry('foo.x', '4'),
|
||||
VariableEntry('len(foo.__dict__["x"] * "abc")', 12),
|
||||
LineEntry(),
|
||||
VariableEntry('i', '1'),
|
||||
LineEntry(),
|
||||
VariableEntry('foo.x', '16'),
|
||||
VariableEntry('len(foo.__dict__["x"] * "abc")', 48),
|
||||
LineEntry(),
|
||||
ReturnEntry(),
|
||||
ReturnValueEntry('None')
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ class VariableEntry(_BaseValueEntry):
|
|||
return self._check_stage(stage)
|
||||
|
||||
_content_pattern = re.compile(
|
||||
r"""^(?P<name>[^ ]+) = (?P<value>.+)$"""
|
||||
r"""^(?P<name>.+?) = (?P<value>.+)$"""
|
||||
)
|
||||
|
||||
def _check_content(self, content):
|
||||
|
|
@ -120,7 +120,7 @@ class VariableEntry(_BaseValueEntry):
|
|||
|
||||
def _check_value(self, value):
|
||||
if self.value is not None:
|
||||
return value == self.value
|
||||
return value == str(self.value)
|
||||
elif self.value_regex is not None:
|
||||
return self.value_regex.match(value)
|
||||
else:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue