Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronsteers committed Jan 26, 2024
1 parent 809918b commit 4a41ffb
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
8 changes: 2 additions & 6 deletions airbyte-lib/airbyte_lib/_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from collections.abc import Generator, Iterable, Iterator



_LATEST_VERSION = "latest"


Expand Down Expand Up @@ -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,
*,
Expand Down Expand Up @@ -254,7 +252,6 @@ def _get_installed_version(
def interpreter_path(self) -> Path:
return self._get_venv_path() / "bin" / "python"


def ensure_installation(
self,
*,
Expand Down Expand Up @@ -358,7 +355,6 @@ def get_telemetry_info(self) -> SourceTelemetryInfo:


class PathExecutor(Executor):

def __init__(
self,
name: str | None = None,
Expand Down Expand Up @@ -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,
)
4 changes: 2 additions & 2 deletions airbyte-lib/airbyte_lib/_factories/connector_factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion airbyte-lib/airbyte_lib/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 23 additions & 3 deletions airbyte-lib/tests/integration_tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from unittest.mock import Mock, call, patch
import tempfile
from pathlib import Path
import pip

from sqlalchemy import column, text

Expand Down Expand Up @@ -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"})
Expand Down

0 comments on commit 4a41ffb

Please sign in to comment.