diff --git a/.github/workflows/publish_pypi.yml b/.github/workflows/publish_pypi.yml index 427d281..f5a5d42 100644 --- a/.github/workflows/publish_pypi.yml +++ b/.github/workflows/publish_pypi.yml @@ -3,6 +3,30 @@ name: Publish Python 🐍 distribution 📦 to PyPI on: [push, pull_request] jobs: + test: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + python-version: ["3.9", "3.10", "3.11"] + package: ["happtiq_commons_gen_ai", "happtiq_commons_google_cloud"] + + steps: + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v3 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + cd packages/${{ matrix.package }} + python -m pip install --upgrade pip + pip install -e '.' + pip install -e '.[dev]' + - name: Test with pytest + run: | + cd packages/${{ matrix.package }} + pytest build: name: Build distribution 📦 runs-on: ubuntu-latest diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..c790e6a --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,32 @@ +# This workflow will install Python dependencies, run tests and lint with a variety of Python versions +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python + +name: Test with pytest + +on: [push, pull_request] + +jobs: + test: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + python-version: ["3.9", "3.10", "3.11"] + package: ["happtiq_commons_gen_ai", "happtiq_commons_google_cloud"] + + steps: + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v3 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + cd packages/${{ matrix.package }} + python -m pip install --upgrade pip + pip install -e '.' + pip install -e '.[dev]' + - name: Test with pytest + run: | + cd packages/${{ matrix.package }} + pytest diff --git a/packages/happtiq_commons_gen_ai/src/happtiq_commons_gen_ai/gemini_service.py b/packages/happtiq_commons_gen_ai/src/happtiq_commons_gen_ai/gemini_service.py index 691d3da..cac9639 100644 --- a/packages/happtiq_commons_gen_ai/src/happtiq_commons_gen_ai/gemini_service.py +++ b/packages/happtiq_commons_gen_ai/src/happtiq_commons_gen_ai/gemini_service.py @@ -32,3 +32,4 @@ def send_prompt_to_api(self, prompt: str) -> str: except Exception as e: self.logger.error(f"Error occurred while generating from gemini: {e}") raise + diff --git a/packages/happtiq_commons_gen_ai/tests/happtiq_commons_gen_ai/gemini_service_test.py b/packages/happtiq_commons_gen_ai/tests/happtiq_commons_gen_ai/gemini_service_test.py index 5cc1eb1..aff33a2 100644 --- a/packages/happtiq_commons_gen_ai/tests/happtiq_commons_gen_ai/gemini_service_test.py +++ b/packages/happtiq_commons_gen_ai/tests/happtiq_commons_gen_ai/gemini_service_test.py @@ -4,6 +4,7 @@ @pytest.fixture def vertex_ai_service(monkeypatch): + monkeypatch.setattr("google.auth.default", MagicMock(return_value=(MagicMock(),MagicMock()))) monkeypatch.setattr("vertexai.init", MagicMock()) return GeminiService(project_id="some-project", location="some-location", model_id="some-model") diff --git a/packages/happtiq_commons_google_cloud/tests/happtiq_commons_google_cloud/gcs_service_test.py b/packages/happtiq_commons_google_cloud/tests/happtiq_commons_google_cloud/gcs_service_test.py index 2ef5db4..370a147 100644 --- a/packages/happtiq_commons_google_cloud/tests/happtiq_commons_google_cloud/gcs_service_test.py +++ b/packages/happtiq_commons_google_cloud/tests/happtiq_commons_google_cloud/gcs_service_test.py @@ -3,7 +3,8 @@ from happtiq_commons_google_cloud.gcs_api_service import GcsApiService @pytest.fixture -def gcs_api_service(): +def gcs_api_service(monkeypatch): + monkeypatch.setattr("google.auth.default", MagicMock(return_value=(MagicMock(universe_domain="googleapis.com"),"some-proje"))) return GcsApiService(timeout=30) def mock_storage_client(): diff --git a/packages/happtiq_commons_google_cloud/tests/happtiq_commons_google_cloud/pubsub_api_service_test.py b/packages/happtiq_commons_google_cloud/tests/happtiq_commons_google_cloud/pubsub_api_service_test.py index cbff902..09e6b53 100644 --- a/packages/happtiq_commons_google_cloud/tests/happtiq_commons_google_cloud/pubsub_api_service_test.py +++ b/packages/happtiq_commons_google_cloud/tests/happtiq_commons_google_cloud/pubsub_api_service_test.py @@ -5,7 +5,8 @@ @pytest.fixture -def pubsub_api_service(): +def pubsub_api_service(monkeypatch): + monkeypatch.setattr("google.auth.default", MagicMock(return_value=(MagicMock(),"some-proje"))) return PubsubApiService() def test_publish_message(pubsub_api_service, monkeypatch): diff --git a/packages/happtiq_commons_google_cloud/tests/happtiq_commons_google_cloud/secret_manager_api_service_test.py b/packages/happtiq_commons_google_cloud/tests/happtiq_commons_google_cloud/secret_manager_api_service_test.py index a56b969..ca8d31d 100644 --- a/packages/happtiq_commons_google_cloud/tests/happtiq_commons_google_cloud/secret_manager_api_service_test.py +++ b/packages/happtiq_commons_google_cloud/tests/happtiq_commons_google_cloud/secret_manager_api_service_test.py @@ -3,7 +3,8 @@ from unittest.mock import MagicMock, patch @pytest.fixture -def secret_manager_api_service(): +def secret_manager_api_service(monkeypatch): + monkeypatch.setattr("google.auth.default", MagicMock(return_value=(MagicMock(),"some-proje"))) return SecretManagerApiService() def test_read_secret(secret_manager_api_service, monkeypatch):