Skip to content

Commit d97312a

Browse files
committed
Use "check_file_regression" in tests
1 parent 39d1dca commit d97312a

File tree

3 files changed

+27
-25
lines changed

3 files changed

+27
-25
lines changed

tests/test_iterative.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
# this package
1818
from domdf_python_tools.iterative import Len, chunks, double_chain, flatten, make_tree, permutations, split_len
19+
from domdf_python_tools.testing import check_file_regression
1920

2021

2122
def test_chunks():
@@ -110,10 +111,6 @@ def test_double_chain(value, expects):
110111
assert list(double_chain(value)) == expects
111112

112113

113-
def check_file_regression(data, file_regression: FileRegressionFixture, extension=".txt"):
114-
file_regression.check(data, encoding="UTF-8", extension=extension)
115-
116-
117114
def test_make_tree(file_regression: FileRegressionFixture):
118115
check_file_regression(
119116
'\n'.join(

tests/test_pretty_print.py

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
# this package
2323
from domdf_python_tools.pretty_print import FancyPrinter, simple_repr
2424
from domdf_python_tools.stringlist import StringList
25-
2625
# list, tuple and dict subclasses that do or don't overwrite __repr__
26+
from domdf_python_tools.testing import check_file_regression
2727

2828

2929
class list2(list):
@@ -497,7 +497,7 @@ def test_ordered_dict(self, file_regression: FileRegressionFixture):
497497
assert FancyPrinter(width=1).pformat(d) == "OrderedDict()"
498498
words = "the quick brown fox jumped over a lazy dog".split()
499499
d = collections.OrderedDict(zip(words, itertools.count()))
500-
self.check_file_regression(FancyPrinter().pformat(d), file_regression)
500+
check_file_regression(FancyPrinter().pformat(d), file_regression)
501501

502502
def test_mapping_proxy(self):
503503
words = "the quick brown fox jumped over a lazy dog".split()
@@ -546,7 +546,7 @@ def test_small_simple_namespace(self):
546546

547547
def test_subclassing(self, file_regression: FileRegressionFixture):
548548
o = {"names with spaces": "should be presented using repr()", "others.should.not.be": "like.this"}
549-
file_regression.check(DottedPrettyPrinter().pformat(o), extension=".txt", encoding="UTF-8")
549+
check_file_regression(DottedPrettyPrinter().pformat(o), file_regression)
550550

551551
@pytest.mark.parametrize(
552552
"value, width",
@@ -559,7 +559,7 @@ def test_subclassing(self, file_regression: FileRegressionFixture):
559559
def test_set_reprs(self, value, width, file_regression: FileRegressionFixture):
560560
assert FancyPrinter().pformat(set()) == "set()"
561561
assert FancyPrinter().pformat(set(range(3))) == "{0, 1, 2}"
562-
self.check_file_regression(FancyPrinter(width=width).pformat(value), file_regression)
562+
check_file_regression(FancyPrinter(width=width).pformat(value), file_regression)
563563

564564
@pytest.mark.parametrize(
565565
"value, width",
@@ -572,7 +572,7 @@ def test_set_reprs(self, value, width, file_regression: FileRegressionFixture):
572572
def test_frozenset_reprs(self, value, width, file_regression: FileRegressionFixture):
573573
assert FancyPrinter().pformat(frozenset()) == "frozenset()"
574574
assert FancyPrinter().pformat(frozenset(range(3))) == "frozenset({0, 1, 2})"
575-
self.check_file_regression(FancyPrinter(width=width).pformat(value), file_regression)
575+
check_file_regression(FancyPrinter(width=width).pformat(value), file_regression)
576576

577577
def test_depth(self):
578578
nested_tuple = (1, (2, (3, (4, (5, 6)))))
@@ -853,34 +853,34 @@ def test_bytes_wrap(self):
853853
]
854854
)
855855
def test_bytearray_wrap(self, value, width, file_regression: FileRegressionFixture):
856-
self.check_file_regression(FancyPrinter(width=width).pformat(value), file_regression)
856+
check_file_regression(FancyPrinter(width=width).pformat(value), file_regression)
857857

858858
def test_default_dict(self, file_regression: FileRegressionFixture):
859859
d: collections.defaultdict = collections.defaultdict(int)
860860
assert FancyPrinter(width=1).pformat(d) == "defaultdict(<class 'int'>, {})"
861861
words = "the quick brown fox jumped over a lazy dog".split()
862862
d = collections.defaultdict(int, zip(words, itertools.count()))
863-
self.check_file_regression(FancyPrinter().pformat(d), file_regression)
863+
check_file_regression(FancyPrinter().pformat(d), file_regression)
864864

865865
def test_counter(self, file_regression: FileRegressionFixture):
866866
d: collections.Counter = collections.Counter()
867867
assert FancyPrinter(width=1).pformat(d) == "Counter()"
868868
d = collections.Counter("senselessness")
869-
self.check_file_regression(FancyPrinter(width=40).pformat(d), file_regression)
869+
check_file_regression(FancyPrinter(width=40).pformat(d), file_regression)
870870

871871
def test_chainmap(self, file_regression: FileRegressionFixture):
872872
d: collections.ChainMap = collections.ChainMap()
873873
assert FancyPrinter(width=1).pformat(d) == "ChainMap({})"
874874
words = "the quick brown fox jumped over a lazy dog".split()
875875
items = list(zip(words, itertools.count()))
876876
d = collections.ChainMap(dict(items))
877-
self.check_file_regression(FancyPrinter().pformat(d), file_regression)
877+
check_file_regression(FancyPrinter().pformat(d), file_regression)
878878

879879
def test_chainmap_nested(self, file_regression: FileRegressionFixture):
880880
words = "the quick brown fox jumped over a lazy dog".split()
881881
items = list(zip(words, itertools.count()))
882882
d = collections.ChainMap(dict(items), collections.OrderedDict(items))
883-
self.check_file_regression(FancyPrinter().pformat(d), file_regression)
883+
check_file_regression(FancyPrinter().pformat(d), file_regression)
884884

885885
def test_deque(self):
886886
d: collections.deque = collections.deque()
@@ -914,22 +914,19 @@ def test_deque(self):
914914
('dog', 8)],
915915
maxlen=7)"""
916916

917-
def check_file_regression(self, data, file_regression: FileRegressionFixture):
918-
file_regression.check(data, extension=".txt", encoding="UTF-8")
919-
920917
def test_user_dict(self, file_regression: FileRegressionFixture):
921918
d: collections.UserDict = collections.UserDict()
922919
assert FancyPrinter(width=1).pformat(d) == "{}"
923920
words = "the quick brown fox jumped over a lazy dog".split()
924921
d = collections.UserDict(zip(words, itertools.count())) # type: ignore
925-
self.check_file_regression(FancyPrinter().pformat(d), file_regression)
922+
check_file_regression(FancyPrinter().pformat(d), file_regression)
926923

927924
def test_user_list(self, file_regression: FileRegressionFixture):
928925
d: collections.UserList = collections.UserList()
929926
assert FancyPrinter(width=1).pformat(d) == "[]"
930927
words = "the quick brown fox jumped over a lazy dog".split()
931928
d = collections.UserList(zip(words, itertools.count()))
932-
self.check_file_regression(FancyPrinter().pformat(d), file_regression)
929+
check_file_regression(FancyPrinter().pformat(d), file_regression)
933930

934931
@pytest.mark.parametrize(
935932
"value, width, expects",
@@ -983,4 +980,4 @@ class F:
983980
c = "cherry"
984981
d = list(range(100))
985982

986-
file_regression.check(repr(F()), encoding="UTF-8", extension=".txt")
983+
check_file_regression(repr(F()), file_regression)

tests/test_utils.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@
1717

1818
# 3rd party
1919
import pytest
20+
from deprecation import fail_if_not_removed
2021
from pytest_regressions.file_regression import FileRegressionFixture
2122

2223
# this package
2324
from domdf_python_tools import utils
2425
from domdf_python_tools.paths import PathPlus
25-
from domdf_python_tools.testing import testing_boolean_values
26+
from domdf_python_tools.testing import check_file_regression, testing_boolean_values
2627
from domdf_python_tools.typing import HasHead
2728
from domdf_python_tools.utils import coloured_diff, deprecated, head
2829

@@ -31,15 +32,20 @@ def test_pyversion():
3132
assert isinstance(utils.pyversion, int)
3233

3334

35+
@fail_if_not_removed
3436
def test_check_dependencies(capsys):
3537
deps = ["pytest", "domdf_python_tools", "madeup_module"]
3638

37-
missing_deps = utils.check_dependencies(deps, False)
39+
with pytest.deprecated_call() as record:
40+
missing_deps = utils.check_dependencies(deps, False)
41+
assert len(record) == 1
3842
assert isinstance(missing_deps, list)
3943
assert len(missing_deps) == 1
4044
assert missing_deps == ["madeup_module"]
4145

42-
missing_deps = utils.check_dependencies(deps)
46+
with pytest.deprecated_call() as record:
47+
missing_deps = utils.check_dependencies(deps)
48+
assert len(record) == 1
4349
captured = capsys.readouterr()
4450
stdout = captured.out.split('\n')
4551
assert stdout[0] == "The following modules are missing:"
@@ -50,7 +56,9 @@ def test_check_dependencies(capsys):
5056
assert len(missing_deps) == 1
5157
assert missing_deps == ["madeup_module"]
5258

53-
missing_deps = utils.check_dependencies(["pytest"])
59+
with pytest.deprecated_call() as record:
60+
missing_deps = utils.check_dependencies(["pytest"])
61+
assert len(record) == 1
5462
captured = capsys.readouterr()
5563
stdout = captured.out.split('\n')
5664
assert stdout[0] == "All modules installed"
@@ -469,4 +477,4 @@ def test_diff(file_regression: FileRegressionFixture):
469477
lineterm='',
470478
)
471479

472-
file_regression.check(diff, encoding="UTF-8", extension=".txt")
480+
check_file_regression(diff, file_regression)

0 commit comments

Comments
 (0)