Skip to content

Commit

Permalink
Run testbed with Textual in CI (without tests)
Browse files Browse the repository at this point in the history
  • Loading branch information
rmartin16 committed Sep 12, 2024
1 parent dbda4d4 commit 3d0e1f6
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 13 deletions.
39 changes: 33 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,17 @@ jobs:
strategy:
fail-fast: false
matrix:
backend: [ "macOS-x86_64", "macOS-arm64", "windows", "linux-x11", "linux-wayland","android", "iOS" ]
backend:
- "macOS-x86_64"
- "macOS-arm64"
- "windows"
- "linux-x11"
- "linux-wayland"
- "android"
- "iOS"
- "textual-linux"
- "textual-macOS"
- "textual-windows"
include:
- pre-command: ""
briefcase-run-prefix: ""
Expand Down Expand Up @@ -265,6 +275,25 @@ jobs:
setup-python: false # Use the system Python packages
app-user-data-path: "$HOME/.local/share/testbed"

- backend: "textual-linux"
platform: "linux"
runs-on: "ubuntu-22.04"
setup-python: false # Use the system Python packages
briefcase-run-args: --config 'requires=["../core","../textual"]' --config 'console_app=true'
app-user-data-path: "$HOME/.local/share/testbed"

- backend: "textual-macOS"
platform: "macOS"
runs-on: "macos-14"
briefcase-run-args: --config 'requires=["../core","../textual"]' --config 'console_app=true'
app-user-data-path: "$HOME/Library/Application Support/org.beeware.toga.testbed"

- backend: "textual-windows"
platform: "windows"
runs-on: "windows-latest"
briefcase-run-args: --config 'requires=["../core","../textual"]' --config 'console_app=true'
app-user-data-path: '$HOME\AppData\Local\Tiberius Yak\Toga Testbed\Data'

- backend: "windows"
platform: "windows"
runs-on: "windows-latest"
Expand All @@ -274,7 +303,7 @@ jobs:
platform: "iOS"
runs-on: "macos-14"
# As of early April 2024, the XCode 15/iOS 17 simulator had a performance
# issue that rendered Github Actions testing impossible. The issue didn't
# issue that rendered GitHub Actions testing impossible. The issue didn't
# impact iOS 16.4, but that required the use of Xcode 14.3.1.
#
# Refs #2476, actions/runner-images#9591.
Expand All @@ -301,7 +330,7 @@ jobs:
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm
steps:
# Github runners seem to have intermittent connectivity issues.
# GitHub runners seem to have intermittent connectivity issues.
# See https://github.com/beeware/toga/issues/2632
- name: Tune GitHub-hosted runner network
uses: smorimoto/tune-github-hosted-runner-network@v1.0.0
Expand All @@ -326,9 +355,7 @@ jobs:
${{ matrix.pre-command }}
# Use the development version of Briefcase
python -m pip install -U pip
# python -m pip install git+https://github.com/beeware/briefcase.git
# TODO: Use the stable release of Briefcase so that binary packages are available.
python -m pip install briefcase==0.3.19
python -m pip install git+https://github.com/beeware/briefcase.git
- name: Test App
working-directory: testbed
Expand Down
1 change: 1 addition & 0 deletions changes/2823.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CI now verifies the testbed app can start with the toga-textual backend.
1 change: 0 additions & 1 deletion testbed/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ requires = [
"../gtk",
]


[tool.briefcase.app.testbed.windows]
test_sources = [
"../winforms/tests_backend",
Expand Down
23 changes: 18 additions & 5 deletions testbed/tests/testbed.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import coverage
import pytest

from testbed.app import main
import testbed.app


def run_tests(app, cov, args, report_coverage, run_slow, running_in_ci):
Expand All @@ -37,6 +37,14 @@ def run_tests(app, cov, args, report_coverage, run_slow, running_in_ci):
return

print("ready.")

# Textual backend does not yet support testing.
# However, this will verify a Textual app can at least start.
if app.factory.__name__.startswith("toga_textual"):
time.sleep(1) # wait for the Textual app to start
app.returncode = 0 if app._impl.native.is_running else 1
return

# Control the run speed of the test app.
app.run_slow = run_slow

Expand Down Expand Up @@ -149,9 +157,6 @@ def run_tests(app, cov, args, report_coverage, run_slow, running_in_ci):
)
cov.start()

# Create the test app, starting the test suite as a background task
app = main()

# Determine pytest arguments
args = sys.argv[1:]

Expand All @@ -170,6 +175,7 @@ def run_tests(app, cov, args, report_coverage, run_slow, running_in_ci):
except ValueError:
report_coverage = False

# Use flag for running in CI since some tests will only succeed on the CI platform
try:
args.remove("--ci")
running_in_ci = True
Expand All @@ -182,6 +188,9 @@ def run_tests(app, cov, args, report_coverage, run_slow, running_in_ci):
args = ["tests"]
report_coverage = True

# Create the test app, starting the test suite as a background task
app = testbed.app.main()

thread = Thread(
target=partial(
run_tests,
Expand All @@ -193,10 +202,14 @@ def run_tests(app, cov, args, report_coverage, run_slow, running_in_ci):
running_in_ci=running_in_ci,
)
)

# Queue a background task to run that will start the main thread. We do this,
# instead of just starting the thread directly, so that we can make sure the App has
# been fully initialized, and the event loop is running.
app.loop.call_soon_threadsafe(thread.start)

# Start the test app.
# Ensure Textual apps start in headless mode
app._impl.headless = True

# Start the test app
app.main_loop()
5 changes: 4 additions & 1 deletion textual/src/toga_textual/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ def __init__(self, interface):
self.loop = asyncio.new_event_loop()
self.native = TogaApp(self)

# run the app without displaying it
self.headless = False

def create(self):
self.interface._startup()
self.set_current_window(self.interface.main_window._impl)
Expand All @@ -51,7 +54,7 @@ def exit(self):
self.native.exit()

def main_loop(self):
self.loop.run_until_complete(self.native.run_async())
self.loop.run_until_complete(self.native.run_async(headless=self.headless))

def set_icon(self, icon):
pass
Expand Down

0 comments on commit 3d0e1f6

Please sign in to comment.