pytest-regtest 2.0.2__tar.gz → 2.0.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pytest-regtest
3
- Version: 2.0.2
3
+ Version: 2.0.3
4
4
  Summary: "pytest plugin for snapshot regression testing"
5
5
  Author: Uwe Schmitt
6
6
  Author-email: uwe.schmitt@id.ethz.ch
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pytest-regtest
3
- Version: 2.0.2
3
+ Version: 2.0.3
4
4
  Summary: "pytest plugin for snapshot regression testing"
5
5
  Author: Uwe Schmitt
6
6
  Author-email: uwe.schmitt@id.ethz.ch
@@ -1,4 +1,6 @@
1
1
  import difflib
2
+ import functools
3
+ import inspect
2
4
  import os
3
5
  import re
4
6
  import sys
@@ -250,7 +252,7 @@ class RegtestStream:
250
252
  def write(self, what):
251
253
  self.buffer.write(what)
252
254
 
253
- def flush(self, true):
255
+ def flush(self):
254
256
  pass
255
257
 
256
258
  def get_lines(self):
@@ -303,13 +305,29 @@ _converters_pre = []
303
305
  _converters_post = []
304
306
 
305
307
 
308
+ def _fix_pre_v2_converter_function(function):
309
+ @functools.wraps(function)
310
+ def fixed_converter_function(output, request):
311
+ return function(output)
312
+
313
+ return fixed_converter_function
314
+
315
+
306
316
  def register_converter_pre(function):
307
317
  if function not in _converters_pre:
318
+ signature = inspect.signature(function)
319
+ # keep downward compatibility:
320
+ if len(signature.parameters) == 1:
321
+ function = _fix_pre_v2_converter_function(function)
308
322
  _converters_pre.append(function)
309
323
 
310
324
 
311
325
  def register_converter_post(function):
312
326
  if function not in _converters_post:
327
+ signature = inspect.signature(function)
328
+ # keep downward compatibility:
329
+ if len(signature.parameters) == 1:
330
+ function = _fix_pre_v2_converter_function(function)
313
331
  _converters_post.append(function)
314
332
 
315
333
 
@@ -1,6 +1,6 @@
1
1
  [metadata]
2
2
  name = pytest-regtest
3
- version = 2.0.2
3
+ version = 2.0.3
4
4
  license = MIT
5
5
  description = "pytest plugin for snapshot regression testing"
6
6
  long_description = file: README.md
@@ -19,6 +19,7 @@ def create_test_regtest_context_manager(testdir):
19
19
  print(tempfile.gettempdir())
20
20
  print(tempfile.mkdtemp())
21
21
  print("obj id is", hex(id(tempfile)))
22
+ regtest.flush()
22
23
 
23
24
  """
24
25
  )
@@ -39,6 +40,7 @@ def create_test_regtest_fh(testdir):
39
40
  print(tempfile.gettempdir(), file=regtest)
40
41
  print(tempfile.mkdtemp(), file=regtest)
41
42
  print("obj id is", hex(id(tempfile)), file=regtest)
43
+ regtest.flush()
42
44
 
43
45
  """
44
46
  )
@@ -149,6 +151,42 @@ def test_failed_test(testdir):
149
151
  result.assert_outcomes(failed=1)
150
152
 
151
153
 
154
+ def test_converter_pre_pre_v2(testdir):
155
+ testdir.makepyfile(
156
+ """
157
+ import tempfile
158
+ from pytest_regtest import register_converter_pre
159
+
160
+ @register_converter_pre
161
+ def to_upper_conv(line):
162
+ return line.upper()
163
+
164
+ def test_regtest(regtest_all, tmpdir):
165
+ print("this is expected outcome")
166
+ print("obj id is 0xabcdeffff")
167
+ """
168
+ )
169
+ result = testdir.runpytest_subprocess()
170
+ result.assert_outcomes(failed=1)
171
+
172
+ expected_diff = """
173
+ > --- is
174
+ > +++ tobe
175
+ > @@ -1,2 +0,0 @@
176
+ > -THIS IS EXPECTED OUTCOME
177
+ > -OBJ ID IS 0XABCDEFFFF
178
+ """.strip().split(
179
+ "\n"
180
+ )
181
+
182
+ result.stdout.fnmatch_lines(
183
+ [line.lstrip() for line in expected_diff], consecutive=True
184
+ )
185
+
186
+ result = testdir.runpytest("--regtest-reset")
187
+ result.assert_outcomes(passed=1)
188
+
189
+
152
190
  def test_converter_pre(testdir):
153
191
  testdir.makepyfile(
154
192
  """
@@ -185,6 +223,48 @@ def test_converter_pre(testdir):
185
223
  result.assert_outcomes(passed=1)
186
224
 
187
225
 
226
+ def test_converter_post_pre_v2(testdir):
227
+ testdir.makepyfile(
228
+ """
229
+ import tempfile
230
+ from pytest_regtest import register_converter_post
231
+
232
+ @register_converter_post
233
+ def to_upper_conv(line):
234
+ return line.upper()
235
+
236
+ def test_regtest(regtest_all, tmpdir):
237
+ print("this is expected outcome")
238
+ print(tmpdir.join("test").strpath)
239
+ print(tempfile.gettempdir())
240
+ print(tempfile.mkdtemp())
241
+ print("obj id is", hex(id(tempfile)))
242
+ """
243
+ )
244
+ result = testdir.runpytest_subprocess()
245
+ result.assert_outcomes(failed=1)
246
+
247
+ expected_diff = """
248
+ > --- is
249
+ > +++ tobe
250
+ > @@ -1,5 +0,0 @@
251
+ > -THIS IS EXPECTED OUTCOME
252
+ > -<TMPDIR_FROM_FIXTURE>/TEST
253
+ > -<TMPDIR_FROM_TEMPFILE_MODULE>
254
+ > -<TMPDIR_FROM_TEMPFILE_MODULE>
255
+ > -OBJ ID IS 0X?????????
256
+ """.strip().split(
257
+ "\n"
258
+ )
259
+
260
+ result.stdout.fnmatch_lines(
261
+ [line.lstrip() for line in expected_diff], consecutive=True
262
+ )
263
+
264
+ result = testdir.runpytest("--regtest-reset")
265
+ result.assert_outcomes(passed=1)
266
+
267
+
188
268
  def test_converter_post(testdir):
189
269
  testdir.makepyfile(
190
270
  """
@@ -227,6 +307,7 @@ def test_converter_post(testdir):
227
307
  result.assert_outcomes(passed=1)
228
308
 
229
309
 
310
+
230
311
  def test_consider_line_endings(create_test_regtest_fh):
231
312
  create_test_regtest_fh.runpytest("--regtest-reset")
232
313
 
File without changes