Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 45
Add python sdk unit tests and ci#214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
be007e5c6186bbbe29ded6752dbbFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| name: Python SDK Tests | ||
| on: | ||
| push: | ||
| branches: [main] | ||
| paths: | ||
| - 'python-sdk/**' | ||
| pull_request: | ||
| branches: [main] | ||
| paths: | ||
| - 'python-sdk/**' | ||
NiveditJain marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| jobs: | ||
| test: | ||
| runs-on: ubuntu-latest | ||
NiveditJain marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
| - name: Set up Python | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: '3.12' | ||
| - name: Install uv | ||
| uses: astral-sh/setup-uv@v2 | ||
| with: | ||
| cache: true | ||
| - name: Install dev dependencies with uv | ||
| working-directory: python-sdk | ||
| run: | | ||
| uv sync --group dev | ||
| - name: Install python-sdk package (editable) | ||
| working-directory: python-sdk | ||
| run: | | ||
| uv pip install -e . | ||
NiveditJain marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| - name: Run tests with pytest and coverage | ||
| working-directory: python-sdk | ||
| run: | | ||
| uv run pytest --cov=exospherehost --cov-report=xml --cov-report=term-missing -v --junitxml=pytest-report.xml | ||
NiveditJain marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| - name: Upload coverage reports to Codecov | ||
| uses: codecov/codecov-action@v5 | ||
| with: | ||
| token: ${{ secrets.CODECOV_TOKEN }} | ||
| slug: exospherehost/exospherehost | ||
| files: python-sdk/coverage.xml | ||
| flags: python-sdk-unittests | ||
| name: python-sdk-coverage-report | ||
| fail_ci_if_error: true | ||
NiveditJain marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| - name: Upload test results | ||
| uses: actions/upload-artifact@v4 | ||
| if: always() | ||
| with: | ||
| name: python-sdk-test-results | ||
| path: python-sdk/pytest-report.xml | ||
| retention-days: 30 | ||
NiveditJain marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| from exospherehost.node.BaseNode import BaseNode | ||
| from pydantic import BaseModel | ||
| import asyncio | ||
| class EchoNode(BaseNode): | ||
| class Inputs(BaseModel): | ||
| text: str | ||
NiveditJain marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| class Outputs(BaseModel): | ||
| message: str | ||
NiveditJain marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| class Secrets(BaseModel): | ||
| token: str | ||
NiveditJain marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| async def execute(self) -> Outputs: | ||
| return self.Outputs(message=f"{self.inputs.text}:{self.secrets.token}") | ||
NiveditJain marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| def test_base_node_execute_sets_inputs_and_returns_outputs(): | ||
| node = EchoNode() | ||
| inputs = EchoNode.Inputs(text="hello") | ||
| secrets = EchoNode.Secrets(token="tkn") | ||
| outputs = asyncio.run(node._execute(inputs, secrets)) | ||
| assert isinstance(outputs, EchoNode.Outputs) | ||
| assert outputs.message == "hello:tkn" | ||
| assert node.inputs == inputs | ||
| assert node.secrets == secrets | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| import pytest | ||
| from pydantic import BaseModel | ||
| from exospherehost.runtime import Runtime | ||
| from exospherehost.node.BaseNode import BaseNode | ||
| class GoodNode(BaseNode): | ||
| class Inputs(BaseModel): | ||
| name: str | ||
| class Outputs(BaseModel): | ||
| message: str | ||
| class Secrets(BaseModel): | ||
| api_key: str | ||
| async def execute(self): | ||
| return self.Outputs(message=f"hi {self.inputs.name}") | ||
| class BadNodeWrongInputsBase(BaseNode): | ||
| Inputs = object # not a pydantic BaseModel | ||
| class Outputs(BaseModel): | ||
| message: str | ||
| class Secrets(BaseModel): | ||
| token: str | ||
| async def execute(self): | ||
| return self.Outputs(message="x") | ||
| class BadNodeWrongTypes(BaseNode): | ||
| class Inputs(BaseModel): | ||
| count: int | ||
| class Outputs(BaseModel): | ||
| ok: bool | ||
| class Secrets(BaseModel): | ||
| secret: bytes | ||
| async def execute(self): | ||
| return self.Outputs(ok=True) | ||
| def test_runtime_missing_config_raises(monkeypatch): | ||
| # Ensure env vars not set | ||
| monkeypatch.delenv("EXOSPHERE_STATE_MANAGER_URI", raising=False) | ||
| monkeypatch.delenv("EXOSPHERE_API_KEY", raising=False) | ||
| with pytest.raises(ValueError): | ||
| Runtime(namespace="ns", name="rt", nodes=[GoodNode]) | ||
NiveditJain marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| def test_runtime_with_env_ok(monkeypatch): | ||
| monkeypatch.setenv("EXOSPHERE_STATE_MANAGER_URI", "http://sm") | ||
| monkeypatch.setenv("EXOSPHERE_API_KEY", "k") | ||
| rt = Runtime(namespace="ns", name="rt", nodes=[GoodNode]) | ||
| assert rt is not None | ||
| def test_runtime_invalid_params_raises(monkeypatch): | ||
| monkeypatch.setenv("EXOSPHERE_STATE_MANAGER_URI", "http://sm") | ||
| monkeypatch.setenv("EXOSPHERE_API_KEY", "k") | ||
| with pytest.raises(ValueError): | ||
| Runtime(namespace="ns", name="rt", nodes=[GoodNode], batch_size=0) | ||
| with pytest.raises(ValueError): | ||
| Runtime(namespace="ns", name="rt", nodes=[GoodNode], workers=0) | ||
| def test_node_validation_errors(monkeypatch): | ||
| monkeypatch.setenv("EXOSPHERE_STATE_MANAGER_URI", "http://sm") | ||
| monkeypatch.setenv("EXOSPHERE_API_KEY", "k") | ||
| with pytest.raises(ValueError) as e: | ||
| Runtime(namespace="ns", name="rt", nodes=[BadNodeWrongInputsBase]) | ||
| assert "Inputs class that inherits" in str(e.value) | ||
| with pytest.raises(ValueError) as e2: | ||
| Runtime(namespace="ns", name="rt", nodes=[BadNodeWrongTypes]) | ||
| msg = str(e2.value) | ||
| assert "Inputs field" in msg and "Outputs field" in msg and "Secrets field" in msg | ||
NiveditJain marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| def test_duplicate_node_names_raise(monkeypatch): | ||
| monkeypatch.setenv("EXOSPHERE_STATE_MANAGER_URI", "http://sm") | ||
| monkeypatch.setenv("EXOSPHERE_API_KEY", "k") | ||
| class AnotherGood(BaseNode): | ||
| class Inputs(BaseModel): | ||
| name: str | ||
| class Outputs(BaseModel): | ||
| message: str | ||
| class Secrets(BaseModel): | ||
| api_key: str | ||
| async def execute(self): | ||
| return self.Outputs(message="ok") | ||
| AnotherGood.__name__ = "GoodNode" # force duplicate name | ||
| with pytest.raises(ValueError): | ||
| Runtime(namespace="ns", name="rt", nodes=[GoodNode, AnotherGood]) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import pytest | ||
| import asyncio | ||
| from exospherehost.statemanager import StateManager, TriggerState | ||
| def test_trigger_requires_either_state_or_states(monkeypatch): | ||
| monkeypatch.setenv("EXOSPHERE_STATE_MANAGER_URI", "http://sm") | ||
| monkeypatch.setenv("EXOSPHERE_API_KEY", "k") | ||
| sm = StateManager(namespace="ns") | ||
| with pytest.raises(ValueError): | ||
| asyncio.run(sm.trigger("g")) | ||
| def test_trigger_rejects_both_state_and_states(monkeypatch): | ||
| monkeypatch.setenv("EXOSPHERE_STATE_MANAGER_URI", "http://sm") | ||
| monkeypatch.setenv("EXOSPHERE_API_KEY", "k") | ||
| sm = StateManager(namespace="ns") | ||
| state = TriggerState(identifier="id", inputs={}) | ||
| with pytest.raises(ValueError): | ||
| asyncio.run(sm.trigger("g", state=state, states=[state])) | ||
| def test_trigger_rejects_empty_states_list(monkeypatch): | ||
| monkeypatch.setenv("EXOSPHERE_STATE_MANAGER_URI", "http://sm") | ||
| monkeypatch.setenv("EXOSPHERE_API_KEY", "k") | ||
| sm = StateManager(namespace="ns") | ||
| with pytest.raises(ValueError): | ||
| asyncio.run(sm.trigger("g", states=[])) |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.