From 13b27e1fa33cdce2adfe61c16712d086b8cc21bf Mon Sep 17 00:00:00 2001 From: Darren Burns Date: Tue, 20 Sep 2022 13:48:35 +0100 Subject: [PATCH] Updates --- .../__snapshots__/test_snapshots.ambr | 747 ++++++++++++++++-- tests/snapshot_tests/conftest.py | 46 +- tests/snapshot_tests/snapshot_report.html | 364 +-------- .../snapshot_report_template.jinja2 | 2 +- tests/snapshot_tests/test_snapshots.py | 20 +- 5 files changed, 715 insertions(+), 464 deletions(-) diff --git a/tests/snapshot_tests/__snapshots__/test_snapshots.ambr b/tests/snapshot_tests/__snapshots__/test_snapshots.ambr index 74538c10d..e333fcd1f 100644 --- a/tests/snapshot_tests/__snapshots__/test_snapshots.ambr +++ b/tests/snapshot_tests/__snapshots__/test_snapshots.ambr @@ -1,4 +1,4 @@ -# name: test_combining_layouts +# name: test_center_layout ''' @@ -21,139 +21,289 @@ font-weight: 700; } - .terminal-1942842461-matrix { + .terminal-3376477890-matrix { font-family: Fira Code, monospace; font-size: 20px; line-height: 24.4px; font-variant-east-asian: full-width; } - .terminal-1942842461-title { + .terminal-3376477890-title { font-size: 18px; font-weight: bold; font-family: arial; } - .terminal-1942842461-r1 { fill: #c5c8c6 } - .terminal-1942842461-r2 { fill: #f6f5f5 } - .terminal-1942842461-r3 { fill: #e0dedb } - .terminal-1942842461-r4 { fill: #1e90ff } - .terminal-1942842461-r5 { fill: #c71585 } - .terminal-1942842461-r6 { fill: #f3f3f3 } - .terminal-1942842461-r7 { fill: #ffffff } - .terminal-1942842461-r8 { fill: #172127 } - .terminal-1942842461-r9 { fill: #adff2f } + .terminal-3376477890-r1 { fill: #f3f3f3 } + .terminal-3376477890-r2 { fill: #c5c8c6 } - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - Textual + Textual - - - - - CombiningLayoutsExample14:29:12 - - ┌──────────────────────────────────────┐┌──────────────────────────────────────┐ - HorizontallyPositionedChildrenHere - Vertical layout, child 0 - - - - Vertical layout, child 1 - ▇▇ - - └──────────────────────────────────────┘ - Vertical layout, child 2┌──────────────────────────────────────┐ - Thispanelis - - - Vertical layout, child 3 - - usinggrid layout! - - Vertical layout, child 4 - - └──────────────────────────────────────┘└──────────────────────────────────────┘ + + + + + + One + + + + Two + + + Three + + + + + + + + + + + + + + + + + + + ''' +# --- +# name: test_dock_layout_sidebar + ''' + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Textual + + + + + + + + + + Sidebar1Docking a widget removes it from the layout and  + fixes its position, aligned to either the top,  + right, bottom, or left edges of a container. + + Docked widgets will not scroll out of view,  + making them ideal for sticky headers, footers,  + and sidebars. + ▇▇ + Docking a widget removes it from the layout and  + fixes its position, aligned to either the top,  + right, bottom, or left edges of a container. + + Docked widgets will not scroll out of view,  + making them ideal for sticky headers, footers,  + and sidebars. + + Docking a widget removes it from the layout and  + fixes its position, aligned to either the top,  + right, bottom, or left edges of a container. + + Docked widgets will not scroll out of view,  + making them ideal for sticky headers, footers,  + and sidebars. + @@ -472,9 +622,472 @@ ''' # --- -# name: test_x +# name: test_horizontal_layout ''' - 123 - 123123123 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Textual + + + + + + + + + + ┌────────────────────────┐┌─────────────────────────┐┌─────────────────────────┐ + OneTwoThree + + + + + + + + + + + + + + + + + + + + + + └────────────────────────┘└─────────────────────────┘└─────────────────────────┘ + + + + + ''' +# --- +# name: test_layers + ''' + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Textual + + + + + + + + + + + + + + + + + + + + + box1 (layer = above) + + + + + + box2 (layer = below) + + + + + + + + + + + ''' +# --- +# name: test_vertical_layout + ''' + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Textual + + + + + + + + + + ┌──────────────────────────────────────────────────────────────────────────────┐ + One + + + + + + └──────────────────────────────────────────────────────────────────────────────┘ + ┌──────────────────────────────────────────────────────────────────────────────┐ + Two + + + + + + └──────────────────────────────────────────────────────────────────────────────┘ + ┌──────────────────────────────────────────────────────────────────────────────┐ + Three + + + + + + └──────────────────────────────────────────────────────────────────────────────┘ + + + + ''' # --- diff --git a/tests/snapshot_tests/conftest.py b/tests/snapshot_tests/conftest.py index f24ab3512..69cc6d1b3 100644 --- a/tests/snapshot_tests/conftest.py +++ b/tests/snapshot_tests/conftest.py @@ -5,10 +5,10 @@ from functools import partial from operator import attrgetter from os import PathLike from pathlib import Path -from typing import Union, List, Optional, Any, Callable +from typing import Union, List, Optional, Callable import pytest -from _pytest.fixtures import FixtureDef, SubRequest, FixtureRequest +from _pytest.fixtures import FixtureRequest from jinja2 import Template from rich.console import Console from rich.panel import Panel @@ -49,20 +49,6 @@ class SvgSnapshotDiff: line_number: int -# -# def pytest_runtestloop(session: "Session") -> Optional[object]: - -@pytest.hookimpl(hookwrapper=True) -def pytest_pyfunc_call(pyfuncitem: "pytest.Function") -> Optional[object]: - """Call underlying test function. - - Stops at first non-None result, see :ref:`firstresult`. - """ - # Before - yield - # After - - def pytest_runtest_teardown(item: pytest.Item, nextitem: Optional[pytest.Item]) -> None: """Called to perform the teardown phase for a test item. @@ -79,26 +65,6 @@ def pytest_runtest_teardown(item: pytest.Item, nextitem: Optional[pytest.Item]) """ -@pytest.hookimpl(hookwrapper=True) -def pytest_fixture_setup( - fixturedef: FixtureDef[Any], request: SubRequest -) -> Optional[object]: - """Perform fixture setup execution. - - :returns: The return value of the call to the fixture function. - - Stops at first non-None result, see :ref:`firstresult`. - - .. note:: - If the fixture function returns None, other implementations of - this hook function will continue to be called, according to the - behavior of the :ref:`firstresult` option. - """ - value = yield - value = value.get_result() - value = repr(value) - - def pytest_sessionfinish( session: "pytest.Session", exitstatus: Union[int, "pytest.ExitCode"], @@ -120,7 +86,9 @@ def pytest_sessionfinish( SvgSnapshotDiff( snapshot=str(snapshot_svg), actual=str(actual_svg), - file_similarity=100 * difflib.SequenceMatcher(a=str(snapshot_svg), b=str(actual_svg)).ratio(), + file_similarity=100 * difflib.SequenceMatcher(a=str(snapshot_svg), + b=str( + actual_svg)).ratio(), test_name=name, path=path, line_number=line_index + 1, @@ -143,8 +111,8 @@ def pytest_sessionfinish( diffs=diffs, passes=num_snapshots_passing, fails=num_fails, - pass_percentage=100*(num_snapshots_passing/num_snapshot_tests), - fail_percentage=100*(num_fails/num_snapshot_tests), + pass_percentage=100 * (num_snapshots_passing / (num_snapshot_tests + 1)), + fail_percentage=100 * (num_fails / (num_snapshot_tests + 1)), num_snapshot_tests=num_snapshot_tests, now=datetime.utcnow() ) diff --git a/tests/snapshot_tests/snapshot_report.html b/tests/snapshot_tests/snapshot_report.html index f853befd7..294be0c2b 100644 --- a/tests/snapshot_tests/snapshot_report.html +++ b/tests/snapshot_tests/snapshot_report.html @@ -14,379 +14,33 @@

