Skip to content

Commit 91d7016

Browse files
godlygeekpablogsal
authored andcommitted
tests: Ignore Textual snapshot mismatches on 3.7
The snapshots we've generated using current versions of Textual aren't expected to match anymore on Python 3.7, as Textual dropped support for Python 3.7 in the 0.44 release. However, we'd still like to run our snapshot tests on Python 3.7, to confirm that no unexpected exceptions occur and that the app doesn't crash. So, allow `snap_compare()` to drive the application, but always return `True` on Python 3.7 as long as no exception was raised. Signed-off-by: Matt Wozniski <[email protected]>
1 parent 1933551 commit 91d7016

File tree

3 files changed

+35
-64
lines changed

3 files changed

+35
-64
lines changed

tests/conftest.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import socket
2-
import sys
32

43
import pytest
54

@@ -11,12 +10,3 @@ def free_port():
1110
port_number = s.getsockname()[1]
1211
s.close()
1312
return port_number
14-
15-
16-
def pytest_configure(config):
17-
# Several of the tree reporter tests require Textual 0.48, which does not
18-
# support Python 3.7, but skipping those tests causes the test suite to
19-
# fail due to unused snapshots. Override the configuration for Python 3.7
20-
# so that unused snapshots are a warning, not an error.
21-
if sys.version_info < (3, 8):
22-
config.option.warn_unused_snapshots = True

tests/unit/test_tree_reporter.py

Lines changed: 17 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1532,6 +1532,15 @@ def test_render_runs_the_app(self):
15321532

