Debian Codegraph @

tests/test_file_regression.py

raw symbols SCIP
1 import sys
2 import textwrap
3
4 import pytest
5
6 from pytest_regressions.testing import check_regression_fixture_workflow
7
8
9 def test_simple_text_file(file_regression, datadir):
10 contents = textwrap.dedent(
11 """\
12 # Title
13 Another line: olรก
14 """
15 )
16 file_regression.check(contents, encoding="latin1", extension=".md")
17
18
19 def test_simple_bin_file(file_regression, datadir):
20 contents = b"binary contents \xff\xff\xde"
21 file_regression.check(contents, binary=True, extension=".bin")
22
23
24 def test_binary_and_text_error(file_regression):
25 with pytest.raises(ValueError):
26 file_regression.check("", encoding="UTF-8", binary=True)
27
28
29 def test_file_regression_workflow(pytester, monkeypatch):
30 monkeypatch.setattr(sys, "get_data", lambda: "foo", raising=False)
31 source = """
32 import sys
33 def test_1(file_regression):
34 contents = sys.get_data()
35 file_regression.check(contents, extension='.test')
36 """
37
38 def get_file_contents():
39 fn = pytester.path / "test_file" / "test_1.test"
40 assert fn.is_file()
41 return fn.read_text()
42
43 check_regression_fixture_workflow(
44 pytester,
45 source,
46 data_getter=get_file_contents,
47 data_modifier=lambda: monkeypatch.setattr(
48 sys, "get_data", lambda: "foobar", raising=False
49 ),
50 expected_data_1="foo",
51 expected_data_2="foobar",
52 )