Textual Snapshot Tests

- Showing diffs for 1 mismatched snapshot(s) + Showing diffs for 0 mismatched snapshot(s)
- 1 snapshots changed + 0 snapshots changed · - 2 snapshots matched + 7 snapshots matched
+ style="width: 0.0%" + aria-valuenow="0" aria-valuemin="0" aria-valuemax="7">
+ style="width: 87.5%" + aria-valuenow="7" aria-valuemin="0" + aria-valuemax="7">
-
-
-
-
-
- - test_combining_layouts - - (88.89% similar) -
- /Users/darrenburns/code/textual/tests/snapshot_tests/test_snapshots.py:9 -
-
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Textual - - - - - - - - - - -CombiningLayoutsExample15:50:46 - -┌──────────────────────────────────────┐┌──────────────────────────────────────┐ -HorizontallyPositionedChildrenHere -Vertical layout, child 0 - - - -Vertical layout, child 1 -▇▇ - -└──────────────────────────────────────┘ -Vertical layout, child 2┌──────────────────────────────────────┐ -Thispanelis - - -Vertical layout, child 3 - -usinggrid layout! - -Vertical layout, child 4 - -└──────────────────────────────────────┘└──────────────────────────────────────┘ - - - - -
- Output from test -
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Textual - - - - - - - - - - -CombiningLayoutsExample14:29:12 - -┌──────────────────────────────────────┐┌──────────────────────────────────────┐ -HorizontallyPositionedChildrenHere -Vertical layout, child 0 - - - -Vertical layout, child 1 -▇▇ - -└──────────────────────────────────────┘ -Vertical layout, child 2┌──────────────────────────────────────┐ -Thispanelis - - -Vertical layout, child 3 - -usinggrid layout! - -Vertical layout, child 4 - -└──────────────────────────────────────┘└──────────────────────────────────────┘ - - - - -
- Historical snapshot -
-
-
-
-
-
-
-
@@ -401,7 +55,7 @@
-

