MCPcopy
hub / github.com/cool-RR/PySnooper / VariableEntry

Class VariableEntry

tests/utils.py:135–199  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

133
134
135class VariableEntry(_BaseValueEntry):
136 def __init__(self, name=None, value=None, stage=None, prefix='',
137 name_regex=None, value_regex=None, min_python_version=None,
138 max_python_version=None):
139 _BaseValueEntry.__init__(self, prefix=prefix,
140 min_python_version=min_python_version,
141 max_python_version=max_python_version)
142 if name is not None:
143 assert name_regex is None
144 if value is not None:
145 assert value_regex is None
146 assert stage in (None, 'starting', 'new', 'modified')
147
148 self.name = name
149 self.value = value
150 self.stage = stage
151 self.name_regex = (None if name_regex is None else
152 re.compile(name_regex))
153 self.value_regex = (None if value_regex is None else
154 re.compile(value_regex))
155
156 _preamble_pattern = re.compile(
157 r"""^(?P<stage>New|Modified|Starting) var$"""
158 )
159
160 def _check_preamble(self, preamble):
161 match = self._preamble_pattern.match(preamble)
162 if not match:
163 return False
164 stage = match.group('stage')
165 return self._check_stage(stage)
166
167 _content_pattern = re.compile(
168 r"""^(?P<name>.+?) = (?P<value>.+)$"""
169 )
170
171 def _check_content(self, content):
172 match = self._content_pattern.match(content)
173 if not match:
174 return False
175 name, value = match.groups()
176 return self._check_name(name) and self._check_value(value)
177
178 def _check_name(self, name):
179 if self.name is not None:
180 return name == self.name
181 elif self.name_regex is not None:
182 return self.name_regex.match(name)
183 else:
184 return True
185
186 def _check_value(self, value):
187 if self.value is not None:
188 return value == self.value
189 elif self.value_regex is not None:
190 return self.value_regex.match(value)
191 else:
192 return True

Callers 15

test_string_ioFunction · 0.85
test_relative_timeFunction · 0.85
test_thread_infoFunction · 0.85
test_multi_thread_infoFunction · 0.85
test_callableFunction · 0.85
test_watchFunction · 0.85
test_watch_explodeFunction · 0.85
test_variables_classesFunction · 0.85
test_long_variableFunction · 0.85

Calls

no outgoing calls

Tested by 15

test_string_ioFunction · 0.68
test_relative_timeFunction · 0.68
test_thread_infoFunction · 0.68
test_multi_thread_infoFunction · 0.68
test_callableFunction · 0.68
test_watchFunction · 0.68
test_watch_explodeFunction · 0.68
test_variables_classesFunction · 0.68
test_long_variableFunction · 0.68