Skip to content

Commit

Permalink
add first snapshot tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mirpedrol committed Nov 14, 2023
1 parent 19f60bc commit 887f372
Show file tree
Hide file tree
Showing 5 changed files with 483 additions and 1 deletion.
2 changes: 2 additions & 0 deletions nf_core/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,7 @@ def create_pipeline(ctx, name, description, author, version, force, outdir, temp
)
app = PipelineCreateApp()
app.run()
sys.exit(app.return_code or 0)


# nf-core create (deprecated)
Expand Down Expand Up @@ -582,6 +583,7 @@ def create(name, description, author, version, force, outdir, template_yaml, pla
app = PipelineCreateApp()
try:
app.run()
sys.exit(app.return_code or 0)
except UserWarning as e:
log.error(e)
sys.exit(1)
Expand Down
2 changes: 1 addition & 1 deletion nf_core/pipelines/create/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def on_button_pressed(self, event: Button.Pressed) -> None:
elif event.button.id == "close_screen":
self.switch_screen("github_repo")
if event.button.id == "close_app":
self.exit()
self.exit(return_code=0)

def action_toggle_dark(self) -> None:
"""An action to toggle dark mode."""
Expand Down
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ textual-dev>=1.2.1
mypy
types-PyYAML
types-requests
pytest-textual-snapshot
442 changes: 442 additions & 0 deletions tests/__snapshots__/test_create_app.ambr

Large diffs are not rendered by default.

37 changes: 37 additions & 0 deletions tests/test_create_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
""" Test Pipeline Create App """
import pytest

from nf_core.pipelines.create import PipelineCreateApp


@pytest.mark.asyncio
async def test_app_bindings():
"""Test that the app bindings work."""
app = PipelineCreateApp()
async with app.run_test() as pilot:
# Test pressing the D key
assert app.dark == True
await pilot.press("d")
assert app.dark == False
await pilot.press("d")
assert app.dark == True

# Test pressing the Q key
await pilot.press("q")
assert app.return_code == 0


def test_welcome(snap_compare):
"""Test snapshot for the first screen in the app. The welcome screen."""
assert snap_compare("../nf_core/pipelines/create/__init__.py")


def test_choose_type(snap_compare):
"""Test snapshot for the choose_type screen.
screen welcome > press start > screen choose_type
"""

async def run_before(pilot) -> None:
await pilot.click("#start")

assert snap_compare("../nf_core/pipelines/create/__init__.py", terminal_size=(100, 50), run_before=run_before)

0 comments on commit 887f372

Please sign in to comment.