-
Notifications
You must be signed in to change notification settings - Fork 43
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
Changes from 2 commits
be007e5
c6186bb
be29ded
6752dbb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. send report to codecov also, like we are doing in api-server |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| name: Python SDK Tests | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main] | ||
| paths: | ||
| - 'python-sdk/**' | ||
| pull_request: | ||
| branches: [main] | ||
| paths: | ||
| - 'python-sdk/**' | ||
|
NiveditJain marked this conversation as resolved.
|
||
|
|
||
| jobs: | ||
| test: | ||
| runs-on: ubuntu-latest | ||
|
NiveditJain marked this conversation as resolved.
|
||
| 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: 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.
|
||
| - 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.
|
||
| - 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.
|
||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why this file? we don't need it
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @cursoragent remove this file There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
Large diffs are not rendered by default.
| 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 | ||
|
|
||
| class Outputs(BaseModel): | ||
| message: str | ||
|
|
||
| class Secrets(BaseModel): | ||
| token: str | ||
|
|
||
| async def execute(self) -> Outputs: | ||
| return self.Outputs(message=f"{self.inputs.text}:{self.secrets.token}") | ||
|
|
||
|
|
||
| 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,96 @@ | ||
| import os | ||
| 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]) | ||
|
|
||
|
|
||
| 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 | ||
|
|
||
|
|
||
| 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.