Skip to content

Commit

Permalink
色々変える
Browse files Browse the repository at this point in the history
  • Loading branch information
voluntas committed Nov 6, 2024
1 parent 91e8add commit 5a66299
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 12 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,7 @@ __pycache__

# vscode
build

# .env
.env
!.env.template
4 changes: 4 additions & 0 deletions test/.env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
TEST_SIGNALING_URLS=wss://sora.example.com/signaling
TEST_CHANNEL_ID_PREFIX=momo_
TEST_SECRET_KEY=secret
TEST_API_URL=https://sora.example.com/api
36 changes: 36 additions & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import os

import pytest
from dotenv import load_dotenv


@pytest.fixture
def setup():
# 環境変数読み込み
load_dotenv()

# signaling_url 単体か複数かをランダムで決めてテストする
if (test_signaling_urls := os.environ.get("TEST_SIGNALING_URLS")) is None:
raise ValueError("TEST_SIGNALING_URLS is required.")

# , で区切って ['wss://...', ...] に変換
test_signaling_urls = test_signaling_urls.split(",")

if (test_channel_id_prefix := os.environ.get("TEST_CHANNEL_ID_PREFIX")) is None:
raise ValueError("TEST_CHANNEL_ID_PREFIX is required.")

if (test_secret_key := os.environ.get("TEST_SECRET_KEY")) is None:
raise ValueError("TEST_SECRET_KEY is required.")

# if (test_api_url := os.environ.get("TEST_API_URL")) is None:
# raise ValueError("TEST_API_URL is required.")

return {
"signaling_urls": test_signaling_urls,
"channel_id_prefix": test_channel_id_prefix,
# "secret": test_secret_key,
# "api_url": test_api_url,
"metadata": {"access_token": test_secret_key},
# openh264_path は str | None でよい
# "openh264_path": os.environ.get("OPENH264_PATH"),
}
33 changes: 27 additions & 6 deletions test/momo.py → test/momo_sora.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import sys
import threading
import time
import uuid
from pathlib import Path

# プラットフォームに応じたリリースディレクトリの設定
Expand All @@ -22,11 +23,27 @@


class Momo:
def __init__(self, mode="test", port=5000):
signaling_urls: list[str]
channel_id_prefix: str
secret_key: str
port: int

def __init__(
self,
signaling_urls: list[str],
channel_id_prefix: str,
metadata: dict[str, str],
):
self.signaling_urls = signaling_urls
self.channel_id_prefix = channel_id_prefix
self.metadata = metadata

self.channel_id = f"{self.channel_id_prefix}_{uuid.uuid4()}"

self.port = 5000

self.executable = RELEASE_DIR / "momo"
assert self.executable.exists()
self.mode = mode
self.port = port
self.process = None
self.thread = None
self.is_running = False
Expand All @@ -38,14 +55,18 @@ def __exit__(self, exc_type, exc_val, exc_tb):
self.stop()

def run_app(self):
print(self.executable)

args = [
"sudo",
str(self.executable),
self.mode,
"sora",
"--port",
str(self.port),
"--signaling-urls",
",".join(self.signaling_urls),
"--channel-id",
self.channel_id_prefix,
"--secret-key",
self.secret_key,
"--video-device",
# これは GitHub Actions 用
"VCamera",
Expand Down
8 changes: 6 additions & 2 deletions test/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@
name = "momo-e2e-test"
version = "2013.3.8"
requires-python = ">= 3.12"
dependencies = ["pytest>=8.3", "pytest-timeout>=2.3"]
dependencies = [
"pytest>=8.3",
"pytest-timeout>=2.3",
"python-dotenv>=1.0",
]

[tool.uv]
package = false
managed = true
dev-dependencies = ["ruff>=0.6"]
dev-dependencies = ["ruff"]

[tool.pytest.ini_options]
timeout = 45
Expand Down
6 changes: 3 additions & 3 deletions test/test_momo.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import time

from momo import Momo
from momo_sora import Momo


def test_start_and_stop():
with Momo() as momo:
def test_start_and_stop(setup):
with Momo(**setup) as momo:
momo.start()

time.sleep(3)
Expand Down
13 changes: 12 additions & 1 deletion test/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5a66299

Please sign in to comment.