Report generated at UTC 2022-09-16 14:50:47.993944.

+

Report generated at UTC 2022-09-20 12:27:59.430929.

diff --git a/tests/snapshot_tests/snapshot_report_template.jinja2 b/tests/snapshot_tests/snapshot_report_template.jinja2 index a726b9b57..9427a9606 100644 --- a/tests/snapshot_tests/snapshot_report_template.jinja2 +++ b/tests/snapshot_tests/snapshot_report_template.jinja2 @@ -49,7 +49,7 @@ {{ diff.test_name }} - ({{ "%.2f"|format(diff.file_similarity) }}% similar) + ({{ "%.2f"|format(diff.file_similarity) }}% source similarity)
{{ diff.path }}:{{ diff.line_number }}
diff --git a/tests/snapshot_tests/test_snapshots.py b/tests/snapshot_tests/test_snapshots.py index d3de89f48..0c95f103c 100644 --- a/tests/snapshot_tests/test_snapshots.py +++ b/tests/snapshot_tests/test_snapshots.py @@ -6,9 +6,25 @@ def test_grid_layout_basic_overflow(snap_compare): assert snap_compare("docs/examples/guide/layout/grid_layout2.py") -def test_combining_layouts(snap_compare): - assert snap_compare("docs/examples/guide/layout/combining_layouts.py") +def test_grid_layout_gutter(snap_compare): + assert snap_compare("docs/examples/guide/layout/grid_layout7_gutter.py") def test_layers(snap_compare): assert snap_compare("docs/examples/guide/layout/layers.py") + + +def test_center_layout(snap_compare): + assert snap_compare("docs/examples/guide/layout/center_layout.py") + + +def test_horizontal_layout(snap_compare): + assert snap_compare("docs/examples/guide/layout/horizontal_layout.py") + + +def test_vertical_layout(snap_compare): + assert snap_compare("docs/examples/guide/layout/vertical_layout.py") + + +def test_dock_layout_sidebar(snap_compare): + assert snap_compare("docs/examples/guide/layout/dock_layout2_sidebar.py")