15331533
@pytest.fixture
15341534
def compare(monkeypatch, tmp_path, snap_compare):
1535+
# The snapshots we've generated using current versions of Textual aren't
1536+
# expected to match anymore on Python 3.7, as Textual dropped support for
1537+
# Python 3.7 in the 0.44 release. However, we'd still like to run our
1538+
# snapshot tests on Python 3.7, to confirm that no unexpected exceptions
1539+
# occur and that the app doesn't crash. So, allow `snap_compare()` to drive
1540+
# the application, but always return `True` on Python 3.7 as long as no
1541+
# exception was raised.
1542+
succeed_even_if_mismatched = sys.version_info < (3, 8)
1543+
15351544
def compare_impl(
15361545
allocations: Iterator[AllocationRecord],
15371546
press: Iterable[str] = (),
@@ -1550,21 +1559,20 @@ def compare_impl(
15501559
with monkeypatch.context() as app_patch:
15511560
app_patch.setitem(globals(), app_global, app)
15521561
tmp_main.write_text(f"from {__name__} import {app_global} as app")
1553-
return snap_compare(
1554-
str(tmp_main),
1555-
press=press,
1556-
terminal_size=terminal_size,
1557-
run_before=run_before,
1562+
return (
1563+
snap_compare(
1564+
str(tmp_main),
1565+
press=press,
1566+
terminal_size=terminal_size,
1567+
run_before=run_before,
1568+
)
1569+
or succeed_even_if_mismatched
15581570
)
15591571

15601572
yield compare_impl
15611573

15621574

15631575
class TestTUILooks:
1564-
@pytest.mark.skipif(
1565-
sys.version_info < (3, 8),
1566-
reason="This test requires Textual 0.49 or higher, which doesn't support 3.7",
1567-
)
15681576
def test_basic(self, compare):
15691577
# GIVEN
15701578
code = dedent(
@@ -1599,10 +1607,6 @@ def generate_primes():
15991607
getlines.return_value = code.splitlines()
16001608
assert compare(peak_allocations, press=[])
16011609

1602-
@pytest.mark.skipif(
1603-
sys.version_info < (3, 8),
1604-
reason="This test requires Textual 0.48 or higher, which doesn't support 3.7",
1605-
)
16061610
def test_basic_node_selected_not_leaf(self, compare):
16071611
# GIVEN
16081612
code = dedent(
@@ -1637,10 +1641,6 @@ def generate_primes():
16371641
getlines.return_value = code.splitlines()
16381642
assert compare(peak_allocations, press=[*["down"] * 2])
16391643

1640-
@pytest.mark.skipif(
1641-
sys.version_info < (3, 8),
1642-
reason="This test requires Textual 0.49 or higher, which doesn't support 3.7",
1643-
)
16441644
def test_basic_node_selected_leaf(self, compare):
16451645
# GIVEN
16461646
code = dedent(
@@ -1675,10 +1675,6 @@ def generate_primes():
16751675
getlines.return_value = code.splitlines()
16761676
assert compare(peak_allocations, press=[*["down"] * 3])
16771677

1678-
@pytest.mark.skipif(
1679-
sys.version_info < (3, 8),
1680-
reason="This test requires Textual 0.49 or higher, which doesn't support 3.7",
1681-
)
16821678
def test_two_chains(self, compare):
16831679
# GIVEN
16841680
code = dedent(
@@ -1726,10 +1722,6 @@ def generate_primes():
17261722
getlines.return_value = code.splitlines()
17271723
assert compare(peak_allocations, press=[])
17281724

1729-
@pytest.mark.skipif(
1730-
sys.version_info < (3, 8),
1731-
reason="This test requires Textual 0.48 or higher, which doesn't support 3.7",
1732-
)
17331725
def test_two_chains_after_expanding_second(self, compare):
17341726
# GIVEN
17351727
code = dedent(
@@ -1779,10 +1771,6 @@ def generate_primes():
17791771
getlines.return_value = code.splitlines()
17801772
assert compare(peak_allocations, press=[*["down"] * 4, "e"])
17811773

1782-
@pytest.mark.skipif(
1783-
sys.version_info < (3, 8),
1784-
reason="This test requires Textual 0.49 or higher, which doesn't support 3.7",
1785-
)
17861774
def test_hide_import_system(self, compare):
17871775
# GIVEN
17881776
code = dedent(
@@ -1833,10 +1821,6 @@ def generate_primes():
18331821
getlines.return_value = code.splitlines()
18341822
assert compare(peak_allocations, press=["i"])
18351823

1836-
@pytest.mark.skipif(
1837-
sys.version_info < (3, 8),
1838-
reason="This test requires Textual 0.49 or higher, which doesn't support 3.7",
1839-
)
18401824
def test_show_uninteresting(self, compare):
18411825
# GIVEN
18421826
code = dedent(
@@ -1887,10 +1871,6 @@ def generate_primes():
18871871
getlines.return_value = code.splitlines()
18881872
assert compare(peak_allocations, press=["u"])
18891873

1890-
@pytest.mark.skipif(
1891-
sys.version_info < (3, 8),
1892-
reason="This test requires Textual 0.49 or higher, which doesn't support 3.7",
1893-
)
18941874
def test_show_uninteresting_and_hide_import_system(self, compare):
18951875
# GIVEN
18961876
code = dedent(
@@ -1942,10 +1922,6 @@ def generate_primes():
19421922
getlines.return_value = code.splitlines()
19431923
assert compare(peak_allocations, press=["u", "i"])
19441924

1945-
@pytest.mark.skipif(
1946-
sys.version_info < (3, 8),
1947-
reason="This test requires Textual 0.48 or higher, which doesn't support 3.7",
1948-
)
19491925
def test_select_screen(self, tmp_path, compare):
19501926
# GIVEN
19511927
code = dedent(
@@ -1979,10 +1955,6 @@ def generate_primes():
19791955
getlines.return_value = code.splitlines()
19801956
assert compare(peak_allocations, press=[*["down"] * 3])
19811957

1982-
@pytest.mark.skipif(
1983-
sys.version_info < (3, 8),
1984-
reason="This test requires Textual 0.49 or higher, which doesn't support 3.7",
1985-
)
19861958
def test_allocations_of_different_sizes(self, compare):
19871959
# GIVEN
19881960
peak_allocations = [
@@ -2003,10 +1975,6 @@ def test_allocations_of_different_sizes(self, compare):
20031975
getlines.return_value = []
20041976
assert compare(peak_allocations, press=[], terminal_size=(350, 100))
20051977

2006-
@pytest.mark.skipif(
2007-
sys.version_info < (3, 8),
2008-
reason="This test requires Textual 0.49 or higher, which doesn't support 3.7",
2009-
)
20101978
def test_biggest_allocations(self, compare):
20111979
# GIVEN
20121980
peak_allocations = [

tests/unit/test_tui_reporter.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import asyncio
22
import datetime
3+
import sys
34
from io import StringIO
45
from typing import Awaitable
56
from typing import Callable
@@ -102,6 +103,15 @@ def get_current_snapshot(
102103
def compare(monkeypatch, tmp_path, snap_compare):
103104
monkeypatch.setattr(memray.reporters.tui, "datetime", FakeDatetime)
104105

106+
# The snapshots we've generated using current versions of Textual aren't
107+
# expected to match anymore on Python 3.7, as Textual dropped support for
108+
# Python 3.7 in the 0.44 release. However, we'd still like to run our
109+
# snapshot tests on Python 3.7, to confirm that no unexpected exceptions
110+
# occur and that the app doesn't crash. So, allow `snap_compare()` to drive
111+
# the application, but always return `True` on Python 3.7 as long as no
112+
# exception was raised.
113+
succeed_even_if_mismatched = sys.version_info < (3, 8)
114+
105115
def compare_impl(
106116
cmdline_override: Optional[str] = None,
107117
press: Iterable[str] = (),
@@ -128,11 +138,14 @@ async def run_before_wrapper(pilot) -> None:
128138
with monkeypatch.context() as app_patch:
129139
app_patch.setitem(globals(), app_global, app)
130140
tmp_main.write_text(f"from {__name__} import {app_global} as app")
131-
return snap_compare(
132-
str(tmp_main),
133-
press=press,
134-
terminal_size=terminal_size,
135-
run_before=run_before_wrapper,
141+
return (
142+
snap_compare(
143+
str(tmp_main),
144+
press=press,
145+
terminal_size=terminal_size,
146+
run_before=run_before_wrapper,
147+
)
148+
or succeed_even_if_mismatched
136149
)
137150

138151
yield compare_impl

0 commit comments

Comments
 (0)