-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ただし、カメラデバイスが掴めずエラーになる可能性あり。
- Loading branch information
Showing
7 changed files
with
113 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: e2e-test | ||
|
||
on: | ||
push: | ||
paths-ignore: | ||
- "doc/**" | ||
- "html/**" | ||
- "**.md" | ||
- "THANKS" | ||
- "LICENSE" | ||
- "NOTICE" | ||
|
||
jobs: | ||
e2e-test-macos: | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
name: | ||
- macos_arm64 | ||
name: Build momo for ${{ matrix.name }} | ||
runs-on: macos-14 | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- run: python3 run.py ${{ matrix.name }} | ||
- uses: eifinger/setup-rye@v3 | ||
with: | ||
version: 'latest' | ||
- run: rye sync | ||
working-directory: ./test | ||
- run: rye run pytest test/test_momo.py | ||
working-directory: ./test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,3 +46,8 @@ webrtc_logs_0 | |
|
||
# python | ||
.venv | ||
.pytest_cache | ||
__pycache__ | ||
|
||
# vscode | ||
build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,79 @@ | ||
import platform | ||
import signal | ||
import subprocess | ||
import sys | ||
import threading | ||
import time | ||
from pathlib import Path | ||
|
||
# プラットフォームに応じたリリースディレクトリの設定 | ||
RELEASE_DIR = Path(__file__).resolve().parent.parent / Path("_build/") | ||
if platform.system() == "Darwin": | ||
if platform.machine() == "arm64": | ||
RELEASE_DIR = RELEASE_DIR / "macos_arm64/release/momo" | ||
elif platform.system() == "Linux": | ||
# ubuntu 24.04 かどうかの確認が必要 | ||
# ubuntu 22.04 と 24.04 がある | ||
RELEASE_DIR = RELEASE_DIR / "ubuntu-24.04_x86_64/release/momo" | ||
else: | ||
raise OSError(f"Unsupported platform: {platform.system()}") | ||
|
||
|
||
class Momo: | ||
def __init__(self): | ||
pass | ||
def __init__(self, port=5000): | ||
self.executable = RELEASE_DIR / "momo" | ||
self.port = port | ||
self.process = None | ||
self.thread = None | ||
self.is_running = False | ||
|
||
def __enter__(self): | ||
return self | ||
|
||
def __exit__(self, exc_type, exc_val, exc_tb): | ||
self.stop() | ||
|
||
def run_app(self, args): | ||
self.process = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | ||
self.process.wait() | ||
self.is_running = False | ||
def run_app(self): | ||
# test モードでポートだけ指定してあげる | ||
args = [str(self.executable), "test", "--port", str(self.port)] | ||
try: | ||
self.process = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | ||
self.process.wait() | ||
except Exception as e: | ||
print(f"Error running momo: {e}", file=sys.stderr) | ||
finally: | ||
self.is_running = False | ||
|
||
def start(self): | ||
self.thread = threading.Thread(target=self.run_app, args=()) | ||
if not self.executable.exists(): | ||
raise FileNotFoundError(f"Momo executable not found: {self.executable}") | ||
|
||
self.thread = threading.Thread(target=self.run_app) | ||
self.thread.start() | ||
self.is_running = True | ||
time.sleep(1) # アプリケーションの起動を待つ | ||
|
||
# momoの起動を確認 | ||
start_time = time.time() | ||
while time.time() - start_time < 10: # 10秒のタイムアウト | ||
if self.process and self.process.poll() is None: | ||
print(f"Momo started on port {self.port}") | ||
return | ||
time.sleep(0.1) | ||
|
||
raise TimeoutError("Momo failed to start within the timeout period") | ||
|
||
def stop(self): | ||
pass | ||
if self.is_running and self.process: | ||
# SIGINT を送信 (Ctrl+C と同等) | ||
self.process.send_signal(signal.SIGINT) | ||
try: | ||
# プロセスが終了するのを最大5秒間待つ | ||
self.process.wait(timeout=5) | ||
except subprocess.TimeoutExpired: | ||
# タイムアウトした場合、強制終了 | ||
print("Momo did not terminate gracefully. Forcing termination.", file=sys.stderr) | ||
self.process.kill() | ||
|
||
self.thread.join() | ||
self.is_running = False | ||
print("Momo stopped") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,4 +16,6 @@ packaging==24.1 | |
pluggy==1.5.0 | ||
# via pytest | ||
pytest==8.3.2 | ||
# via pytest-timeout | ||
pytest-timeout==2.3.1 | ||
ruff==0.6.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,5 @@ packaging==24.1 | |
pluggy==1.5.0 | ||
# via pytest | ||
pytest==8.3.2 | ||
# via pytest-timeout | ||
pytest-timeout==2.3.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import time | ||
|
||
from momo import Momo | ||
|
||
|
||
def test_start_and_stop(): | ||
with Momo() as momo: | ||
momo.start() | ||
|
||
time.sleep(3) | ||
|
||
momo.stop() |