Skip to content

Commit

Permalink
Support testing extension
Browse files Browse the repository at this point in the history
  • Loading branch information
Wh1isper committed Dec 11, 2023
1 parent d498a84 commit a8d6d03
Show file tree
Hide file tree
Showing 11 changed files with 158 additions and 6 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/extension.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Testing example extensions

on:
push:
branches: ["master", "main"]
pull_request:
branches: ["master", "main"]

jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.11"]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -e .[test]
- name: Install all packages in example/extension
run: |
python -m pip install -e example/extension/dummydataconnector[test]
python -m pip install -e example/extension/dummydataprocessor[test]
python -m pip install -e example/extension/dummymodel[test]
- name: Test with pytest
run: |
pytest -vv example/extension
5 changes: 3 additions & 2 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -e .[test]
- name: Test with pytest
run: |
pytest -vv --cov=sdgx
pytest -vv --cov=sdgx tests
- name: Install dependencies for building
run: |
pip install build twine hatch
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "0.1.0"
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from __future__ import annotations

from sdgx.data_connectors.base import DataConnector


class MyOwnDataConnector(DataConnector):
...


from sdgx.data_connectors.extension import hookimpl


@hookimpl
def register(manager):
manager.register("DummyDataConnector", MyOwnDataConnector)
27 changes: 27 additions & 0 deletions example/extension/dummydataconnector/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "dummydataconnector"
dependencies = ["sdgx"]
dynamic = ["version"]
requires-python = ">=3.8"
classifiers = [
"Programming Language :: Python :: 3",
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
]
[project.optional-dependencies]
test = ["pytest"]

[tool.check-manifest]
ignore = [".*"]

[tool.hatch.version]
path = "dummydataconnector/__init__.py"

[project.entry-points."sdgx.data_connector"]
dummydataconnector = "dummydataconnector.dataconnector"
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import pytest

from sdgx.data_connectors.manager import DataConnectorManager


@pytest.fixture
def manager():
yield DataConnectorManager()


def test_registed_data_connector(manager: DataConnectorManager):
assert "DummyDataConnector" in manager.registed_data_connectors
manager.init_data_connector("DummyDataConnector")


if __name__ == "__main__":
pytest.main(["-vv", "-s", __file__])
15 changes: 13 additions & 2 deletions example/extension/dummydataprocessor/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,25 @@ requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "sdgx-dummymdataprocessor"
name = "dummydataprocessor"

dependencies = ["sdgx"]
dynamic = ["version"]
requires-python = ">=3.8"
classifiers = [
"Programming Language :: Python :: 3",
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
]

[project.optional-dependencies]
test = ["pytest"]

# This is the entry point for the Manager to find the extension.
[project.entry-points."sdgx.data_processor"]
dummydataprocessor = "dummydataprocessor.model"
dummydataprocessor = "dummydataprocessor.dataprocessor"

[tool.hatch.version]
path = "dummydataprocessor/__init__.py"
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import pytest

from sdgx.data_processors.manager import DataProcessorManager


@pytest.fixture
def manager():
yield DataProcessorManager()


def test_registed_data_processor(manager: DataProcessorManager):
assert "DummyDataProcessor" in manager.registed_data_processors
manager.init_data_processors("DummyDataProcessor")


if __name__ == "__main__":
pytest.main(["-vv", "-s", __file__])
13 changes: 12 additions & 1 deletion example/extension/dummymodel/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,21 @@ requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "sdgx-dummymodel"
name = "dummymodel"

dependencies = ["sdgx"]
dynamic = ["version"]
requires-python = ">=3.8"
classifiers = [
"Programming Language :: Python :: 3",
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
]

[project.optional-dependencies]
test = ["pytest"]

# This is the entry point for the Manager to find the extension.
[project.entry-points."sdgx.model"]
Expand Down
17 changes: 17 additions & 0 deletions example/extension/dummymodel/tests/test_registed_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import pytest

from sdgx.models.manager import ModelManager


@pytest.fixture
def manager():
yield ModelManager()


def test_registed_model(manager: ModelManager):
assert "DummyModel" in manager.registed_models
manager.init_model("DummyModel")


if __name__ == "__main__":
pytest.main(["-vv", "-s", __file__])
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ build-backend = "hatchling.build"
[project]
name = "sdgx"
description = "synthetic-data-generator"
keywords = ["sdg", "hitsz-ids"]
keywords = ["synthetic data", "hitsz-ids"]
requires-python = ">=3.8"

dependencies = [
Expand Down

0 comments on commit a8d6d03

Please sign in to comment.