From 4a41ffb14162e649b7d42455fd5fd52dca8a570f Mon Sep 17 00:00:00 2001 From: Aaron Steers Date: Fri, 26 Jan 2024 15:57:08 -0800 Subject: [PATCH] fix tests --- airbyte-lib/airbyte_lib/_executor.py | 8 ++---- .../_factories/connector_factories.py | 4 +-- airbyte-lib/airbyte_lib/source.py | 1 - .../integration_tests/test_integration.py | 26 ++++++++++++++++--- 4 files changed, 27 insertions(+), 12 deletions(-) diff --git a/airbyte-lib/airbyte_lib/_executor.py b/airbyte-lib/airbyte_lib/_executor.py index 355df286fc67..801d02361282 100644 --- a/airbyte-lib/airbyte_lib/_executor.py +++ b/airbyte-lib/airbyte_lib/_executor.py @@ -18,7 +18,6 @@ from collections.abc import Generator, Iterable, Iterator - _LATEST_VERSION = "latest" @@ -202,7 +201,6 @@ def install(self) -> None: # Assuming the installation succeeded, store the installed version self.reported_version = self._get_installed_version(raise_on_error=False, recheck=True) - def _get_installed_version( self, *, @@ -254,7 +252,6 @@ def _get_installed_version( def interpreter_path(self) -> Path: return self._get_venv_path() / "bin" / "python" - def ensure_installation( self, *, @@ -358,7 +355,6 @@ def get_telemetry_info(self) -> SourceTelemetryInfo: class PathExecutor(Executor): - def __init__( self, name: str | None = None, @@ -408,12 +404,12 @@ def uninstall(self) -> NoReturn: ) def execute(self, args: list[str]) -> Iterator[str]: - with _stream_from_subprocess([self.path, *args]) as stream: + with _stream_from_subprocess([str(self.path), *args]) as stream: yield from stream def get_telemetry_info(self) -> SourceTelemetryInfo: return SourceTelemetryInfo( - self.path, + str(self.name), SourceType.LOCAL_INSTALL, version=self.reported_version, ) diff --git a/airbyte-lib/airbyte_lib/_factories/connector_factories.py b/airbyte-lib/airbyte_lib/_factories/connector_factories.py index 322305c48893..197ed61142c6 100644 --- a/airbyte-lib/airbyte_lib/_factories/connector_factories.py +++ b/airbyte-lib/airbyte_lib/_factories/connector_factories.py @@ -3,10 +3,10 @@ import shutil from pathlib import Path -from typing import TYPE_CHECKING, Any +from typing import Any from airbyte_lib import exceptions as exc -from airbyte_lib._executor import Executor, PathExecutor, VenvExecutor +from airbyte_lib._executor import PathExecutor, VenvExecutor from airbyte_lib.registry import ConnectorMetadata, get_connector_metadata from airbyte_lib.source import Source diff --git a/airbyte-lib/airbyte_lib/source.py b/airbyte-lib/airbyte_lib/source.py index fda00928bdd0..ee58286b6d06 100644 --- a/airbyte-lib/airbyte_lib/source.py +++ b/airbyte-lib/airbyte_lib/source.py @@ -2,7 +2,6 @@ from __future__ import annotations import json -from pathlib import Path import tempfile from contextlib import contextmanager, suppress from typing import TYPE_CHECKING, Any diff --git a/airbyte-lib/tests/integration_tests/test_integration.py b/airbyte-lib/tests/integration_tests/test_integration.py index 5d626d654035..3e474ac3eff2 100644 --- a/airbyte-lib/tests/integration_tests/test_integration.py +++ b/airbyte-lib/tests/integration_tests/test_integration.py @@ -7,6 +7,7 @@ from unittest.mock import Mock, call, patch import tempfile from pathlib import Path +import pip from sqlalchemy import column, text @@ -57,17 +58,36 @@ def expected_test_stream_data() -> dict[str, list[dict[str, str | int]]]: } def test_list_streams(expected_test_stream_data: dict[str, list[dict[str, str | int]]]): - source = ab.get_connector("source-test", config={"apiKey": "test"}) - + source = ab.get_connector( + "source-test", config={"apiKey": "test"}, install_if_missing=False + ) assert source.get_available_streams() == list(expected_test_stream_data.keys()) def test_invalid_config(): - source = ab.get_connector("source-test", config={"apiKey": 1234}) + source = ab.get_connector( + "source-test", config={"apiKey": 1234}, install_if_missing=False + ) with pytest.raises(exc.AirbyteConnectorCheckFailedError): source.check() +def test_ensure_installation_detection(): + """Assert that install isn't called, since the connector is already installed by the fixture.""" + with patch("airbyte_lib._executor.VenvExecutor.install") as mock_venv_install, \ + patch("airbyte_lib.source.Source.install") as mock_source_install, \ + patch("airbyte_lib._executor.VenvExecutor.ensure_installation") as mock_ensure_installed: + source = ab.get_connector( + "source-test", + config={"apiKey": 1234}, + pip_url="https://pypi.org/project/airbyte-not-found", + install_if_missing=True, + ) + assert mock_ensure_installed.call_count == 1 + assert not mock_venv_install.called + assert not mock_source_install.called + + def test_non_existing_connector(): with pytest.raises(Exception): ab.get_connector("source-not-existing", config={"apiKey": "abc"})