diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b47733a9..48cc0f71 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -32,7 +32,7 @@ $ pip install -r requirements-dev.lock ## Modifying/Adding code Most of the SDK is generated code, and any modified code will be overridden on the next generation. The -`src/openlayer/lib/` and `examples/` directories are exceptions and will never be overridden. +`src/openlayer-test/lib/` and `examples/` directories are exceptions and will never be overridden. ## Adding and running examples diff --git a/README.md b/README.md index 108252df..c7ceb214 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Openlayer Python API library -[![PyPI version](https://img.shields.io/pypi/v/openlayer.svg)](https://pypi.org/project/openlayer/) +[![PyPI version](https://img.shields.io/pypi/v/openlayer-test.svg)](https://pypi.org/project/openlayer-test/) The Openlayer Python library provides convenient access to the Openlayer REST API from any Python 3.7+ application. The library includes type definitions for all request params and response fields, @@ -16,7 +16,7 @@ The REST API documentation can be found [on openlayer.com](https://openlayer.com ```sh # install from PyPI -pip install --pre openlayer +pip install --pre openlayer-test ``` ## Usage @@ -25,7 +25,7 @@ The full API of this library can be found in [api.md](api.md). ```python import os -from openlayer import Openlayer +from openlayer-test import Openlayer client = Openlayer( # This is the default and can be omitted @@ -41,15 +41,13 @@ data_stream_response = client.inference_pipelines.data.stream( "cost_column_name": "cost", "timestamp_column_name": "timestamp", }, - rows=[ - { - "user_query": "what's the meaning of life?", - "output": "42", - "tokens": 7, - "cost": 0.02, - "timestamp": 1620000000, - } - ], + rows=[{ + "user_query": "what's the meaning of life?", + "output": "42", + "tokens": 7, + "cost": 0.02, + "timestamp": 1620000000, + }], ) print(data_stream_response.success) ``` @@ -66,36 +64,32 @@ Simply import `AsyncOpenlayer` instead of `Openlayer` and use `await` with each ```python import os import asyncio -from openlayer import AsyncOpenlayer +from openlayer-test import AsyncOpenlayer client = AsyncOpenlayer( # This is the default and can be omitted api_key=os.environ.get("OPENLAYER_API_KEY"), ) - async def main() -> None: - data_stream_response = await client.inference_pipelines.data.stream( - "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", - config={ - "input_variable_names": ["user_query"], - "output_column_name": "output", - "num_of_token_column_name": "tokens", - "cost_column_name": "cost", - "timestamp_column_name": "timestamp", - }, - rows=[ - { - "user_query": "what's the meaning of life?", - "output": "42", - "tokens": 7, - "cost": 0.02, - "timestamp": 1620000000, - } - ], - ) - print(data_stream_response.success) - + data_stream_response = await client.inference_pipelines.data.stream( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", + config={ + "input_variable_names": ["user_query"], + "output_column_name": "output", + "num_of_token_column_name": "tokens", + "cost_column_name": "cost", + "timestamp_column_name": "timestamp", + }, + rows=[{ + "user_query": "what's the meaning of life?", + "output": "42", + "tokens": 7, + "cost": 0.02, + "timestamp": 1620000000, + }], + ) + print(data_stream_response.success) asyncio.run(main()) ``` @@ -113,16 +107,16 @@ Typed requests and responses provide autocomplete and documentation within your ## Handling errors -When the library is unable to connect to the API (for example, due to network connection problems or a timeout), a subclass of `openlayer.APIConnectionError` is raised. +When the library is unable to connect to the API (for example, due to network connection problems or a timeout), a subclass of `openlayer-test.APIConnectionError` is raised. When the API returns a non-success status code (that is, 4xx or 5xx -response), a subclass of `openlayer.APIStatusError` is raised, containing `status_code` and `response` properties. +response), a subclass of `openlayer-test.APIStatusError` is raised, containing `status_code` and `response` properties. -All errors inherit from `openlayer.APIError`. +All errors inherit from `openlayer-test.APIError`. ```python -import openlayer -from openlayer import Openlayer +import openlayer-test +from openlayer-test import Openlayer client = Openlayer() @@ -136,22 +130,20 @@ try: "cost_column_name": "cost", "timestamp_column_name": "timestamp", }, - rows=[ - { - "user_query": "what's the meaning of life?", - "output": "42", - "tokens": 7, - "cost": 0.02, - "timestamp": 1620000000, - } - ], + rows=[{ + "user_query": "what's the meaning of life?", + "output": "42", + "tokens": 7, + "cost": 0.02, + "timestamp": 1620000000, + }], ) -except openlayer.APIConnectionError as e: +except openlayer-test.APIConnectionError as e: print("The server could not be reached") - print(e.__cause__) # an underlying Exception, likely raised within httpx. -except openlayer.RateLimitError as e: + print(e.__cause__) # an underlying Exception, likely raised within httpx. +except openlayer-test.RateLimitError as e: print("A 429 status code was received; we should back off a bit.") -except openlayer.APIStatusError as e: +except openlayer-test.APIStatusError as e: print("Another non-200-range status code was received") print(e.status_code) print(e.response) @@ -179,7 +171,7 @@ Connection errors (for example, due to a network connectivity problem), 408 Requ You can use the `max_retries` option to configure or disable retry settings: ```python -from openlayer import Openlayer +from openlayer-test import Openlayer # Configure the default for all requests: client = Openlayer( @@ -188,7 +180,7 @@ client = Openlayer( ) # Or, configure per-request: -client.with_options(max_retries=5).inference_pipelines.data.stream( +client.with_options(max_retries = 5).inference_pipelines.data.stream( "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", config={ "input_variable_names": ["user_query"], @@ -197,15 +189,13 @@ client.with_options(max_retries=5).inference_pipelines.data.stream( "cost_column_name": "cost", "timestamp_column_name": "timestamp", }, - rows=[ - { - "user_query": "what's the meaning of life?", - "output": "42", - "tokens": 7, - "cost": 0.02, - "timestamp": 1620000000, - } - ], + rows=[{ + "user_query": "what's the meaning of life?", + "output": "42", + "tokens": 7, + "cost": 0.02, + "timestamp": 1620000000, + }], ) ``` @@ -215,7 +205,7 @@ By default requests time out after 1 minute. You can configure this with a `time which accepts a float or an [`httpx.Timeout`](https://www.python-httpx.org/advanced/#fine-tuning-the-configuration) object: ```python -from openlayer import Openlayer +from openlayer-test import Openlayer # Configure the default for all requests: client = Openlayer( @@ -229,7 +219,7 @@ client = Openlayer( ) # Override per-request: -client.with_options(timeout=5.0).inference_pipelines.data.stream( +client.with_options(timeout = 5.0).inference_pipelines.data.stream( "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", config={ "input_variable_names": ["user_query"], @@ -238,15 +228,13 @@ client.with_options(timeout=5.0).inference_pipelines.data.stream( "cost_column_name": "cost", "timestamp_column_name": "timestamp", }, - rows=[ - { - "user_query": "what's the meaning of life?", - "output": "42", - "tokens": 7, - "cost": 0.02, - "timestamp": 1620000000, - } - ], + rows=[{ + "user_query": "what's the meaning of life?", + "output": "42", + "tokens": 7, + "cost": 0.02, + "timestamp": 1620000000, + }], ) ``` @@ -283,7 +271,7 @@ if response.my_field is None: The "raw" Response object can be accessed by prefixing `.with_raw_response.` to any HTTP method call, e.g., ```py -from openlayer import Openlayer +from openlayer-test import Openlayer client = Openlayer() response = client.inference_pipelines.data.with_raw_response.stream( @@ -309,9 +297,9 @@ data = response.parse() # get the object that `inference_pipelines.data.stream( print(data.success) ``` -These methods return an [`APIResponse`](https://github.com/openlayer-ai/openlayer-python/tree/main/src/openlayer/_response.py) object. +These methods return an [`APIResponse`](https://github.com/openlayer-ai/openlayer-python/tree/main/src/openlayer-test/_response.py) object. -The async client returns an [`AsyncAPIResponse`](https://github.com/openlayer-ai/openlayer-python/tree/main/src/openlayer/_response.py) with the same structure, the only difference being `await`able methods for reading the response content. +The async client returns an [`AsyncAPIResponse`](https://github.com/openlayer-ai/openlayer-python/tree/main/src/openlayer-test/_response.py) with the same structure, the only difference being `await`able methods for reading the response content. #### `.with_streaming_response` @@ -329,20 +317,18 @@ with client.inference_pipelines.data.with_streaming_response.stream( "cost_column_name": "cost", "timestamp_column_name": "timestamp", }, - rows=[ - { - "user_query": "what's the meaning of life?", - "output": "42", - "tokens": 7, - "cost": 0.02, - "timestamp": 1620000000, - } - ], -) as response: - print(response.headers.get("X-My-Header")) + rows=[{ + "user_query": "what's the meaning of life?", + "output": "42", + "tokens": 7, + "cost": 0.02, + "timestamp": 1620000000, + }], +) as response : + print(response.headers.get('X-My-Header')) for line in response.iter_lines(): - print(line) + print(line) ``` The context manager is required so that the response will reliably be closed. @@ -391,15 +377,12 @@ You can directly override the [httpx client](https://www.python-httpx.org/api/#c - Additional [advanced](https://www.python-httpx.org/advanced/#client-instances) functionality ```python -from openlayer import Openlayer, DefaultHttpxClient +from openlayer-test import Openlayer, DefaultHttpxClient client = Openlayer( # Or use the `OPENLAYER_BASE_URL` env var base_url="http://my.test.server.example.com:8083", - http_client=DefaultHttpxClient( - proxies="http://my.test.proxy.example.com", - transport=httpx.HTTPTransport(local_address="0.0.0.0"), - ), + http_client=DefaultHttpxClient(proxies="http://my.test.proxy.example.com", transport=httpx.HTTPTransport(local_address="0.0.0.0")), ) ``` diff --git a/api.md b/api.md index 6a11c669..5949d339 100644 --- a/api.md +++ b/api.md @@ -3,36 +3,36 @@ Types: ```python -from openlayer.types import ProjectListResponse +from openlayer-test.types import ProjectListResponse ``` Methods: -- client.projects.list(\*\*params) -> ProjectListResponse +- client.projects.list(\*\*params) -> ProjectListResponse ## Commits Types: ```python -from openlayer.types.projects import CommitListResponse +from openlayer-test.types.projects import CommitListResponse ``` Methods: -- client.projects.commits.list(id, \*\*params) -> CommitListResponse +- client.projects.commits.list(id, \*\*params) -> CommitListResponse ## InferencePipelines Types: ```python -from openlayer.types.projects import InferencePipelineListResponse +from openlayer-test.types.projects import InferencePipelineListResponse ``` Methods: -- client.projects.inference_pipelines.list(id, \*\*params) -> InferencePipelineListResponse +- client.projects.inference_pipelines.list(id, \*\*params) -> InferencePipelineListResponse # Commits @@ -41,12 +41,12 @@ Methods: Types: ```python -from openlayer.types.commits import TestResultListResponse +from openlayer-test.types.commits import TestResultListResponse ``` Methods: -- client.commits.test_results.list(id, \*\*params) -> TestResultListResponse +- client.commits.test_results.list(id, \*\*params) -> TestResultListResponse # InferencePipelines @@ -55,21 +55,21 @@ Methods: Types: ```python -from openlayer.types.inference_pipelines import DataStreamResponse +from openlayer-test.types.inference_pipelines import DataStreamResponse ``` Methods: -- client.inference_pipelines.data.stream(id, \*\*params) -> DataStreamResponse +- client.inference_pipelines.data.stream(id, \*\*params) -> DataStreamResponse ## TestResults Types: ```python -from openlayer.types.inference_pipelines import TestResultListResponse +from openlayer-test.types.inference_pipelines import TestResultListResponse ``` Methods: -- client.inference_pipelines.test_results.list(id, \*\*params) -> TestResultListResponse +- client.inference_pipelines.test_results.list(id, \*\*params) -> TestResultListResponse diff --git a/mypy.ini b/mypy.ini index 20794fe4..bccb2c92 100644 --- a/mypy.ini +++ b/mypy.ini @@ -5,7 +5,7 @@ show_error_codes = True # Exclude _files.py because mypy isn't smart enough to apply # the correct type narrowing and as this is an internal module # it's fine to just use Pyright. -exclude = ^(src/openlayer/_files\.py|_dev/.*\.py)$ +exclude = ^(src/openlayer-test/_files\.py|_dev/.*\.py)$ strict_equality = True implicit_reexport = True diff --git a/pyproject.toml b/pyproject.toml index 80e547bc..e4c448f0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [project] -name = "openlayer" +name = "openlayer-test" version = "0.1.0-alpha.4" description = "The official Python library for the openlayer API" dynamic = ["readme"] @@ -84,7 +84,7 @@ typecheck = { chain = [ "typecheck:mypy" ]} "typecheck:pyright" = "pyright" -"typecheck:verify-types" = "pyright --verifytypes openlayer --ignoreexternal" +"typecheck:verify-types" = "pyright --verifytypes openlayer-test --ignoreexternal" "typecheck:mypy" = "mypy ." [build-system] @@ -97,7 +97,7 @@ include = [ ] [tool.hatch.build.targets.wheel] -packages = ["src/openlayer"] +packages = ["src/openlayer-test"] [tool.hatch.metadata.hooks.fancy-pypi-readme] content-type = "text/markdown" @@ -187,7 +187,7 @@ length-sort = true length-sort-straight = true combine-as-imports = true extra-standard-library = ["typing_extensions"] -known-first-party = ["openlayer", "tests"] +known-first-party = ["openlayer-test", "tests"] [tool.ruff.per-file-ignores] "bin/**.py" = ["T201", "T203"] diff --git a/release-please-config.json b/release-please-config.json index 83a417a7..b474b872 100644 --- a/release-please-config.json +++ b/release-please-config.json @@ -61,6 +61,6 @@ ], "release-type": "python", "extra-files": [ - "src/openlayer/_version.py" + "src/openlayer-test/_version.py" ] } \ No newline at end of file diff --git a/requirements-dev.lock b/requirements-dev.lock index 26451e23..6a8433ee 100644 --- a/requirements-dev.lock +++ b/requirements-dev.lock @@ -12,7 +12,7 @@ annotated-types==0.6.0 # via pydantic anyio==4.1.0 # via httpx - # via openlayer + # via openlayer-test argcomplete==3.1.2 # via nox attrs==23.1.0 @@ -26,7 +26,7 @@ dirty-equals==0.6.0 distlib==0.3.7 # via virtualenv distro==1.8.0 - # via openlayer + # via openlayer-test exceptiongroup==1.1.3 # via anyio filelock==3.12.4 @@ -36,7 +36,7 @@ h11==0.14.0 httpcore==1.0.2 # via httpx httpx==0.25.2 - # via openlayer + # via openlayer-test # via respx idna==3.4 # via anyio @@ -60,7 +60,7 @@ pluggy==1.3.0 py==1.11.0 # via pytest pydantic==2.7.1 - # via openlayer + # via openlayer-test pydantic-core==2.18.2 # via pydantic pyright==1.1.364 @@ -80,14 +80,14 @@ six==1.16.0 sniffio==1.3.0 # via anyio # via httpx - # via openlayer + # via openlayer-test time-machine==2.9.0 tomli==2.0.1 # via mypy # via pytest typing-extensions==4.8.0 # via mypy - # via openlayer + # via openlayer-test # via pydantic # via pydantic-core virtualenv==20.24.5 diff --git a/requirements.lock b/requirements.lock index 04f85d2e..4e5a36e4 100644 --- a/requirements.lock +++ b/requirements.lock @@ -12,12 +12,12 @@ annotated-types==0.6.0 # via pydantic anyio==4.1.0 # via httpx - # via openlayer + # via openlayer-test certifi==2023.7.22 # via httpcore # via httpx distro==1.8.0 - # via openlayer + # via openlayer-test exceptiongroup==1.1.3 # via anyio h11==0.14.0 @@ -25,19 +25,19 @@ h11==0.14.0 httpcore==1.0.2 # via httpx httpx==0.25.2 - # via openlayer + # via openlayer-test idna==3.4 # via anyio # via httpx pydantic==2.7.1 - # via openlayer + # via openlayer-test pydantic-core==2.18.2 # via pydantic sniffio==1.3.0 # via anyio # via httpx - # via openlayer + # via openlayer-test typing-extensions==4.8.0 - # via openlayer + # via openlayer-test # via pydantic # via pydantic-core diff --git a/scripts/bootstrap b/scripts/bootstrap index 29df07e7..8c5c60eb 100755 --- a/scripts/bootstrap +++ b/scripts/bootstrap @@ -16,4 +16,4 @@ echo "==> Installing Python dependencies…" # experimental uv support makes installations significantly faster rye config --set-bool behavior.use-uv=true -rye sync +rye sync --all-features diff --git a/scripts/lint b/scripts/lint index 763eb089..4595e5de 100755 --- a/scripts/lint +++ b/scripts/lint @@ -8,5 +8,5 @@ echo "==> Running lints" rye run lint echo "==> Making sure it imports" -rye run python -c 'import openlayer' +rye run python -c 'import openlayer-test' diff --git a/src/openlayer/__init__.py b/src/openlayer-test/__init__.py similarity index 89% rename from src/openlayer/__init__.py rename to src/openlayer-test/__init__.py index e2047e6c..d7221ba8 100644 --- a/src/openlayer/__init__.py +++ b/src/openlayer-test/__init__.py @@ -1,41 +1,41 @@ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. from . import types -from ._types import NOT_GIVEN, NoneType, NotGiven, Transport, ProxiesTypes -from ._utils import file_from_path +from ._version import __version__, __title__ from ._client import ( - Client, - Stream, Timeout, - Openlayer, Transport, + RequestOptions, + Client, AsyncClient, + Stream, AsyncStream, + Openlayer, AsyncOpenlayer, - RequestOptions, ) -from ._models import BaseModel -from ._version import __title__, __version__ -from ._response import APIResponse as APIResponse, AsyncAPIResponse as AsyncAPIResponse -from ._constants import DEFAULT_TIMEOUT, DEFAULT_MAX_RETRIES, DEFAULT_CONNECTION_LIMITS from ._exceptions import ( + OpenlayerError, APIError, - ConflictError, - NotFoundError, APIStatusError, - OpenlayerError, - RateLimitError, APITimeoutError, - BadRequestError, APIConnectionError, + APIResponseValidationError, + BadRequestError, AuthenticationError, - InternalServerError, PermissionDeniedError, + NotFoundError, + ConflictError, UnprocessableEntityError, - APIResponseValidationError, + RateLimitError, + InternalServerError, ) +from ._types import NoneType, Transport, ProxiesTypes, NotGiven, NOT_GIVEN +from ._utils import file_from_path +from ._models import BaseModel +from ._constants import DEFAULT_TIMEOUT, DEFAULT_MAX_RETRIES, DEFAULT_CONNECTION_LIMITS from ._base_client import DefaultHttpxClient, DefaultAsyncHttpxClient from ._utils._logs import setup_logging as _setup_logging +from ._response import APIResponse as APIResponse, AsyncAPIResponse as AsyncAPIResponse __all__ = [ "types", @@ -82,12 +82,12 @@ # Update the __module__ attribute for exported symbols so that # error messages point to this module instead of the module # it was originally defined in, e.g. -# openlayer._exceptions.NotFoundError -> openlayer.NotFoundError +# openlayer-test._exceptions.NotFoundError -> openlayer-test.NotFoundError __locals = locals() for __name in __all__: if not __name.startswith("__"): try: - __locals[__name].__module__ = "openlayer" + setattr(__locals[__name], "__module__", "openlayer-test") except (TypeError, AttributeError): # Some of our exported symbols are builtins which we can't set attributes for. pass diff --git a/src/openlayer/_base_client.py b/src/openlayer-test/_base_client.py similarity index 99% rename from src/openlayer/_base_client.py rename to src/openlayer-test/_base_client.py index e56f38d8..21bfa7c4 100644 --- a/src/openlayer/_base_client.py +++ b/src/openlayer-test/_base_client.py @@ -60,7 +60,7 @@ RequestOptions, ModelBuilderProtocol, ) -from ._utils import is_dict, is_list, is_given, lru_cache, is_mapping +from ._utils import is_dict, is_given, is_mapping, is_list, lru_cache from ._compat import model_copy, model_dump from ._models import GenericModel, FinalRequestOptions, validate_type, construct_type from ._response import ( @@ -69,16 +69,17 @@ AsyncAPIResponse, extract_response_type, ) +from ._legacy_response import LegacyAPIResponse from ._constants import ( - DEFAULT_TIMEOUT, - MAX_RETRY_DELAY, + DEFAULT_CONNECTION_LIMITS, DEFAULT_MAX_RETRIES, + DEFAULT_TIMEOUT, INITIAL_RETRY_DELAY, + MAX_RETRY_DELAY, RAW_RESPONSE_HEADER, OVERRIDE_CAST_TO_HEADER, - DEFAULT_CONNECTION_LIMITS, ) -from ._streaming import Stream, SSEDecoder, AsyncStream, SSEBytesDecoder +from ._streaming import Stream, AsyncStream, SSEDecoder, SSEBytesDecoder from ._exceptions import ( APIStatusError, APITimeoutError, @@ -361,7 +362,7 @@ def __init__( if max_retries is None: # pyright: ignore[reportUnnecessaryComparison] raise TypeError( - "max_retries cannot be None. If you want to disable retries, pass `0`; if you want unlimited retries, pass `math.inf` or a very high number; if you want the default behavior, pass `openlayer.DEFAULT_MAX_RETRIES`" + "max_retries cannot be None. If you want to disable retries, pass `0`; if you want unlimited retries, pass `math.inf` or a very high number; if you want the default behavior, pass `openlayer-test.DEFAULT_MAX_RETRIES`" ) def _enforce_trailing_slash(self, url: URL) -> URL: diff --git a/src/openlayer/_client.py b/src/openlayer-test/_client.py similarity index 95% rename from src/openlayer/_client.py rename to src/openlayer-test/_client.py index 4188cb39..bd87c234 100644 --- a/src/openlayer/_client.py +++ b/src/openlayer-test/_client.py @@ -2,36 +2,68 @@ from __future__ import annotations +import httpx + import os -from typing import Any, Union, Mapping -from typing_extensions import Self, override + +from ._streaming import AsyncStream as AsyncStream, Stream as Stream + +from typing_extensions import override, Self + +from typing import Any + +from ._exceptions import APIStatusError + +from ._utils import get_async_library + +from . import _exceptions + +import os +import asyncio +import warnings +from typing import Optional, Union, Dict, Any, Mapping, overload, cast +from typing_extensions import Literal import httpx -from . import resources, _exceptions +from ._version import __version__ from ._qs import Querystring +from .types import shared_params +from ._utils import ( + extract_files, + maybe_transform, + required_args, + deepcopy_minimal, + maybe_coerce_integer, + maybe_coerce_float, + maybe_coerce_boolean, + is_given, +) from ._types import ( - NOT_GIVEN, Omit, - Headers, - Timeout, NotGiven, + Timeout, Transport, ProxiesTypes, RequestOptions, + Headers, + NoneType, + Query, + Body, + NOT_GIVEN, ) -from ._utils import ( - is_given, - get_async_library, -) -from ._version import __version__ -from ._streaming import Stream as Stream, AsyncStream as AsyncStream -from ._exceptions import APIStatusError from ._base_client import ( + DEFAULT_CONNECTION_LIMITS, + DEFAULT_TIMEOUT, DEFAULT_MAX_RETRIES, + ResponseT, + SyncHttpxClientWrapper, + AsyncHttpxClientWrapper, SyncAPIClient, AsyncAPIClient, + make_request_options, ) +from . import resources __all__ = [ "Timeout", diff --git a/src/openlayer/_compat.py b/src/openlayer-test/_compat.py similarity index 100% rename from src/openlayer/_compat.py rename to src/openlayer-test/_compat.py diff --git a/src/openlayer/_constants.py b/src/openlayer-test/_constants.py similarity index 100% rename from src/openlayer/_constants.py rename to src/openlayer-test/_constants.py diff --git a/src/openlayer/_exceptions.py b/src/openlayer-test/_exceptions.py similarity index 100% rename from src/openlayer/_exceptions.py rename to src/openlayer-test/_exceptions.py index 9d25d579..97e1e31b 100644 --- a/src/openlayer/_exceptions.py +++ b/src/openlayer-test/_exceptions.py @@ -2,10 +2,10 @@ from __future__ import annotations -from typing_extensions import Literal - import httpx +from typing_extensions import Literal + __all__ = [ "BadRequestError", "AuthenticationError", diff --git a/src/openlayer/_files.py b/src/openlayer-test/_files.py similarity index 100% rename from src/openlayer/_files.py rename to src/openlayer-test/_files.py diff --git a/src/openlayer/_models.py b/src/openlayer-test/_models.py similarity index 100% rename from src/openlayer/_models.py rename to src/openlayer-test/_models.py diff --git a/src/openlayer/_qs.py b/src/openlayer-test/_qs.py similarity index 100% rename from src/openlayer/_qs.py rename to src/openlayer-test/_qs.py diff --git a/src/openlayer/_resource.py b/src/openlayer-test/_resource.py similarity index 99% rename from src/openlayer/_resource.py rename to src/openlayer-test/_resource.py index eebef711..3f287aa6 100644 --- a/src/openlayer/_resource.py +++ b/src/openlayer-test/_resource.py @@ -3,9 +3,8 @@ from __future__ import annotations import time -from typing import TYPE_CHECKING - import anyio +from typing import TYPE_CHECKING if TYPE_CHECKING: from ._client import Openlayer, AsyncOpenlayer diff --git a/src/openlayer/_response.py b/src/openlayer-test/_response.py similarity index 98% rename from src/openlayer/_response.py rename to src/openlayer-test/_response.py index 39a5a83e..8cb9ca86 100644 --- a/src/openlayer/_response.py +++ b/src/openlayer-test/_response.py @@ -18,7 +18,7 @@ cast, overload, ) -from typing_extensions import Awaitable, ParamSpec, override, get_origin +from typing_extensions import Awaitable, ParamSpec, TypeGuard, override, get_origin import anyio import httpx @@ -26,6 +26,7 @@ from ._types import NoneType from ._utils import is_given, extract_type_arg, is_annotated_type, extract_type_var_from_base +from ._streaming import extract_stream_chunk_type from ._models import BaseModel, is_basemodel from ._constants import RAW_RESPONSE_HEADER, OVERRIDE_CAST_TO_HEADER from ._streaming import Stream, AsyncStream, is_stream_class_type, extract_stream_chunk_type @@ -203,7 +204,9 @@ def _parse(self, *, to: type[_T] | None = None) -> R | _T: return cast(R, response) if inspect.isclass(origin) and not issubclass(origin, BaseModel) and issubclass(origin, pydantic.BaseModel): - raise TypeError("Pydantic models must subclass our base model type, e.g. `from openlayer import BaseModel`") + raise TypeError( + "Pydantic models must subclass our base model type, e.g. `from openlayer-test import BaseModel`" + ) if ( cast_to is not object @@ -271,7 +274,7 @@ def parse(self, *, to: type[_T] | None = None) -> R | _T: the `to` argument, e.g. ```py - from openlayer import BaseModel + from openlayer-test import BaseModel class MyModel(BaseModel): @@ -375,7 +378,7 @@ async def parse(self, *, to: type[_T] | None = None) -> R | _T: the `to` argument, e.g. ```py - from openlayer import BaseModel + from openlayer-test import BaseModel class MyModel(BaseModel): @@ -546,7 +549,7 @@ async def stream_to_file( class MissingStreamClassError(TypeError): def __init__(self) -> None: super().__init__( - "The `stream` argument was set to `True` but the `stream_cls` argument was not given. See `openlayer._streaming` for reference", + "The `stream` argument was set to `True` but the `stream_cls` argument was not given. See `openlayer-test._streaming` for reference", ) diff --git a/src/openlayer/_streaming.py b/src/openlayer-test/_streaming.py similarity index 98% rename from src/openlayer/_streaming.py rename to src/openlayer-test/_streaming.py index 8eb34af1..a13c3850 100644 --- a/src/openlayer/_streaming.py +++ b/src/openlayer-test/_streaming.py @@ -9,7 +9,9 @@ import httpx -from ._utils import extract_type_var_from_base +from ._utils import is_mapping, is_dict, extract_type_var_from_base +from ._exceptions import APIError +from ._response import APIResponse, AsyncAPIResponse if TYPE_CHECKING: from ._client import Openlayer, AsyncOpenlayer diff --git a/src/openlayer/_types.py b/src/openlayer-test/_types.py similarity index 97% rename from src/openlayer/_types.py rename to src/openlayer-test/_types.py index 1dee84b9..f58e2736 100644 --- a/src/openlayer/_types.py +++ b/src/openlayer-test/_types.py @@ -1,6 +1,7 @@ from __future__ import annotations from os import PathLike +from abc import ABC, abstractmethod from typing import ( IO, TYPE_CHECKING, @@ -13,8 +14,10 @@ Mapping, TypeVar, Callable, + Iterator, Optional, Sequence, + AsyncIterator, ) from typing_extensions import Literal, Protocol, TypeAlias, TypedDict, override, runtime_checkable @@ -25,6 +28,7 @@ if TYPE_CHECKING: from ._models import BaseModel from ._response import APIResponse, AsyncAPIResponse + from ._legacy_response import HttpxBinaryResponseContent Transport = BaseTransport AsyncTransport = AsyncBaseTransport @@ -81,7 +85,7 @@ # This unfortunately means that you will either have # to import this type and pass it explicitly: # -# from openlayer import NoneType +# from openlayer-test import NoneType # client.get('/foo', cast_to=NoneType) # # or build it yourself: diff --git a/src/openlayer/_utils/__init__.py b/src/openlayer-test/_utils/__init__.py similarity index 100% rename from src/openlayer/_utils/__init__.py rename to src/openlayer-test/_utils/__init__.py diff --git a/src/openlayer/_utils/_logs.py b/src/openlayer-test/_utils/_logs.py similarity index 75% rename from src/openlayer/_utils/_logs.py rename to src/openlayer-test/_utils/_logs.py index 84e87cf4..15effa81 100644 --- a/src/openlayer/_utils/_logs.py +++ b/src/openlayer-test/_utils/_logs.py @@ -1,12 +1,12 @@ import os import logging -logger: logging.Logger = logging.getLogger("openlayer") +logger: logging.Logger = logging.getLogger("openlayer-test") httpx_logger: logging.Logger = logging.getLogger("httpx") def _basic_config() -> None: - # e.g. [2023-10-05 14:12:26 - openlayer._base_client:818 - DEBUG] HTTP Request: POST http://127.0.0.1:4010/foo/bar "200 OK" + # e.g. [2023-10-05 14:12:26 - openlayer-test._base_client:818 - DEBUG] HTTP Request: POST http://127.0.0.1:4010/foo/bar "200 OK" logging.basicConfig( format="[%(asctime)s - %(name)s:%(lineno)d - %(levelname)s] %(message)s", datefmt="%Y-%m-%d %H:%M:%S", diff --git a/src/openlayer/_utils/_proxy.py b/src/openlayer-test/_utils/_proxy.py similarity index 100% rename from src/openlayer/_utils/_proxy.py rename to src/openlayer-test/_utils/_proxy.py diff --git a/src/openlayer/_utils/_streams.py b/src/openlayer-test/_utils/_streams.py similarity index 100% rename from src/openlayer/_utils/_streams.py rename to src/openlayer-test/_utils/_streams.py diff --git a/src/openlayer/_utils/_sync.py b/src/openlayer-test/_utils/_sync.py similarity index 100% rename from src/openlayer/_utils/_sync.py rename to src/openlayer-test/_utils/_sync.py diff --git a/src/openlayer/_utils/_transform.py b/src/openlayer-test/_utils/_transform.py similarity index 100% rename from src/openlayer/_utils/_transform.py rename to src/openlayer-test/_utils/_transform.py diff --git a/src/openlayer/_utils/_typing.py b/src/openlayer-test/_utils/_typing.py similarity index 100% rename from src/openlayer/_utils/_typing.py rename to src/openlayer-test/_utils/_typing.py diff --git a/src/openlayer/_utils/_utils.py b/src/openlayer-test/_utils/_utils.py similarity index 100% rename from src/openlayer/_utils/_utils.py rename to src/openlayer-test/_utils/_utils.py diff --git a/src/openlayer/_version.py b/src/openlayer-test/_version.py similarity index 83% rename from src/openlayer/_version.py rename to src/openlayer-test/_version.py index 597e782e..7f41c4d4 100644 --- a/src/openlayer/_version.py +++ b/src/openlayer-test/_version.py @@ -1,4 +1,4 @@ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -__title__ = "openlayer" +__title__ = "openlayer-test" __version__ = "0.1.0-alpha.4" # x-release-please-version diff --git a/src/openlayer-test/lib/.keep b/src/openlayer-test/lib/.keep new file mode 100644 index 00000000..5e2c99fd --- /dev/null +++ b/src/openlayer-test/lib/.keep @@ -0,0 +1,4 @@ +File generated from our OpenAPI spec by Stainless. + +This directory can be used to store custom files to expand the SDK. +It is ignored by Stainless code generation and its content (other than this keep file) won't be touched. \ No newline at end of file diff --git a/src/openlayer/py.typed b/src/openlayer-test/py.typed similarity index 100% rename from src/openlayer/py.typed rename to src/openlayer-test/py.typed diff --git a/src/openlayer/resources/projects/__init__.py b/src/openlayer-test/resources/__init__.py similarity index 87% rename from src/openlayer/resources/projects/__init__.py rename to src/openlayer-test/resources/__init__.py index 47503c6d..ff23e20e 100644 --- a/src/openlayer/resources/projects/__init__.py +++ b/src/openlayer-test/resources/__init__.py @@ -1,24 +1,21 @@ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -from .commits import ( - CommitsResource, - AsyncCommitsResource, - CommitsResourceWithRawResponse, - AsyncCommitsResourceWithRawResponse, - CommitsResourceWithStreamingResponse, - AsyncCommitsResourceWithStreamingResponse, -) +from .projects import ProjectsResource, AsyncProjectsResource from .projects import ( - ProjectsResource, - AsyncProjectsResource, ProjectsResourceWithRawResponse, AsyncProjectsResourceWithRawResponse, ProjectsResourceWithStreamingResponse, AsyncProjectsResourceWithStreamingResponse, ) +from .commits import CommitsResource, AsyncCommitsResource +from .commits import ( + CommitsResourceWithRawResponse, + AsyncCommitsResourceWithRawResponse, + CommitsResourceWithStreamingResponse, + AsyncCommitsResourceWithStreamingResponse, +) +from .inference_pipelines import InferencePipelinesResource, AsyncInferencePipelinesResource from .inference_pipelines import ( - InferencePipelinesResource, - AsyncInferencePipelinesResource, InferencePipelinesResourceWithRawResponse, AsyncInferencePipelinesResourceWithRawResponse, InferencePipelinesResourceWithStreamingResponse, @@ -26,6 +23,12 @@ ) __all__ = [ + "ProjectsResource", + "AsyncProjectsResource", + "ProjectsResourceWithRawResponse", + "AsyncProjectsResourceWithRawResponse", + "ProjectsResourceWithStreamingResponse", + "AsyncProjectsResourceWithStreamingResponse", "CommitsResource", "AsyncCommitsResource", "CommitsResourceWithRawResponse", @@ -38,10 +41,4 @@ "AsyncInferencePipelinesResourceWithRawResponse", "InferencePipelinesResourceWithStreamingResponse", "AsyncInferencePipelinesResourceWithStreamingResponse", - "ProjectsResource", - "AsyncProjectsResource", - "ProjectsResourceWithRawResponse", - "AsyncProjectsResourceWithRawResponse", - "ProjectsResourceWithStreamingResponse", - "AsyncProjectsResourceWithStreamingResponse", ] diff --git a/src/openlayer/resources/commits/__init__.py b/src/openlayer-test/resources/commits/__init__.py similarity index 88% rename from src/openlayer/resources/commits/__init__.py rename to src/openlayer-test/resources/commits/__init__.py index 7ff3a88a..19d177aa 100644 --- a/src/openlayer/resources/commits/__init__.py +++ b/src/openlayer-test/resources/commits/__init__.py @@ -1,21 +1,19 @@ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -from .commits import ( - CommitsResource, - AsyncCommitsResource, - CommitsResourceWithRawResponse, - AsyncCommitsResourceWithRawResponse, - CommitsResourceWithStreamingResponse, - AsyncCommitsResourceWithStreamingResponse, -) +from .test_results import TestResultsResource, AsyncTestResultsResource from .test_results import ( - TestResultsResource, - AsyncTestResultsResource, TestResultsResourceWithRawResponse, AsyncTestResultsResourceWithRawResponse, TestResultsResourceWithStreamingResponse, AsyncTestResultsResourceWithStreamingResponse, ) +from .commits import CommitsResource, AsyncCommitsResource +from .commits import ( + CommitsResourceWithRawResponse, + AsyncCommitsResourceWithRawResponse, + CommitsResourceWithStreamingResponse, + AsyncCommitsResourceWithStreamingResponse, +) __all__ = [ "TestResultsResource", diff --git a/src/openlayer/resources/commits/commits.py b/src/openlayer-test/resources/commits/commits.py similarity index 81% rename from src/openlayer/resources/commits/commits.py rename to src/openlayer-test/resources/commits/commits.py index e9c62f89..aa687549 100644 --- a/src/openlayer/resources/commits/commits.py +++ b/src/openlayer-test/resources/commits/commits.py @@ -2,8 +2,25 @@ from __future__ import annotations +from .test_results import TestResultsResource, AsyncTestResultsResource + from ..._compat import cached_property + +import warnings +from typing import TYPE_CHECKING, Optional, Union, List, Dict, Any, Mapping, cast, overload +from typing_extensions import Literal +from ..._utils import extract_files, maybe_transform, required_args, deepcopy_minimal, strip_not_given +from ..._types import NotGiven, Timeout, Headers, NoneType, Query, Body, NOT_GIVEN, FileTypes, BinaryResponseContent from ..._resource import SyncAPIResource, AsyncAPIResource +from ..._base_client import ( + SyncAPIClient, + AsyncAPIClient, + _merge_mappings, + AsyncPaginator, + make_request_options, + HttpxBinaryResponseContent, +) +from ...types import shared_params from .test_results import ( TestResultsResource, AsyncTestResultsResource, diff --git a/src/openlayer/resources/commits/test_results.py b/src/openlayer-test/resources/commits/test_results.py similarity index 93% rename from src/openlayer/resources/commits/test_results.py rename to src/openlayer-test/resources/commits/test_results.py index f7aa939a..2521d532 100644 --- a/src/openlayer/resources/commits/test_results.py +++ b/src/openlayer-test/resources/commits/test_results.py @@ -2,28 +2,39 @@ from __future__ import annotations -from typing_extensions import Literal - import httpx -from ..._types import NOT_GIVEN, Body, Query, Headers, NotGiven -from ..._utils import ( - maybe_transform, - async_maybe_transform, -) from ..._compat import cached_property -from ..._resource import SyncAPIResource, AsyncAPIResource + +from ...types.commits.test_result_list_response import TestResultListResponse + +from ..._utils import maybe_transform, async_maybe_transform + +from typing_extensions import Literal + from ..._response import ( to_raw_response_wrapper, - to_streamed_response_wrapper, async_to_raw_response_wrapper, + to_streamed_response_wrapper, async_to_streamed_response_wrapper, ) + +import warnings +from typing import TYPE_CHECKING, Optional, Union, List, Dict, Any, Mapping, cast, overload +from typing_extensions import Literal +from ..._utils import extract_files, maybe_transform, required_args, deepcopy_minimal, strip_not_given +from ..._types import NotGiven, Timeout, Headers, NoneType, Query, Body, NOT_GIVEN, FileTypes, BinaryResponseContent +from ..._resource import SyncAPIResource, AsyncAPIResource from ..._base_client import ( + SyncAPIClient, + AsyncAPIClient, + _merge_mappings, + AsyncPaginator, make_request_options, + HttpxBinaryResponseContent, ) +from ...types import shared_params from ...types.commits import test_result_list_params -from ...types.commits.test_result_list_response import TestResultListResponse __all__ = ["TestResultsResource", "AsyncTestResultsResource"] diff --git a/src/openlayer/resources/inference_pipelines/__init__.py b/src/openlayer-test/resources/inference_pipelines/__init__.py similarity index 87% rename from src/openlayer/resources/inference_pipelines/__init__.py rename to src/openlayer-test/resources/inference_pipelines/__init__.py index fada9d79..4d323c24 100644 --- a/src/openlayer/resources/inference_pipelines/__init__.py +++ b/src/openlayer-test/resources/inference_pipelines/__init__.py @@ -1,24 +1,21 @@ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. +from .data import DataResource, AsyncDataResource from .data import ( - DataResource, - AsyncDataResource, DataResourceWithRawResponse, AsyncDataResourceWithRawResponse, DataResourceWithStreamingResponse, AsyncDataResourceWithStreamingResponse, ) +from .test_results import TestResultsResource, AsyncTestResultsResource from .test_results import ( - TestResultsResource, - AsyncTestResultsResource, TestResultsResourceWithRawResponse, AsyncTestResultsResourceWithRawResponse, TestResultsResourceWithStreamingResponse, AsyncTestResultsResourceWithStreamingResponse, ) +from .inference_pipelines import InferencePipelinesResource, AsyncInferencePipelinesResource from .inference_pipelines import ( - InferencePipelinesResource, - AsyncInferencePipelinesResource, InferencePipelinesResourceWithRawResponse, AsyncInferencePipelinesResourceWithRawResponse, InferencePipelinesResourceWithStreamingResponse, diff --git a/src/openlayer/resources/inference_pipelines/data.py b/src/openlayer-test/resources/inference_pipelines/data.py similarity index 89% rename from src/openlayer/resources/inference_pipelines/data.py rename to src/openlayer-test/resources/inference_pipelines/data.py index 00199059..cf52cf95 100644 --- a/src/openlayer/resources/inference_pipelines/data.py +++ b/src/openlayer-test/resources/inference_pipelines/data.py @@ -2,28 +2,41 @@ from __future__ import annotations -from typing import Dict, Iterable - import httpx -from ..._types import NOT_GIVEN, Body, Query, Headers, NotGiven -from ..._utils import ( - maybe_transform, - async_maybe_transform, -) from ..._compat import cached_property -from ..._resource import SyncAPIResource, AsyncAPIResource + +from ...types.inference_pipelines.data_stream_response import DataStreamResponse + +from ..._utils import maybe_transform, async_maybe_transform + +from typing import Iterable, Dict + from ..._response import ( to_raw_response_wrapper, - to_streamed_response_wrapper, async_to_raw_response_wrapper, + to_streamed_response_wrapper, async_to_streamed_response_wrapper, ) + +from ...types.inference_pipelines import data_stream_params + +import warnings +from typing import TYPE_CHECKING, Optional, Union, List, Dict, Any, Mapping, cast, overload +from typing_extensions import Literal +from ..._utils import extract_files, maybe_transform, required_args, deepcopy_minimal, strip_not_given +from ..._types import NotGiven, Timeout, Headers, NoneType, Query, Body, NOT_GIVEN, FileTypes, BinaryResponseContent +from ..._resource import SyncAPIResource, AsyncAPIResource from ..._base_client import ( + SyncAPIClient, + AsyncAPIClient, + _merge_mappings, + AsyncPaginator, make_request_options, + HttpxBinaryResponseContent, ) +from ...types import shared_params from ...types.inference_pipelines import data_stream_params -from ...types.inference_pipelines.data_stream_response import DataStreamResponse __all__ = ["DataResource", "AsyncDataResource"] diff --git a/src/openlayer/resources/inference_pipelines/inference_pipelines.py b/src/openlayer-test/resources/inference_pipelines/inference_pipelines.py similarity index 85% rename from src/openlayer/resources/inference_pipelines/inference_pipelines.py rename to src/openlayer-test/resources/inference_pipelines/inference_pipelines.py index 10853fe5..58d706d4 100644 --- a/src/openlayer/resources/inference_pipelines/inference_pipelines.py +++ b/src/openlayer-test/resources/inference_pipelines/inference_pipelines.py @@ -2,6 +2,27 @@ from __future__ import annotations +from .data import DataResource, AsyncDataResource + +from ..._compat import cached_property + +from .test_results import TestResultsResource, AsyncTestResultsResource + +import warnings +from typing import TYPE_CHECKING, Optional, Union, List, Dict, Any, Mapping, cast, overload +from typing_extensions import Literal +from ..._utils import extract_files, maybe_transform, required_args, deepcopy_minimal, strip_not_given +from ..._types import NotGiven, Timeout, Headers, NoneType, Query, Body, NOT_GIVEN, FileTypes, BinaryResponseContent +from ..._resource import SyncAPIResource, AsyncAPIResource +from ..._base_client import ( + SyncAPIClient, + AsyncAPIClient, + _merge_mappings, + AsyncPaginator, + make_request_options, + HttpxBinaryResponseContent, +) +from ...types import shared_params from .data import ( DataResource, AsyncDataResource, @@ -10,8 +31,6 @@ DataResourceWithStreamingResponse, AsyncDataResourceWithStreamingResponse, ) -from ..._compat import cached_property -from ..._resource import SyncAPIResource, AsyncAPIResource from .test_results import ( TestResultsResource, AsyncTestResultsResource, diff --git a/src/openlayer/resources/inference_pipelines/test_results.py b/src/openlayer-test/resources/inference_pipelines/test_results.py similarity index 93% rename from src/openlayer/resources/inference_pipelines/test_results.py rename to src/openlayer-test/resources/inference_pipelines/test_results.py index fd63ee8a..361681c9 100644 --- a/src/openlayer/resources/inference_pipelines/test_results.py +++ b/src/openlayer-test/resources/inference_pipelines/test_results.py @@ -2,28 +2,39 @@ from __future__ import annotations -from typing_extensions import Literal - import httpx -from ..._types import NOT_GIVEN, Body, Query, Headers, NotGiven -from ..._utils import ( - maybe_transform, - async_maybe_transform, -) from ..._compat import cached_property -from ..._resource import SyncAPIResource, AsyncAPIResource + +from ...types.inference_pipelines.test_result_list_response import TestResultListResponse + +from ..._utils import maybe_transform, async_maybe_transform + +from typing_extensions import Literal + from ..._response import ( to_raw_response_wrapper, - to_streamed_response_wrapper, async_to_raw_response_wrapper, + to_streamed_response_wrapper, async_to_streamed_response_wrapper, ) + +import warnings +from typing import TYPE_CHECKING, Optional, Union, List, Dict, Any, Mapping, cast, overload +from typing_extensions import Literal +from ..._utils import extract_files, maybe_transform, required_args, deepcopy_minimal, strip_not_given +from ..._types import NotGiven, Timeout, Headers, NoneType, Query, Body, NOT_GIVEN, FileTypes, BinaryResponseContent +from ..._resource import SyncAPIResource, AsyncAPIResource from ..._base_client import ( + SyncAPIClient, + AsyncAPIClient, + _merge_mappings, + AsyncPaginator, make_request_options, + HttpxBinaryResponseContent, ) +from ...types import shared_params from ...types.inference_pipelines import test_result_list_params -from ...types.inference_pipelines.test_result_list_response import TestResultListResponse __all__ = ["TestResultsResource", "AsyncTestResultsResource"] diff --git a/src/openlayer/resources/__init__.py b/src/openlayer-test/resources/projects/__init__.py similarity index 87% rename from src/openlayer/resources/__init__.py rename to src/openlayer-test/resources/projects/__init__.py index 28cab671..a2bd727c 100644 --- a/src/openlayer/resources/__init__.py +++ b/src/openlayer-test/resources/projects/__init__.py @@ -1,37 +1,28 @@ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. +from .commits import CommitsResource, AsyncCommitsResource from .commits import ( - CommitsResource, - AsyncCommitsResource, CommitsResourceWithRawResponse, AsyncCommitsResourceWithRawResponse, CommitsResourceWithStreamingResponse, AsyncCommitsResourceWithStreamingResponse, ) -from .projects import ( - ProjectsResource, - AsyncProjectsResource, - ProjectsResourceWithRawResponse, - AsyncProjectsResourceWithRawResponse, - ProjectsResourceWithStreamingResponse, - AsyncProjectsResourceWithStreamingResponse, -) +from .inference_pipelines import InferencePipelinesResource, AsyncInferencePipelinesResource from .inference_pipelines import ( - InferencePipelinesResource, - AsyncInferencePipelinesResource, InferencePipelinesResourceWithRawResponse, AsyncInferencePipelinesResourceWithRawResponse, InferencePipelinesResourceWithStreamingResponse, AsyncInferencePipelinesResourceWithStreamingResponse, ) +from .projects import ProjectsResource, AsyncProjectsResource +from .projects import ( + ProjectsResourceWithRawResponse, + AsyncProjectsResourceWithRawResponse, + ProjectsResourceWithStreamingResponse, + AsyncProjectsResourceWithStreamingResponse, +) __all__ = [ - "ProjectsResource", - "AsyncProjectsResource", - "ProjectsResourceWithRawResponse", - "AsyncProjectsResourceWithRawResponse", - "ProjectsResourceWithStreamingResponse", - "AsyncProjectsResourceWithStreamingResponse", "CommitsResource", "AsyncCommitsResource", "CommitsResourceWithRawResponse", @@ -44,4 +35,10 @@ "AsyncInferencePipelinesResourceWithRawResponse", "InferencePipelinesResourceWithStreamingResponse", "AsyncInferencePipelinesResourceWithStreamingResponse", + "ProjectsResource", + "AsyncProjectsResource", + "ProjectsResourceWithRawResponse", + "AsyncProjectsResourceWithRawResponse", + "ProjectsResourceWithStreamingResponse", + "AsyncProjectsResourceWithStreamingResponse", ] diff --git a/src/openlayer/resources/projects/commits.py b/src/openlayer-test/resources/projects/commits.py similarity index 91% rename from src/openlayer/resources/projects/commits.py rename to src/openlayer-test/resources/projects/commits.py index 0252f17f..44b92c22 100644 --- a/src/openlayer/resources/projects/commits.py +++ b/src/openlayer-test/resources/projects/commits.py @@ -4,24 +4,35 @@ import httpx -from ..._types import NOT_GIVEN, Body, Query, Headers, NotGiven -from ..._utils import ( - maybe_transform, - async_maybe_transform, -) from ..._compat import cached_property -from ..._resource import SyncAPIResource, AsyncAPIResource + +from ...types.projects.commit_list_response import CommitListResponse + +from ..._utils import maybe_transform, async_maybe_transform + from ..._response import ( to_raw_response_wrapper, - to_streamed_response_wrapper, async_to_raw_response_wrapper, + to_streamed_response_wrapper, async_to_streamed_response_wrapper, ) + +import warnings +from typing import TYPE_CHECKING, Optional, Union, List, Dict, Any, Mapping, cast, overload +from typing_extensions import Literal +from ..._utils import extract_files, maybe_transform, required_args, deepcopy_minimal, strip_not_given +from ..._types import NotGiven, Timeout, Headers, NoneType, Query, Body, NOT_GIVEN, FileTypes, BinaryResponseContent +from ..._resource import SyncAPIResource, AsyncAPIResource from ..._base_client import ( + SyncAPIClient, + AsyncAPIClient, + _merge_mappings, + AsyncPaginator, make_request_options, + HttpxBinaryResponseContent, ) +from ...types import shared_params from ...types.projects import commit_list_params -from ...types.projects.commit_list_response import CommitListResponse __all__ = ["CommitsResource", "AsyncCommitsResource"] diff --git a/src/openlayer/resources/projects/inference_pipelines.py b/src/openlayer-test/resources/projects/inference_pipelines.py similarity index 91% rename from src/openlayer/resources/projects/inference_pipelines.py rename to src/openlayer-test/resources/projects/inference_pipelines.py index 31b195f1..ccbc6f83 100644 --- a/src/openlayer/resources/projects/inference_pipelines.py +++ b/src/openlayer-test/resources/projects/inference_pipelines.py @@ -4,24 +4,35 @@ import httpx -from ..._types import NOT_GIVEN, Body, Query, Headers, NotGiven -from ..._utils import ( - maybe_transform, - async_maybe_transform, -) from ..._compat import cached_property -from ..._resource import SyncAPIResource, AsyncAPIResource + +from ...types.projects.inference_pipeline_list_response import InferencePipelineListResponse + +from ..._utils import maybe_transform, async_maybe_transform + from ..._response import ( to_raw_response_wrapper, - to_streamed_response_wrapper, async_to_raw_response_wrapper, + to_streamed_response_wrapper, async_to_streamed_response_wrapper, ) + +import warnings +from typing import TYPE_CHECKING, Optional, Union, List, Dict, Any, Mapping, cast, overload +from typing_extensions import Literal +from ..._utils import extract_files, maybe_transform, required_args, deepcopy_minimal, strip_not_given +from ..._types import NotGiven, Timeout, Headers, NoneType, Query, Body, NOT_GIVEN, FileTypes, BinaryResponseContent +from ..._resource import SyncAPIResource, AsyncAPIResource from ..._base_client import ( + SyncAPIClient, + AsyncAPIClient, + _merge_mappings, + AsyncPaginator, make_request_options, + HttpxBinaryResponseContent, ) +from ...types import shared_params from ...types.projects import inference_pipeline_list_params -from ...types.projects.inference_pipeline_list_response import InferencePipelineListResponse __all__ = ["InferencePipelinesResource", "AsyncInferencePipelinesResource"] diff --git a/src/openlayer/resources/projects/projects.py b/src/openlayer-test/resources/projects/projects.py similarity index 92% rename from src/openlayer/resources/projects/projects.py rename to src/openlayer-test/resources/projects/projects.py index fb5ab1ac..5dbe69af 100644 --- a/src/openlayer/resources/projects/projects.py +++ b/src/openlayer-test/resources/projects/projects.py @@ -2,10 +2,42 @@ from __future__ import annotations +import httpx + +from .commits import CommitsResource, AsyncCommitsResource + +from ..._compat import cached_property + +from .inference_pipelines import InferencePipelinesResource, AsyncInferencePipelinesResource + +from ...types.project_list_response import ProjectListResponse + +from ..._utils import maybe_transform, async_maybe_transform + from typing_extensions import Literal -import httpx +from ..._response import ( + to_raw_response_wrapper, + async_to_raw_response_wrapper, + to_streamed_response_wrapper, + async_to_streamed_response_wrapper, +) +import warnings +from typing import TYPE_CHECKING, Optional, Union, List, Dict, Any, Mapping, cast, overload +from typing_extensions import Literal +from ..._utils import extract_files, maybe_transform, required_args, deepcopy_minimal, strip_not_given +from ..._types import NotGiven, Timeout, Headers, NoneType, Query, Body, NOT_GIVEN, FileTypes, BinaryResponseContent +from ..._resource import SyncAPIResource, AsyncAPIResource +from ..._base_client import ( + SyncAPIClient, + AsyncAPIClient, + _merge_mappings, + AsyncPaginator, + make_request_options, + HttpxBinaryResponseContent, +) +from ...types import shared_params from ...types import project_list_params from .commits import ( CommitsResource, @@ -15,22 +47,6 @@ CommitsResourceWithStreamingResponse, AsyncCommitsResourceWithStreamingResponse, ) -from ..._types import NOT_GIVEN, Body, Query, Headers, NotGiven -from ..._utils import ( - maybe_transform, - async_maybe_transform, -) -from ..._compat import cached_property -from ..._resource import SyncAPIResource, AsyncAPIResource -from ..._response import ( - to_raw_response_wrapper, - to_streamed_response_wrapper, - async_to_raw_response_wrapper, - async_to_streamed_response_wrapper, -) -from ..._base_client import ( - make_request_options, -) from .inference_pipelines import ( InferencePipelinesResource, AsyncInferencePipelinesResource, @@ -39,7 +55,6 @@ InferencePipelinesResourceWithStreamingResponse, AsyncInferencePipelinesResourceWithStreamingResponse, ) -from ...types.project_list_response import ProjectListResponse __all__ = ["ProjectsResource", "AsyncProjectsResource"] diff --git a/src/openlayer/types/__init__.py b/src/openlayer-test/types/__init__.py similarity index 100% rename from src/openlayer/types/__init__.py rename to src/openlayer-test/types/__init__.py index 5fee6060..b816f73b 100644 --- a/src/openlayer/types/__init__.py +++ b/src/openlayer-test/types/__init__.py @@ -2,5 +2,5 @@ from __future__ import annotations -from .project_list_params import ProjectListParams as ProjectListParams from .project_list_response import ProjectListResponse as ProjectListResponse +from .project_list_params import ProjectListParams as ProjectListParams diff --git a/src/openlayer/types/commits/__init__.py b/src/openlayer-test/types/commits/__init__.py similarity index 100% rename from src/openlayer/types/commits/__init__.py rename to src/openlayer-test/types/commits/__init__.py index 3208a274..14ec8a6d 100644 --- a/src/openlayer/types/commits/__init__.py +++ b/src/openlayer-test/types/commits/__init__.py @@ -2,5 +2,5 @@ from __future__ import annotations -from .test_result_list_params import TestResultListParams as TestResultListParams from .test_result_list_response import TestResultListResponse as TestResultListResponse +from .test_result_list_params import TestResultListParams as TestResultListParams diff --git a/src/openlayer/types/inference_pipelines/test_result_list_params.py b/src/openlayer-test/types/commits/test_result_list_params.py similarity index 77% rename from src/openlayer/types/inference_pipelines/test_result_list_params.py rename to src/openlayer-test/types/commits/test_result_list_params.py index d158bba3..7ed3cef4 100644 --- a/src/openlayer/types/inference_pipelines/test_result_list_params.py +++ b/src/openlayer-test/types/commits/test_result_list_params.py @@ -2,10 +2,16 @@ from __future__ import annotations -from typing_extensions import Literal, Annotated, TypedDict +from typing_extensions import TypedDict, Annotated, Literal from ..._utils import PropertyInfo +from typing import List, Union, Dict, Optional +from typing_extensions import Literal, TypedDict, Required, Annotated +from ..._types import FileTypes +from ..._utils import PropertyInfo +from ...types import shared_params + __all__ = ["TestResultListParams"] diff --git a/src/openlayer/types/inference_pipelines/test_result_list_response.py b/src/openlayer-test/types/commits/test_result_list_response.py similarity index 96% rename from src/openlayer/types/inference_pipelines/test_result_list_response.py rename to src/openlayer-test/types/commits/test_result_list_response.py index b099bfe0..9f5290ed 100644 --- a/src/openlayer/types/inference_pipelines/test_result_list_response.py +++ b/src/openlayer-test/types/commits/test_result_list_response.py @@ -1,12 +1,17 @@ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -from typing import List, Union, Optional +from ..._models import BaseModel + +from typing import Optional, List, Union + from datetime import datetime + from typing_extensions import Literal +from typing import Optional, Union, List, Dict, Any +from typing_extensions import Literal from pydantic import Field as FieldInfo - -from ..._models import BaseModel +from ...types import shared __all__ = ["TestResultListResponse", "_Meta", "Item", "ItemGoal", "ItemGoalThreshold"] diff --git a/src/openlayer/types/inference_pipelines/__init__.py b/src/openlayer-test/types/inference_pipelines/__init__.py similarity index 100% rename from src/openlayer/types/inference_pipelines/__init__.py rename to src/openlayer-test/types/inference_pipelines/__init__.py index 69717a48..736dd193 100644 --- a/src/openlayer/types/inference_pipelines/__init__.py +++ b/src/openlayer-test/types/inference_pipelines/__init__.py @@ -2,7 +2,7 @@ from __future__ import annotations -from .data_stream_params import DataStreamParams as DataStreamParams from .data_stream_response import DataStreamResponse as DataStreamResponse -from .test_result_list_params import TestResultListParams as TestResultListParams +from .data_stream_params import DataStreamParams as DataStreamParams from .test_result_list_response import TestResultListResponse as TestResultListResponse +from .test_result_list_params import TestResultListParams as TestResultListParams diff --git a/src/openlayer/types/inference_pipelines/data_stream_params.py b/src/openlayer-test/types/inference_pipelines/data_stream_params.py similarity index 95% rename from src/openlayer/types/inference_pipelines/data_stream_params.py rename to src/openlayer-test/types/inference_pipelines/data_stream_params.py index b452cb35..078a5297 100644 --- a/src/openlayer/types/inference_pipelines/data_stream_params.py +++ b/src/openlayer-test/types/inference_pipelines/data_stream_params.py @@ -2,10 +2,17 @@ from __future__ import annotations -from typing import Dict, List, Union, Iterable, Optional -from typing_extensions import Required, Annotated, TypedDict +from typing_extensions import TypedDict, Required, Annotated +from typing import Iterable, Dict, List, Optional, Union + +from ..._utils import PropertyInfo + +from typing import List, Union, Dict, Optional +from typing_extensions import Literal, TypedDict, Required, Annotated +from ..._types import FileTypes from ..._utils import PropertyInfo +from ...types import shared_params __all__ = [ "DataStreamParams", diff --git a/src/openlayer/types/inference_pipelines/data_stream_response.py b/src/openlayer-test/types/inference_pipelines/data_stream_response.py similarity index 61% rename from src/openlayer/types/inference_pipelines/data_stream_response.py rename to src/openlayer-test/types/inference_pipelines/data_stream_response.py index 3863d3ff..4c408a1e 100644 --- a/src/openlayer/types/inference_pipelines/data_stream_response.py +++ b/src/openlayer-test/types/inference_pipelines/data_stream_response.py @@ -1,8 +1,13 @@ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. +from ..._models import BaseModel + from typing_extensions import Literal -from ..._models import BaseModel +from typing import Optional, Union, List, Dict, Any +from typing_extensions import Literal +from pydantic import Field as FieldInfo +from ...types import shared __all__ = ["DataStreamResponse"] diff --git a/src/openlayer/types/commits/test_result_list_params.py b/src/openlayer-test/types/inference_pipelines/test_result_list_params.py similarity index 77% rename from src/openlayer/types/commits/test_result_list_params.py rename to src/openlayer-test/types/inference_pipelines/test_result_list_params.py index d158bba3..7ed3cef4 100644 --- a/src/openlayer/types/commits/test_result_list_params.py +++ b/src/openlayer-test/types/inference_pipelines/test_result_list_params.py @@ -2,10 +2,16 @@ from __future__ import annotations -from typing_extensions import Literal, Annotated, TypedDict +from typing_extensions import TypedDict, Annotated, Literal from ..._utils import PropertyInfo +from typing import List, Union, Dict, Optional +from typing_extensions import Literal, TypedDict, Required, Annotated +from ..._types import FileTypes +from ..._utils import PropertyInfo +from ...types import shared_params + __all__ = ["TestResultListParams"] diff --git a/src/openlayer/types/commits/test_result_list_response.py b/src/openlayer-test/types/inference_pipelines/test_result_list_response.py similarity index 96% rename from src/openlayer/types/commits/test_result_list_response.py rename to src/openlayer-test/types/inference_pipelines/test_result_list_response.py index b099bfe0..9f5290ed 100644 --- a/src/openlayer/types/commits/test_result_list_response.py +++ b/src/openlayer-test/types/inference_pipelines/test_result_list_response.py @@ -1,12 +1,17 @@ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -from typing import List, Union, Optional +from ..._models import BaseModel + +from typing import Optional, List, Union + from datetime import datetime + from typing_extensions import Literal +from typing import Optional, Union, List, Dict, Any +from typing_extensions import Literal from pydantic import Field as FieldInfo - -from ..._models import BaseModel +from ...types import shared __all__ = ["TestResultListResponse", "_Meta", "Item", "ItemGoal", "ItemGoalThreshold"] diff --git a/src/openlayer/types/project_list_params.py b/src/openlayer-test/types/project_list_params.py similarity index 71% rename from src/openlayer/types/project_list_params.py rename to src/openlayer-test/types/project_list_params.py index 6cff1bed..361dd31d 100644 --- a/src/openlayer/types/project_list_params.py +++ b/src/openlayer-test/types/project_list_params.py @@ -2,10 +2,16 @@ from __future__ import annotations -from typing_extensions import Literal, Annotated, TypedDict +from typing_extensions import TypedDict, Annotated, Literal from .._utils import PropertyInfo +from typing import List, Union, Dict, Optional +from typing_extensions import Literal, TypedDict, Required, Annotated +from .._types import FileTypes +from .._utils import PropertyInfo +from ..types import shared_params + __all__ = ["ProjectListParams"] diff --git a/src/openlayer/types/project_list_response.py b/src/openlayer-test/types/project_list_response.py similarity index 96% rename from src/openlayer/types/project_list_response.py rename to src/openlayer-test/types/project_list_response.py index 3bc1c5a9..e2a57673 100644 --- a/src/openlayer/types/project_list_response.py +++ b/src/openlayer-test/types/project_list_response.py @@ -1,12 +1,17 @@ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -from typing import List, Optional +from .._models import BaseModel + from datetime import datetime + +from typing import Optional, List + from typing_extensions import Literal +from typing import Optional, Union, List, Dict, Any +from typing_extensions import Literal from pydantic import Field as FieldInfo - -from .._models import BaseModel +from ..types import shared __all__ = ["ProjectListResponse", "_Meta", "Item", "ItemLinks", "ItemGitRepo"] diff --git a/src/openlayer/types/projects/__init__.py b/src/openlayer-test/types/projects/__init__.py similarity index 100% rename from src/openlayer/types/projects/__init__.py rename to src/openlayer-test/types/projects/__init__.py index 4ab9cf2b..d1e6a640 100644 --- a/src/openlayer/types/projects/__init__.py +++ b/src/openlayer-test/types/projects/__init__.py @@ -2,7 +2,7 @@ from __future__ import annotations -from .commit_list_params import CommitListParams as CommitListParams from .commit_list_response import CommitListResponse as CommitListResponse -from .inference_pipeline_list_params import InferencePipelineListParams as InferencePipelineListParams +from .commit_list_params import CommitListParams as CommitListParams from .inference_pipeline_list_response import InferencePipelineListResponse as InferencePipelineListResponse +from .inference_pipeline_list_params import InferencePipelineListParams as InferencePipelineListParams diff --git a/src/openlayer/types/projects/commit_list_params.py b/src/openlayer-test/types/projects/commit_list_params.py similarity index 60% rename from src/openlayer/types/projects/commit_list_params.py rename to src/openlayer-test/types/projects/commit_list_params.py index 45e9fcaa..63653434 100644 --- a/src/openlayer/types/projects/commit_list_params.py +++ b/src/openlayer-test/types/projects/commit_list_params.py @@ -2,10 +2,16 @@ from __future__ import annotations -from typing_extensions import Annotated, TypedDict +from typing_extensions import TypedDict, Annotated from ..._utils import PropertyInfo +from typing import List, Union, Dict, Optional +from typing_extensions import Literal, TypedDict, Required, Annotated +from ..._types import FileTypes +from ..._utils import PropertyInfo +from ...types import shared_params + __all__ = ["CommitListParams"] diff --git a/src/openlayer/types/projects/commit_list_response.py b/src/openlayer-test/types/projects/commit_list_response.py similarity index 96% rename from src/openlayer/types/projects/commit_list_response.py rename to src/openlayer-test/types/projects/commit_list_response.py index d89b9006..de2c6e6c 100644 --- a/src/openlayer/types/projects/commit_list_response.py +++ b/src/openlayer-test/types/projects/commit_list_response.py @@ -1,12 +1,17 @@ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -from typing import List, Optional +from ..._models import BaseModel + +from typing import Optional, List + from datetime import datetime + from typing_extensions import Literal +from typing import Optional, Union, List, Dict, Any +from typing_extensions import Literal from pydantic import Field as FieldInfo - -from ..._models import BaseModel +from ...types import shared __all__ = ["CommitListResponse", "_Meta", "Item", "ItemCommit", "ItemLinks"] diff --git a/src/openlayer/types/projects/inference_pipeline_list_params.py b/src/openlayer-test/types/projects/inference_pipeline_list_params.py similarity index 64% rename from src/openlayer/types/projects/inference_pipeline_list_params.py rename to src/openlayer-test/types/projects/inference_pipeline_list_params.py index ed30e375..74281e5b 100644 --- a/src/openlayer/types/projects/inference_pipeline_list_params.py +++ b/src/openlayer-test/types/projects/inference_pipeline_list_params.py @@ -2,10 +2,16 @@ from __future__ import annotations -from typing_extensions import Annotated, TypedDict +from typing_extensions import TypedDict, Annotated from ..._utils import PropertyInfo +from typing import List, Union, Dict, Optional +from typing_extensions import Literal, TypedDict, Required, Annotated +from ..._types import FileTypes +from ..._utils import PropertyInfo +from ...types import shared_params + __all__ = ["InferencePipelineListParams"] diff --git a/src/openlayer/types/projects/inference_pipeline_list_response.py b/src/openlayer-test/types/projects/inference_pipeline_list_response.py similarity index 94% rename from src/openlayer/types/projects/inference_pipeline_list_response.py rename to src/openlayer-test/types/projects/inference_pipeline_list_response.py index 66c9d1b9..7e3f0da2 100644 --- a/src/openlayer/types/projects/inference_pipeline_list_response.py +++ b/src/openlayer-test/types/projects/inference_pipeline_list_response.py @@ -1,12 +1,17 @@ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -from typing import List, Optional +from ..._models import BaseModel + from datetime import datetime + +from typing import Optional, List + from typing_extensions import Literal +from typing import Optional, Union, List, Dict, Any +from typing_extensions import Literal from pydantic import Field as FieldInfo - -from ..._models import BaseModel +from ...types import shared __all__ = ["InferencePipelineListResponse", "_Meta", "Item", "ItemLinks"] diff --git a/tests/api_resources/commits/test_test_results.py b/tests/api_resources/commits/test_test_results.py index e22aff80..f8005a0f 100644 --- a/tests/api_resources/commits/test_test_results.py +++ b/tests/api_resources/commits/test_test_results.py @@ -2,27 +2,34 @@ from __future__ import annotations -import os +from openlayer-test import Openlayer, AsyncOpenlayer + +from openlayer-test.types.commits import TestResultListResponse + from typing import Any, cast +import os import pytest - -from openlayer import Openlayer, AsyncOpenlayer +import httpx +from typing_extensions import get_args +from typing import Optional +from respx import MockRouter +from openlayer-test import Openlayer, AsyncOpenlayer from tests.utils import assert_matches_type -from openlayer.types.commits import TestResultListResponse +from openlayer-test.types.commits import test_result_list_params base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") - class TestTestResults: - parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"]) + parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=['loose', 'strict']) + @parametrize def test_method_list(self, client: Openlayer) -> None: test_result = client.commits.test_results.list( "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", ) - assert_matches_type(TestResultListResponse, test_result, path=["response"]) + assert_matches_type(TestResultListResponse, test_result, path=['response']) @parametrize def test_method_list_with_all_params(self, client: Openlayer) -> None: @@ -34,49 +41,49 @@ def test_method_list_with_all_params(self, client: Openlayer) -> None: status="passing", type="integrity", ) - assert_matches_type(TestResultListResponse, test_result, path=["response"]) + assert_matches_type(TestResultListResponse, test_result, path=['response']) @parametrize def test_raw_response_list(self, client: Openlayer) -> None: + response = client.commits.test_results.with_raw_response.list( "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", ) assert response.is_closed is True - assert response.http_request.headers.get("X-Stainless-Lang") == "python" + assert response.http_request.headers.get('X-Stainless-Lang') == 'python' test_result = response.parse() - assert_matches_type(TestResultListResponse, test_result, path=["response"]) + assert_matches_type(TestResultListResponse, test_result, path=['response']) @parametrize def test_streaming_response_list(self, client: Openlayer) -> None: with client.commits.test_results.with_streaming_response.list( "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", - ) as response: + ) as response : assert not response.is_closed - assert response.http_request.headers.get("X-Stainless-Lang") == "python" + assert response.http_request.headers.get('X-Stainless-Lang') == 'python' test_result = response.parse() - assert_matches_type(TestResultListResponse, test_result, path=["response"]) + assert_matches_type(TestResultListResponse, test_result, path=['response']) assert cast(Any, response.is_closed) is True @parametrize def test_path_params_list(self, client: Openlayer) -> None: with pytest.raises(ValueError, match=r"Expected a non-empty value for `id` but received ''"): - client.commits.test_results.with_raw_response.list( - "", - ) - - + client.commits.test_results.with_raw_response.list( + "", + ) class TestAsyncTestResults: - parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"]) + parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=['loose', 'strict']) + @parametrize async def test_method_list(self, async_client: AsyncOpenlayer) -> None: test_result = await async_client.commits.test_results.list( "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", ) - assert_matches_type(TestResultListResponse, test_result, path=["response"]) + assert_matches_type(TestResultListResponse, test_result, path=['response']) @parametrize async def test_method_list_with_all_params(self, async_client: AsyncOpenlayer) -> None: @@ -88,35 +95,36 @@ async def test_method_list_with_all_params(self, async_client: AsyncOpenlayer) - status="passing", type="integrity", ) - assert_matches_type(TestResultListResponse, test_result, path=["response"]) + assert_matches_type(TestResultListResponse, test_result, path=['response']) @parametrize async def test_raw_response_list(self, async_client: AsyncOpenlayer) -> None: + response = await async_client.commits.test_results.with_raw_response.list( "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", ) assert response.is_closed is True - assert response.http_request.headers.get("X-Stainless-Lang") == "python" + assert response.http_request.headers.get('X-Stainless-Lang') == 'python' test_result = await response.parse() - assert_matches_type(TestResultListResponse, test_result, path=["response"]) + assert_matches_type(TestResultListResponse, test_result, path=['response']) @parametrize async def test_streaming_response_list(self, async_client: AsyncOpenlayer) -> None: async with async_client.commits.test_results.with_streaming_response.list( "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", - ) as response: + ) as response : assert not response.is_closed - assert response.http_request.headers.get("X-Stainless-Lang") == "python" + assert response.http_request.headers.get('X-Stainless-Lang') == 'python' test_result = await response.parse() - assert_matches_type(TestResultListResponse, test_result, path=["response"]) + assert_matches_type(TestResultListResponse, test_result, path=['response']) assert cast(Any, response.is_closed) is True @parametrize async def test_path_params_list(self, async_client: AsyncOpenlayer) -> None: with pytest.raises(ValueError, match=r"Expected a non-empty value for `id` but received ''"): - await async_client.commits.test_results.with_raw_response.list( - "", - ) + await async_client.commits.test_results.with_raw_response.list( + "", + ) \ No newline at end of file diff --git a/tests/api_resources/inference_pipelines/test_data.py b/tests/api_resources/inference_pipelines/test_data.py index 1e070c1b..3fe72f9c 100644 --- a/tests/api_resources/inference_pipelines/test_data.py +++ b/tests/api_resources/inference_pipelines/test_data.py @@ -2,37 +2,44 @@ from __future__ import annotations -import os +from openlayer-test import Openlayer, AsyncOpenlayer + +from openlayer-test.types.inference_pipelines import DataStreamResponse + from typing import Any, cast +import os import pytest - -from openlayer import Openlayer, AsyncOpenlayer +import httpx +from typing_extensions import get_args +from typing import Optional +from respx import MockRouter +from openlayer-test import Openlayer, AsyncOpenlayer from tests.utils import assert_matches_type -from openlayer.types.inference_pipelines import DataStreamResponse +from openlayer-test.types.inference_pipelines import data_stream_params base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") - class TestData: - parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"]) + parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=['loose', 'strict']) + @parametrize def test_method_stream(self, client: Openlayer) -> None: data = client.inference_pipelines.data.stream( "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", - config={"output_column_name": "output"}, - rows=[ - { - "user_query": "bar", - "output": "bar", - "tokens": "bar", - "cost": "bar", - "timestamp": "bar", - } - ], + config={ + "output_column_name": "output" + }, + rows=[{ + "user_query": "bar", + "output": "bar", + "tokens": "bar", + "cost": "bar", + "timestamp": "bar", + }], ) - assert_matches_type(DataStreamResponse, data, path=["response"]) + assert_matches_type(DataStreamResponse, data, path=['response']) @parametrize def test_method_stream_with_all_params(self, client: Openlayer) -> None: @@ -48,108 +55,104 @@ def test_method_stream_with_all_params(self, client: Openlayer) -> None: "latency_column_name": "latency", "metadata": {}, "output_column_name": "output", - "prompt": [ - { - "role": "user", - "content": "{{ user_query }}", - } - ], + "prompt": [{ + "role": "user", + "content": "{{ user_query }}", + }], "question_column_name": "question", "timestamp_column_name": "timestamp", }, - rows=[ - { - "user_query": "bar", - "output": "bar", - "tokens": "bar", - "cost": "bar", - "timestamp": "bar", - } - ], + rows=[{ + "user_query": "bar", + "output": "bar", + "tokens": "bar", + "cost": "bar", + "timestamp": "bar", + }], ) - assert_matches_type(DataStreamResponse, data, path=["response"]) + assert_matches_type(DataStreamResponse, data, path=['response']) @parametrize def test_raw_response_stream(self, client: Openlayer) -> None: + response = client.inference_pipelines.data.with_raw_response.stream( "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", - config={"output_column_name": "output"}, - rows=[ - { - "user_query": "bar", - "output": "bar", - "tokens": "bar", - "cost": "bar", - "timestamp": "bar", - } - ], + config={ + "output_column_name": "output" + }, + rows=[{ + "user_query": "bar", + "output": "bar", + "tokens": "bar", + "cost": "bar", + "timestamp": "bar", + }], ) assert response.is_closed is True - assert response.http_request.headers.get("X-Stainless-Lang") == "python" + assert response.http_request.headers.get('X-Stainless-Lang') == 'python' data = response.parse() - assert_matches_type(DataStreamResponse, data, path=["response"]) + assert_matches_type(DataStreamResponse, data, path=['response']) @parametrize def test_streaming_response_stream(self, client: Openlayer) -> None: with client.inference_pipelines.data.with_streaming_response.stream( "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", - config={"output_column_name": "output"}, - rows=[ - { - "user_query": "bar", - "output": "bar", - "tokens": "bar", - "cost": "bar", - "timestamp": "bar", - } - ], - ) as response: + config={ + "output_column_name": "output" + }, + rows=[{ + "user_query": "bar", + "output": "bar", + "tokens": "bar", + "cost": "bar", + "timestamp": "bar", + }], + ) as response : assert not response.is_closed - assert response.http_request.headers.get("X-Stainless-Lang") == "python" + assert response.http_request.headers.get('X-Stainless-Lang') == 'python' data = response.parse() - assert_matches_type(DataStreamResponse, data, path=["response"]) + assert_matches_type(DataStreamResponse, data, path=['response']) assert cast(Any, response.is_closed) is True @parametrize def test_path_params_stream(self, client: Openlayer) -> None: with pytest.raises(ValueError, match=r"Expected a non-empty value for `id` but received ''"): - client.inference_pipelines.data.with_raw_response.stream( - "", - config={"output_column_name": "output"}, - rows=[ - { - "user_query": "bar", - "output": "bar", - "tokens": "bar", - "cost": "bar", - "timestamp": "bar", - } - ], - ) - - + client.inference_pipelines.data.with_raw_response.stream( + "", + config={ + "output_column_name": "output" + }, + rows=[{ + "user_query": "bar", + "output": "bar", + "tokens": "bar", + "cost": "bar", + "timestamp": "bar", + }], + ) class TestAsyncData: - parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"]) + parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=['loose', 'strict']) + @parametrize async def test_method_stream(self, async_client: AsyncOpenlayer) -> None: data = await async_client.inference_pipelines.data.stream( "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", - config={"output_column_name": "output"}, - rows=[ - { - "user_query": "bar", - "output": "bar", - "tokens": "bar", - "cost": "bar", - "timestamp": "bar", - } - ], + config={ + "output_column_name": "output" + }, + rows=[{ + "user_query": "bar", + "output": "bar", + "tokens": "bar", + "cost": "bar", + "timestamp": "bar", + }], ) - assert_matches_type(DataStreamResponse, data, path=["response"]) + assert_matches_type(DataStreamResponse, data, path=['response']) @parametrize async def test_method_stream_with_all_params(self, async_client: AsyncOpenlayer) -> None: @@ -165,84 +168,81 @@ async def test_method_stream_with_all_params(self, async_client: AsyncOpenlayer) "latency_column_name": "latency", "metadata": {}, "output_column_name": "output", - "prompt": [ - { - "role": "user", - "content": "{{ user_query }}", - } - ], + "prompt": [{ + "role": "user", + "content": "{{ user_query }}", + }], "question_column_name": "question", "timestamp_column_name": "timestamp", }, - rows=[ - { - "user_query": "bar", - "output": "bar", - "tokens": "bar", - "cost": "bar", - "timestamp": "bar", - } - ], + rows=[{ + "user_query": "bar", + "output": "bar", + "tokens": "bar", + "cost": "bar", + "timestamp": "bar", + }], ) - assert_matches_type(DataStreamResponse, data, path=["response"]) + assert_matches_type(DataStreamResponse, data, path=['response']) @parametrize async def test_raw_response_stream(self, async_client: AsyncOpenlayer) -> None: + response = await async_client.inference_pipelines.data.with_raw_response.stream( "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", - config={"output_column_name": "output"}, - rows=[ - { - "user_query": "bar", - "output": "bar", - "tokens": "bar", - "cost": "bar", - "timestamp": "bar", - } - ], + config={ + "output_column_name": "output" + }, + rows=[{ + "user_query": "bar", + "output": "bar", + "tokens": "bar", + "cost": "bar", + "timestamp": "bar", + }], ) assert response.is_closed is True - assert response.http_request.headers.get("X-Stainless-Lang") == "python" + assert response.http_request.headers.get('X-Stainless-Lang') == 'python' data = await response.parse() - assert_matches_type(DataStreamResponse, data, path=["response"]) + assert_matches_type(DataStreamResponse, data, path=['response']) @parametrize async def test_streaming_response_stream(self, async_client: AsyncOpenlayer) -> None: async with async_client.inference_pipelines.data.with_streaming_response.stream( "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", - config={"output_column_name": "output"}, - rows=[ - { - "user_query": "bar", - "output": "bar", - "tokens": "bar", - "cost": "bar", - "timestamp": "bar", - } - ], - ) as response: + config={ + "output_column_name": "output" + }, + rows=[{ + "user_query": "bar", + "output": "bar", + "tokens": "bar", + "cost": "bar", + "timestamp": "bar", + }], + ) as response : assert not response.is_closed - assert response.http_request.headers.get("X-Stainless-Lang") == "python" + assert response.http_request.headers.get('X-Stainless-Lang') == 'python' data = await response.parse() - assert_matches_type(DataStreamResponse, data, path=["response"]) + assert_matches_type(DataStreamResponse, data, path=['response']) assert cast(Any, response.is_closed) is True @parametrize async def test_path_params_stream(self, async_client: AsyncOpenlayer) -> None: with pytest.raises(ValueError, match=r"Expected a non-empty value for `id` but received ''"): - await async_client.inference_pipelines.data.with_raw_response.stream( - "", - config={"output_column_name": "output"}, - rows=[ - { - "user_query": "bar", - "output": "bar", - "tokens": "bar", - "cost": "bar", - "timestamp": "bar", - } - ], - ) + await async_client.inference_pipelines.data.with_raw_response.stream( + "", + config={ + "output_column_name": "output" + }, + rows=[{ + "user_query": "bar", + "output": "bar", + "tokens": "bar", + "cost": "bar", + "timestamp": "bar", + }], + ) \ No newline at end of file diff --git a/tests/api_resources/inference_pipelines/test_test_results.py b/tests/api_resources/inference_pipelines/test_test_results.py index 2098230a..081159a6 100644 --- a/tests/api_resources/inference_pipelines/test_test_results.py +++ b/tests/api_resources/inference_pipelines/test_test_results.py @@ -2,27 +2,34 @@ from __future__ import annotations -import os +from openlayer-test import Openlayer, AsyncOpenlayer + +from openlayer-test.types.inference_pipelines import TestResultListResponse + from typing import Any, cast +import os import pytest - -from openlayer import Openlayer, AsyncOpenlayer +import httpx +from typing_extensions import get_args +from typing import Optional +from respx import MockRouter +from openlayer-test import Openlayer, AsyncOpenlayer from tests.utils import assert_matches_type -from openlayer.types.inference_pipelines import TestResultListResponse +from openlayer-test.types.inference_pipelines import test_result_list_params base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") - class TestTestResults: - parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"]) + parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=['loose', 'strict']) + @parametrize def test_method_list(self, client: Openlayer) -> None: test_result = client.inference_pipelines.test_results.list( "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", ) - assert_matches_type(TestResultListResponse, test_result, path=["response"]) + assert_matches_type(TestResultListResponse, test_result, path=['response']) @parametrize def test_method_list_with_all_params(self, client: Openlayer) -> None: @@ -34,49 +41,49 @@ def test_method_list_with_all_params(self, client: Openlayer) -> None: status="passing", type="integrity", ) - assert_matches_type(TestResultListResponse, test_result, path=["response"]) + assert_matches_type(TestResultListResponse, test_result, path=['response']) @parametrize def test_raw_response_list(self, client: Openlayer) -> None: + response = client.inference_pipelines.test_results.with_raw_response.list( "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", ) assert response.is_closed is True - assert response.http_request.headers.get("X-Stainless-Lang") == "python" + assert response.http_request.headers.get('X-Stainless-Lang') == 'python' test_result = response.parse() - assert_matches_type(TestResultListResponse, test_result, path=["response"]) + assert_matches_type(TestResultListResponse, test_result, path=['response']) @parametrize def test_streaming_response_list(self, client: Openlayer) -> None: with client.inference_pipelines.test_results.with_streaming_response.list( "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", - ) as response: + ) as response : assert not response.is_closed - assert response.http_request.headers.get("X-Stainless-Lang") == "python" + assert response.http_request.headers.get('X-Stainless-Lang') == 'python' test_result = response.parse() - assert_matches_type(TestResultListResponse, test_result, path=["response"]) + assert_matches_type(TestResultListResponse, test_result, path=['response']) assert cast(Any, response.is_closed) is True @parametrize def test_path_params_list(self, client: Openlayer) -> None: with pytest.raises(ValueError, match=r"Expected a non-empty value for `id` but received ''"): - client.inference_pipelines.test_results.with_raw_response.list( - "", - ) - - + client.inference_pipelines.test_results.with_raw_response.list( + "", + ) class TestAsyncTestResults: - parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"]) + parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=['loose', 'strict']) + @parametrize async def test_method_list(self, async_client: AsyncOpenlayer) -> None: test_result = await async_client.inference_pipelines.test_results.list( "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", ) - assert_matches_type(TestResultListResponse, test_result, path=["response"]) + assert_matches_type(TestResultListResponse, test_result, path=['response']) @parametrize async def test_method_list_with_all_params(self, async_client: AsyncOpenlayer) -> None: @@ -88,35 +95,36 @@ async def test_method_list_with_all_params(self, async_client: AsyncOpenlayer) - status="passing", type="integrity", ) - assert_matches_type(TestResultListResponse, test_result, path=["response"]) + assert_matches_type(TestResultListResponse, test_result, path=['response']) @parametrize async def test_raw_response_list(self, async_client: AsyncOpenlayer) -> None: + response = await async_client.inference_pipelines.test_results.with_raw_response.list( "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", ) assert response.is_closed is True - assert response.http_request.headers.get("X-Stainless-Lang") == "python" + assert response.http_request.headers.get('X-Stainless-Lang') == 'python' test_result = await response.parse() - assert_matches_type(TestResultListResponse, test_result, path=["response"]) + assert_matches_type(TestResultListResponse, test_result, path=['response']) @parametrize async def test_streaming_response_list(self, async_client: AsyncOpenlayer) -> None: async with async_client.inference_pipelines.test_results.with_streaming_response.list( "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", - ) as response: + ) as response : assert not response.is_closed - assert response.http_request.headers.get("X-Stainless-Lang") == "python" + assert response.http_request.headers.get('X-Stainless-Lang') == 'python' test_result = await response.parse() - assert_matches_type(TestResultListResponse, test_result, path=["response"]) + assert_matches_type(TestResultListResponse, test_result, path=['response']) assert cast(Any, response.is_closed) is True @parametrize async def test_path_params_list(self, async_client: AsyncOpenlayer) -> None: with pytest.raises(ValueError, match=r"Expected a non-empty value for `id` but received ''"): - await async_client.inference_pipelines.test_results.with_raw_response.list( - "", - ) + await async_client.inference_pipelines.test_results.with_raw_response.list( + "", + ) \ No newline at end of file diff --git a/tests/api_resources/projects/test_commits.py b/tests/api_resources/projects/test_commits.py index ab353674..0fc0e3f6 100644 --- a/tests/api_resources/projects/test_commits.py +++ b/tests/api_resources/projects/test_commits.py @@ -2,27 +2,34 @@ from __future__ import annotations -import os +from openlayer-test import Openlayer, AsyncOpenlayer + +from openlayer-test.types.projects import CommitListResponse + from typing import Any, cast +import os import pytest - -from openlayer import Openlayer, AsyncOpenlayer +import httpx +from typing_extensions import get_args +from typing import Optional +from respx import MockRouter +from openlayer-test import Openlayer, AsyncOpenlayer from tests.utils import assert_matches_type -from openlayer.types.projects import CommitListResponse +from openlayer-test.types.projects import commit_list_params base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") - class TestCommits: - parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"]) + parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=['loose', 'strict']) + @parametrize def test_method_list(self, client: Openlayer) -> None: commit = client.projects.commits.list( "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", ) - assert_matches_type(CommitListResponse, commit, path=["response"]) + assert_matches_type(CommitListResponse, commit, path=['response']) @parametrize def test_method_list_with_all_params(self, client: Openlayer) -> None: @@ -31,49 +38,49 @@ def test_method_list_with_all_params(self, client: Openlayer) -> None: page=1, per_page=1, ) - assert_matches_type(CommitListResponse, commit, path=["response"]) + assert_matches_type(CommitListResponse, commit, path=['response']) @parametrize def test_raw_response_list(self, client: Openlayer) -> None: + response = client.projects.commits.with_raw_response.list( "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", ) assert response.is_closed is True - assert response.http_request.headers.get("X-Stainless-Lang") == "python" + assert response.http_request.headers.get('X-Stainless-Lang') == 'python' commit = response.parse() - assert_matches_type(CommitListResponse, commit, path=["response"]) + assert_matches_type(CommitListResponse, commit, path=['response']) @parametrize def test_streaming_response_list(self, client: Openlayer) -> None: with client.projects.commits.with_streaming_response.list( "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", - ) as response: + ) as response : assert not response.is_closed - assert response.http_request.headers.get("X-Stainless-Lang") == "python" + assert response.http_request.headers.get('X-Stainless-Lang') == 'python' commit = response.parse() - assert_matches_type(CommitListResponse, commit, path=["response"]) + assert_matches_type(CommitListResponse, commit, path=['response']) assert cast(Any, response.is_closed) is True @parametrize def test_path_params_list(self, client: Openlayer) -> None: with pytest.raises(ValueError, match=r"Expected a non-empty value for `id` but received ''"): - client.projects.commits.with_raw_response.list( - "", - ) - - + client.projects.commits.with_raw_response.list( + "", + ) class TestAsyncCommits: - parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"]) + parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=['loose', 'strict']) + @parametrize async def test_method_list(self, async_client: AsyncOpenlayer) -> None: commit = await async_client.projects.commits.list( "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", ) - assert_matches_type(CommitListResponse, commit, path=["response"]) + assert_matches_type(CommitListResponse, commit, path=['response']) @parametrize async def test_method_list_with_all_params(self, async_client: AsyncOpenlayer) -> None: @@ -82,35 +89,36 @@ async def test_method_list_with_all_params(self, async_client: AsyncOpenlayer) - page=1, per_page=1, ) - assert_matches_type(CommitListResponse, commit, path=["response"]) + assert_matches_type(CommitListResponse, commit, path=['response']) @parametrize async def test_raw_response_list(self, async_client: AsyncOpenlayer) -> None: + response = await async_client.projects.commits.with_raw_response.list( "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", ) assert response.is_closed is True - assert response.http_request.headers.get("X-Stainless-Lang") == "python" + assert response.http_request.headers.get('X-Stainless-Lang') == 'python' commit = await response.parse() - assert_matches_type(CommitListResponse, commit, path=["response"]) + assert_matches_type(CommitListResponse, commit, path=['response']) @parametrize async def test_streaming_response_list(self, async_client: AsyncOpenlayer) -> None: async with async_client.projects.commits.with_streaming_response.list( "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", - ) as response: + ) as response : assert not response.is_closed - assert response.http_request.headers.get("X-Stainless-Lang") == "python" + assert response.http_request.headers.get('X-Stainless-Lang') == 'python' commit = await response.parse() - assert_matches_type(CommitListResponse, commit, path=["response"]) + assert_matches_type(CommitListResponse, commit, path=['response']) assert cast(Any, response.is_closed) is True @parametrize async def test_path_params_list(self, async_client: AsyncOpenlayer) -> None: with pytest.raises(ValueError, match=r"Expected a non-empty value for `id` but received ''"): - await async_client.projects.commits.with_raw_response.list( - "", - ) + await async_client.projects.commits.with_raw_response.list( + "", + ) \ No newline at end of file diff --git a/tests/api_resources/projects/test_inference_pipelines.py b/tests/api_resources/projects/test_inference_pipelines.py index c676d606..45de3a34 100644 --- a/tests/api_resources/projects/test_inference_pipelines.py +++ b/tests/api_resources/projects/test_inference_pipelines.py @@ -2,27 +2,34 @@ from __future__ import annotations -import os +from openlayer-test import Openlayer, AsyncOpenlayer + +from openlayer-test.types.projects import InferencePipelineListResponse + from typing import Any, cast +import os import pytest - -from openlayer import Openlayer, AsyncOpenlayer +import httpx +from typing_extensions import get_args +from typing import Optional +from respx import MockRouter +from openlayer-test import Openlayer, AsyncOpenlayer from tests.utils import assert_matches_type -from openlayer.types.projects import InferencePipelineListResponse +from openlayer-test.types.projects import inference_pipeline_list_params base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") - class TestInferencePipelines: - parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"]) + parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=['loose', 'strict']) + @parametrize def test_method_list(self, client: Openlayer) -> None: inference_pipeline = client.projects.inference_pipelines.list( "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", ) - assert_matches_type(InferencePipelineListResponse, inference_pipeline, path=["response"]) + assert_matches_type(InferencePipelineListResponse, inference_pipeline, path=['response']) @parametrize def test_method_list_with_all_params(self, client: Openlayer) -> None: @@ -32,49 +39,49 @@ def test_method_list_with_all_params(self, client: Openlayer) -> None: page=1, per_page=1, ) - assert_matches_type(InferencePipelineListResponse, inference_pipeline, path=["response"]) + assert_matches_type(InferencePipelineListResponse, inference_pipeline, path=['response']) @parametrize def test_raw_response_list(self, client: Openlayer) -> None: + response = client.projects.inference_pipelines.with_raw_response.list( "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", ) assert response.is_closed is True - assert response.http_request.headers.get("X-Stainless-Lang") == "python" + assert response.http_request.headers.get('X-Stainless-Lang') == 'python' inference_pipeline = response.parse() - assert_matches_type(InferencePipelineListResponse, inference_pipeline, path=["response"]) + assert_matches_type(InferencePipelineListResponse, inference_pipeline, path=['response']) @parametrize def test_streaming_response_list(self, client: Openlayer) -> None: with client.projects.inference_pipelines.with_streaming_response.list( "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", - ) as response: + ) as response : assert not response.is_closed - assert response.http_request.headers.get("X-Stainless-Lang") == "python" + assert response.http_request.headers.get('X-Stainless-Lang') == 'python' inference_pipeline = response.parse() - assert_matches_type(InferencePipelineListResponse, inference_pipeline, path=["response"]) + assert_matches_type(InferencePipelineListResponse, inference_pipeline, path=['response']) assert cast(Any, response.is_closed) is True @parametrize def test_path_params_list(self, client: Openlayer) -> None: with pytest.raises(ValueError, match=r"Expected a non-empty value for `id` but received ''"): - client.projects.inference_pipelines.with_raw_response.list( - "", - ) - - + client.projects.inference_pipelines.with_raw_response.list( + "", + ) class TestAsyncInferencePipelines: - parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"]) + parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=['loose', 'strict']) + @parametrize async def test_method_list(self, async_client: AsyncOpenlayer) -> None: inference_pipeline = await async_client.projects.inference_pipelines.list( "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", ) - assert_matches_type(InferencePipelineListResponse, inference_pipeline, path=["response"]) + assert_matches_type(InferencePipelineListResponse, inference_pipeline, path=['response']) @parametrize async def test_method_list_with_all_params(self, async_client: AsyncOpenlayer) -> None: @@ -84,35 +91,36 @@ async def test_method_list_with_all_params(self, async_client: AsyncOpenlayer) - page=1, per_page=1, ) - assert_matches_type(InferencePipelineListResponse, inference_pipeline, path=["response"]) + assert_matches_type(InferencePipelineListResponse, inference_pipeline, path=['response']) @parametrize async def test_raw_response_list(self, async_client: AsyncOpenlayer) -> None: + response = await async_client.projects.inference_pipelines.with_raw_response.list( "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", ) assert response.is_closed is True - assert response.http_request.headers.get("X-Stainless-Lang") == "python" + assert response.http_request.headers.get('X-Stainless-Lang') == 'python' inference_pipeline = await response.parse() - assert_matches_type(InferencePipelineListResponse, inference_pipeline, path=["response"]) + assert_matches_type(InferencePipelineListResponse, inference_pipeline, path=['response']) @parametrize async def test_streaming_response_list(self, async_client: AsyncOpenlayer) -> None: async with async_client.projects.inference_pipelines.with_streaming_response.list( "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", - ) as response: + ) as response : assert not response.is_closed - assert response.http_request.headers.get("X-Stainless-Lang") == "python" + assert response.http_request.headers.get('X-Stainless-Lang') == 'python' inference_pipeline = await response.parse() - assert_matches_type(InferencePipelineListResponse, inference_pipeline, path=["response"]) + assert_matches_type(InferencePipelineListResponse, inference_pipeline, path=['response']) assert cast(Any, response.is_closed) is True @parametrize async def test_path_params_list(self, async_client: AsyncOpenlayer) -> None: with pytest.raises(ValueError, match=r"Expected a non-empty value for `id` but received ''"): - await async_client.projects.inference_pipelines.with_raw_response.list( - "", - ) + await async_client.projects.inference_pipelines.with_raw_response.list( + "", + ) \ No newline at end of file diff --git a/tests/api_resources/test_projects.py b/tests/api_resources/test_projects.py index a955b36d..b2530e89 100644 --- a/tests/api_resources/test_projects.py +++ b/tests/api_resources/test_projects.py @@ -2,25 +2,32 @@ from __future__ import annotations -import os +from openlayer-test import Openlayer, AsyncOpenlayer + +from openlayer-test.types import ProjectListResponse + from typing import Any, cast +import os import pytest - -from openlayer import Openlayer, AsyncOpenlayer +import httpx +from typing_extensions import get_args +from typing import Optional +from respx import MockRouter +from openlayer-test import Openlayer, AsyncOpenlayer from tests.utils import assert_matches_type -from openlayer.types import ProjectListResponse +from openlayer-test.types import project_list_params base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") - class TestProjects: - parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"]) + parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=['loose', 'strict']) + @parametrize def test_method_list(self, client: Openlayer) -> None: project = client.projects.list() - assert_matches_type(ProjectListResponse, project, path=["response"]) + assert_matches_type(ProjectListResponse, project, path=['response']) @parametrize def test_method_list_with_all_params(self, client: Openlayer) -> None: @@ -30,36 +37,36 @@ def test_method_list_with_all_params(self, client: Openlayer) -> None: per_page=1, task_type="llm-base", ) - assert_matches_type(ProjectListResponse, project, path=["response"]) + assert_matches_type(ProjectListResponse, project, path=['response']) @parametrize def test_raw_response_list(self, client: Openlayer) -> None: + response = client.projects.with_raw_response.list() assert response.is_closed is True - assert response.http_request.headers.get("X-Stainless-Lang") == "python" + assert response.http_request.headers.get('X-Stainless-Lang') == 'python' project = response.parse() - assert_matches_type(ProjectListResponse, project, path=["response"]) + assert_matches_type(ProjectListResponse, project, path=['response']) @parametrize def test_streaming_response_list(self, client: Openlayer) -> None: - with client.projects.with_streaming_response.list() as response: + with client.projects.with_streaming_response.list() as response : assert not response.is_closed - assert response.http_request.headers.get("X-Stainless-Lang") == "python" + assert response.http_request.headers.get('X-Stainless-Lang') == 'python' project = response.parse() - assert_matches_type(ProjectListResponse, project, path=["response"]) + assert_matches_type(ProjectListResponse, project, path=['response']) assert cast(Any, response.is_closed) is True - - class TestAsyncProjects: - parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"]) + parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=['loose', 'strict']) + @parametrize async def test_method_list(self, async_client: AsyncOpenlayer) -> None: project = await async_client.projects.list() - assert_matches_type(ProjectListResponse, project, path=["response"]) + assert_matches_type(ProjectListResponse, project, path=['response']) @parametrize async def test_method_list_with_all_params(self, async_client: AsyncOpenlayer) -> None: @@ -69,24 +76,25 @@ async def test_method_list_with_all_params(self, async_client: AsyncOpenlayer) - per_page=1, task_type="llm-base", ) - assert_matches_type(ProjectListResponse, project, path=["response"]) + assert_matches_type(ProjectListResponse, project, path=['response']) @parametrize async def test_raw_response_list(self, async_client: AsyncOpenlayer) -> None: + response = await async_client.projects.with_raw_response.list() assert response.is_closed is True - assert response.http_request.headers.get("X-Stainless-Lang") == "python" + assert response.http_request.headers.get('X-Stainless-Lang') == 'python' project = await response.parse() - assert_matches_type(ProjectListResponse, project, path=["response"]) + assert_matches_type(ProjectListResponse, project, path=['response']) @parametrize async def test_streaming_response_list(self, async_client: AsyncOpenlayer) -> None: - async with async_client.projects.with_streaming_response.list() as response: + async with async_client.projects.with_streaming_response.list() as response : assert not response.is_closed - assert response.http_request.headers.get("X-Stainless-Lang") == "python" + assert response.http_request.headers.get('X-Stainless-Lang') == 'python' project = await response.parse() - assert_matches_type(ProjectListResponse, project, path=["response"]) + assert_matches_type(ProjectListResponse, project, path=['response']) - assert cast(Any, response.is_closed) is True + assert cast(Any, response.is_closed) is True \ No newline at end of file diff --git a/tests/conftest.py b/tests/conftest.py index 0857c182..232d3fe2 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,20 +1,22 @@ from __future__ import annotations -import os import asyncio import logging -from typing import TYPE_CHECKING, Iterator, AsyncIterator +from typing import Iterator import pytest -from openlayer import Openlayer, AsyncOpenlayer +import os +from typing import TYPE_CHECKING, AsyncIterator + +from openlayer-test import Openlayer, AsyncOpenlayer if TYPE_CHECKING: - from _pytest.fixtures import FixtureRequest + from _pytest.fixtures import FixtureRequest pytest.register_assert_rewrite("tests.utils") -logging.getLogger("openlayer").setLevel(logging.DEBUG) +logging.getLogger("openlayer-test").setLevel(logging.DEBUG) @pytest.fixture(scope="session") @@ -28,22 +30,20 @@ def event_loop() -> Iterator[asyncio.AbstractEventLoop]: api_key = "My API Key" - @pytest.fixture(scope="session") def client(request: FixtureRequest) -> Iterator[Openlayer]: - strict = getattr(request, "param", True) + strict = getattr(request, 'param', True) if not isinstance(strict, bool): - raise TypeError(f"Unexpected fixture parameter type {type(strict)}, expected {bool}") + raise TypeError(f'Unexpected fixture parameter type {type(strict)}, expected {bool}') - with Openlayer(base_url=base_url, api_key=api_key, _strict_response_validation=strict) as client: + with Openlayer(base_url=base_url, api_key=api_key, _strict_response_validation=strict) as client : yield client - @pytest.fixture(scope="session") async def async_client(request: FixtureRequest) -> AsyncIterator[AsyncOpenlayer]: - strict = getattr(request, "param", True) + strict = getattr(request, 'param', True) if not isinstance(strict, bool): - raise TypeError(f"Unexpected fixture parameter type {type(strict)}, expected {bool}") + raise TypeError(f'Unexpected fixture parameter type {type(strict)}, expected {bool}') - async with AsyncOpenlayer(base_url=base_url, api_key=api_key, _strict_response_validation=strict) as client: + async with AsyncOpenlayer(base_url=base_url, api_key=api_key, _strict_response_validation=strict) as client : yield client diff --git a/tests/test_client.py b/tests/test_client.py index bc8b3c26..6ce88083 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -2,48 +2,51 @@ from __future__ import annotations -import gc -import os -import json +import httpx + +from openlayer-test import Openlayer, AsyncOpenlayer + +from openlayer-test._exceptions import APITimeoutError, APIStatusError, APIResponseValidationError + +from typing import Any, cast + +from pydantic import ValidationError + import asyncio +import gc import inspect +import json +import os import tracemalloc -from typing import Any, Union, cast +from typing import Dict, Any, Union, cast from unittest import mock import httpx import pytest from respx import MockRouter -from pydantic import ValidationError - -from openlayer import Openlayer, AsyncOpenlayer, APIResponseValidationError -from openlayer._types import Omit -from openlayer._models import BaseModel, FinalRequestOptions -from openlayer._constants import RAW_RESPONSE_HEADER -from openlayer._exceptions import APIStatusError, APITimeoutError, APIResponseValidationError -from openlayer._base_client import ( - DEFAULT_TIMEOUT, - HTTPX_DEFAULT_TIMEOUT, - BaseClient, - make_request_options, -) +from openlayer-test import Openlayer, AsyncOpenlayer, APIResponseValidationError +from openlayer-test._models import FinalRequestOptions, BaseModel +from openlayer-test._types import NOT_GIVEN, Headers, NotGiven, Query, Body, Timeout, Omit +from openlayer-test._base_client import DEFAULT_TIMEOUT, HTTPX_DEFAULT_TIMEOUT, BaseClient, RequestOptions, make_request_options +from openlayer-test._streaming import Stream, AsyncStream +from openlayer-test._constants import RAW_RESPONSE_HEADER +from openlayer-test._response import APIResponse, AsyncAPIResponse from .utils import update_env +from typing import cast +from typing import cast base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") api_key = "My API Key" - def _get_params(client: BaseClient[Any, Any]) -> dict[str, str]: - request = client._build_request(FinalRequestOptions(method="get", url="/foo")) - url = httpx.URL(request.url) - return dict(url.params) - + request = client._build_request(FinalRequestOptions(method="get", url='/foo')) + url = httpx.URL(request.url) + return dict(url.params) def _low_retry_timeout(*_args: Any, **_kwargs: Any) -> float: return 0.1 - def _get_open_connections(client: Openlayer | AsyncOpenlayer) -> int: transport = client._client._transport assert isinstance(transport, httpx.HTTPTransport) or isinstance(transport, httpx.AsyncHTTPTransport) @@ -51,7 +54,6 @@ def _get_open_connections(client: Openlayer | AsyncOpenlayer) -> int: pool = transport._pool return len(pool._requests) - class TestOpenlayer: client = Openlayer(base_url=base_url, api_key=api_key, _strict_response_validation=True) @@ -66,9 +68,7 @@ def test_raw_response(self, respx_mock: MockRouter) -> None: @pytest.mark.respx(base_url=base_url) def test_raw_response_for_binary(self, respx_mock: MockRouter) -> None: - respx_mock.post("/foo").mock( - return_value=httpx.Response(200, headers={"Content-Type": "application/binary"}, content='{"foo": "bar"}') - ) + respx_mock.post("/foo").mock(return_value=httpx.Response(200, headers={'Content-Type':'application/binary'}, content='{"foo": "bar"}')) response = self.client.post("/foo", cast_to=httpx.Response) assert response.status_code == 200 @@ -100,58 +100,58 @@ def test_copy_default_options(self) -> None: assert isinstance(self.client.timeout, httpx.Timeout) def test_copy_default_headers(self) -> None: - client = Openlayer( - base_url=base_url, api_key=api_key, _strict_response_validation=True, default_headers={"X-Foo": "bar"} - ) - assert client.default_headers["X-Foo"] == "bar" + client = Openlayer(base_url=base_url, api_key=api_key, _strict_response_validation=True, default_headers={ + "X-Foo": "bar" + }) + assert client.default_headers['X-Foo'] == 'bar' # does not override the already given value when not specified copied = client.copy() - assert copied.default_headers["X-Foo"] == "bar" + assert copied.default_headers['X-Foo'] == 'bar' # merges already given headers - copied = client.copy(default_headers={"X-Bar": "stainless"}) - assert copied.default_headers["X-Foo"] == "bar" - assert copied.default_headers["X-Bar"] == "stainless" + copied = client.copy(default_headers={'X-Bar': 'stainless'}) + assert copied.default_headers['X-Foo'] == 'bar' + assert copied.default_headers['X-Bar'] == 'stainless' # uses new values for any already given headers - copied = client.copy(default_headers={"X-Foo": "stainless"}) - assert copied.default_headers["X-Foo"] == "stainless" + copied = client.copy(default_headers={'X-Foo': 'stainless'}) + assert copied.default_headers['X-Foo'] == 'stainless' # set_default_headers # completely overrides already set values copied = client.copy(set_default_headers={}) - assert copied.default_headers.get("X-Foo") is None + assert copied.default_headers.get('X-Foo') is None - copied = client.copy(set_default_headers={"X-Bar": "Robert"}) - assert copied.default_headers["X-Bar"] == "Robert" + copied = client.copy(set_default_headers={'X-Bar': 'Robert'}) + assert copied.default_headers['X-Bar'] == 'Robert' with pytest.raises( - ValueError, - match="`default_headers` and `set_default_headers` arguments are mutually exclusive", + ValueError, + match='`default_headers` and `set_default_headers` arguments are mutually exclusive', ): - client.copy(set_default_headers={}, default_headers={"X-Foo": "Bar"}) + client.copy(set_default_headers={}, default_headers={'X-Foo': 'Bar'}) def test_copy_default_query(self) -> None: - client = Openlayer( - base_url=base_url, api_key=api_key, _strict_response_validation=True, default_query={"foo": "bar"} - ) - assert _get_params(client)["foo"] == "bar" + client = Openlayer(base_url=base_url, api_key=api_key, _strict_response_validation=True, default_query={ + "foo": "bar" + }) + assert _get_params(client)['foo'] == 'bar' # does not override the already given value when not specified copied = client.copy() - assert _get_params(copied)["foo"] == "bar" + assert _get_params(copied)['foo'] == 'bar' # merges already given params - copied = client.copy(default_query={"bar": "stainless"}) + copied = client.copy(default_query={'bar': 'stainless'}) params = _get_params(copied) - assert params["foo"] == "bar" - assert params["bar"] == "stainless" + assert params['foo'] == 'bar' + assert params['bar'] == 'stainless' # uses new values for any already given headers - copied = client.copy(default_query={"foo": "stainless"}) - assert _get_params(copied)["foo"] == "stainless" + copied = client.copy(default_query={'foo': 'stainless'}) + assert _get_params(copied)['foo'] == 'stainless' # set_default_query @@ -159,21 +159,21 @@ def test_copy_default_query(self) -> None: copied = client.copy(set_default_query={}) assert _get_params(copied) == {} - copied = client.copy(set_default_query={"bar": "Robert"}) - assert _get_params(copied)["bar"] == "Robert" + copied = client.copy(set_default_query={'bar': 'Robert'}) + assert _get_params(copied)['bar'] == 'Robert' with pytest.raises( - ValueError, - # TODO: update - match="`default_query` and `set_default_query` arguments are mutually exclusive", + ValueError, + # TODO: update + match='`default_query` and `set_default_query` arguments are mutually exclusive', ): - client.copy(set_default_query={}, default_query={"foo": "Bar"}) + client.copy(set_default_query={}, default_query={'foo': 'Bar'}) def test_copy_signature(self) -> None: # ensure the same parameters that can be passed to the client are defined in the `.copy()` method init_signature = inspect.signature( - # mypy doesn't like that we access the `__init__` property. - self.client.__init__, # type: ignore[misc] + # mypy doesn't like that we access the `__init__` property. + self.client.__init__, # type: ignore[misc] ) copy_signature = inspect.signature(self.client.copy) exclude_params = {"transport", "proxies", "_strict_response_validation"} @@ -225,10 +225,10 @@ def add_leak(leaks: list[tracemalloc.StatisticDiff], diff: tracemalloc.Statistic # to_raw_response_wrapper leaks through the @functools.wraps() decorator. # # removing the decorator fixes the leak for reasons we don't understand. - "openlayer/_legacy_response.py", - "openlayer/_response.py", + "openlayer-test/_legacy_response.py", + "openlayer-test/_response.py", # pydantic.BaseModel.model_dump || pydantic.BaseModel.dict leak memory for some reason. - "openlayer/_compat.py", + "openlayer-test/_compat.py", # Standard library leaks we don't care about. "/logging/__init__.py", ] @@ -259,9 +259,7 @@ def test_request_timeout(self) -> None: assert timeout == httpx.Timeout(100.0) def test_client_timeout_option(self) -> None: - client = Openlayer( - base_url=base_url, api_key=api_key, _strict_response_validation=True, timeout=httpx.Timeout(0) - ) + client = Openlayer(base_url=base_url, api_key=api_key, _strict_response_validation=True, timeout=httpx.Timeout(0)) request = client._build_request(FinalRequestOptions(method="get", url="/foo")) timeout = httpx.Timeout(**request.extensions["timeout"]) # type: ignore @@ -270,88 +268,70 @@ def test_client_timeout_option(self) -> None: def test_http_client_timeout_option(self) -> None: # custom timeout given to the httpx client should be used with httpx.Client(timeout=None) as http_client: - client = Openlayer( - base_url=base_url, api_key=api_key, _strict_response_validation=True, http_client=http_client - ) + client = Openlayer(base_url=base_url, api_key=api_key, _strict_response_validation=True, http_client=http_client) - request = client._build_request(FinalRequestOptions(method="get", url="/foo")) - timeout = httpx.Timeout(**request.extensions["timeout"]) # type: ignore - assert timeout == httpx.Timeout(None) + request = client._build_request(FinalRequestOptions(method="get", url="/foo")) + timeout = httpx.Timeout(**request.extensions["timeout"]) # type: ignore + assert timeout == httpx.Timeout(None) # no timeout given to the httpx client should not use the httpx default with httpx.Client() as http_client: - client = Openlayer( - base_url=base_url, api_key=api_key, _strict_response_validation=True, http_client=http_client - ) + client = Openlayer(base_url=base_url, api_key=api_key, _strict_response_validation=True, http_client=http_client) - request = client._build_request(FinalRequestOptions(method="get", url="/foo")) - timeout = httpx.Timeout(**request.extensions["timeout"]) # type: ignore - assert timeout == DEFAULT_TIMEOUT + request = client._build_request(FinalRequestOptions(method="get", url="/foo")) + timeout = httpx.Timeout(**request.extensions["timeout"]) # type: ignore + assert timeout == DEFAULT_TIMEOUT # explicitly passing the default timeout currently results in it being ignored with httpx.Client(timeout=HTTPX_DEFAULT_TIMEOUT) as http_client: - client = Openlayer( - base_url=base_url, api_key=api_key, _strict_response_validation=True, http_client=http_client - ) + client = Openlayer(base_url=base_url, api_key=api_key, _strict_response_validation=True, http_client=http_client) - request = client._build_request(FinalRequestOptions(method="get", url="/foo")) - timeout = httpx.Timeout(**request.extensions["timeout"]) # type: ignore - assert timeout == DEFAULT_TIMEOUT # our default + request = client._build_request(FinalRequestOptions(method="get", url="/foo")) + timeout = httpx.Timeout(**request.extensions["timeout"]) # type: ignore + assert timeout == DEFAULT_TIMEOUT # our default async def test_invalid_http_client(self) -> None: - with pytest.raises(TypeError, match="Invalid `http_client` arg"): - async with httpx.AsyncClient() as http_client: - Openlayer( - base_url=base_url, - api_key=api_key, - _strict_response_validation=True, - http_client=cast(Any, http_client), - ) + with pytest.raises(TypeError, match='Invalid `http_client` arg') : + async with httpx.AsyncClient() as http_client : + Openlayer(base_url=base_url, api_key=api_key, _strict_response_validation=True, http_client=cast(Any, http_client)) def test_default_headers_option(self) -> None: - client = Openlayer( - base_url=base_url, api_key=api_key, _strict_response_validation=True, default_headers={"X-Foo": "bar"} - ) - request = client._build_request(FinalRequestOptions(method="get", url="/foo")) - assert request.headers.get("x-foo") == "bar" - assert request.headers.get("x-stainless-lang") == "python" - - client2 = Openlayer( - base_url=base_url, - api_key=api_key, - _strict_response_validation=True, - default_headers={ - "X-Foo": "stainless", - "X-Stainless-Lang": "my-overriding-header", - }, - ) - request = client2._build_request(FinalRequestOptions(method="get", url="/foo")) - assert request.headers.get("x-foo") == "stainless" - assert request.headers.get("x-stainless-lang") == "my-overriding-header" + client = Openlayer(base_url=base_url, api_key=api_key, _strict_response_validation=True, default_headers={ + "X-Foo": "bar" + }) + request = client._build_request(FinalRequestOptions(method="get", url='/foo')) + assert request.headers.get('x-foo') == 'bar' + assert request.headers.get('x-stainless-lang') == 'python' + + client2 = Openlayer(base_url=base_url, api_key=api_key, _strict_response_validation=True, default_headers={ + "X-Foo": "stainless", + "X-Stainless-Lang": "my-overriding-header", + }) + request = client2._build_request(FinalRequestOptions(method="get", url='/foo')) + assert request.headers.get('x-foo') == 'stainless' + assert request.headers.get('x-stainless-lang') == 'my-overriding-header' def test_validate_headers(self) -> None: client = Openlayer(base_url=base_url, api_key=api_key, _strict_response_validation=True) - request = client._build_request(FinalRequestOptions(method="get", url="/foo")) + request = client._build_request(FinalRequestOptions(method="get", url='/foo')) assert request.headers.get("Authorization") == f"Bearer {api_key}" client2 = Openlayer(base_url=base_url, api_key=None, _strict_response_validation=True) with pytest.raises( TypeError, - match="Could not resolve authentication method. Expected the api_key to be set. Or for the `Authorization` headers to be explicitly omitted", + match="Could not resolve authentication method. Expected the api_key to be set. Or for the `Authorization` headers to be explicitly omitted" ): - client2._build_request(FinalRequestOptions(method="get", url="/foo")) + client2._build_request(FinalRequestOptions(method="get", url='/foo')) - request2 = client2._build_request( - FinalRequestOptions(method="get", url="/foo", headers={"Authorization": Omit()}) - ) + request2 = client2._build_request(FinalRequestOptions(method="get", url='/foo', headers={"Authorization": Omit()})) assert request2.headers.get("Authorization") is None def test_default_query_option(self) -> None: - client = Openlayer( - base_url=base_url, api_key=api_key, _strict_response_validation=True, default_query={"query_param": "bar"} - ) - request = client._build_request(FinalRequestOptions(method="get", url="/foo")) + client = Openlayer(base_url=base_url, api_key=api_key, _strict_response_validation=True, default_query={ + "query_param": "bar" + }) + request = client._build_request(FinalRequestOptions(method="get", url='/foo')) url = httpx.URL(request.url) assert dict(url.params) == {"query_param": "bar"} @@ -363,7 +343,7 @@ def test_default_query_option(self) -> None: ) ) url = httpx.URL(request.url) - assert dict(url.params) == {"foo": "baz", "query_param": "overriden"} + assert dict(url.params) == {'foo': 'baz', "query_param": "overriden"} def test_request_extra_json(self) -> None: request = self.client._build_request( @@ -446,7 +426,7 @@ def test_request_extra_query(self) -> None: ), ) params = dict(request.url.params) - assert params == {"bar": "1", "foo": "2"} + assert params == {'bar': '1', 'foo': '2'} # `extra_query` takes priority over `query` when keys clash request = self.client._build_request( @@ -460,7 +440,7 @@ def test_request_extra_query(self) -> None: ), ) params = dict(request.url.params) - assert params == {"foo": "2"} + assert params == {'foo': '2'} def test_multipart_repeating_array(self, client: Openlayer) -> None: request = client._build_request( @@ -499,29 +479,27 @@ class Model1(BaseModel): class Model2(BaseModel): foo: str - respx_mock.get("/foo").mock(return_value=httpx.Response(200, json={"foo": "bar"})) + respx_mock.get('/foo').mock(return_value=httpx.Response(200, json={'foo': 'bar'})) response = self.client.get("/foo", cast_to=cast(Any, Union[Model1, Model2])) assert isinstance(response, Model2) - assert response.foo == "bar" - + assert response.foo == 'bar' @pytest.mark.respx(base_url=base_url) def test_union_response_different_types(self, respx_mock: MockRouter) -> None: """Union of objects with the same field name using a different type""" - class Model1(BaseModel): foo: int class Model2(BaseModel): foo: str - respx_mock.get("/foo").mock(return_value=httpx.Response(200, json={"foo": "bar"})) + respx_mock.get('/foo').mock(return_value=httpx.Response(200, json={'foo': 'bar'})) response = self.client.get("/foo", cast_to=cast(Any, Union[Model1, Model2])) assert isinstance(response, Model2) - assert response.foo == "bar" + assert response.foo == 'bar' - respx_mock.get("/foo").mock(return_value=httpx.Response(200, json={"foo": 1})) + respx_mock.get('/foo').mock(return_value=httpx.Response(200, json={'foo': 1})) response = self.client.get("/foo", cast_to=cast(Any, Union[Model1, Model2])) assert isinstance(response, Model1) @@ -532,7 +510,6 @@ def test_non_application_json_content_type_for_json_data(self, respx_mock: MockR """ Response that sets Content-Type to something other than application/json but returns json data """ - class Model(BaseModel): foo: int @@ -557,23 +534,11 @@ def test_base_url_setter(self) -> None: assert client.base_url == "https://example.com/from_setter/" def test_base_url_env(self) -> None: - with update_env(OPENLAYER_BASE_URL="http://localhost:5000/from/env"): - client = Openlayer(api_key=api_key, _strict_response_validation=True) - assert client.base_url == "http://localhost:5000/from/env/" + with update_env(OPENLAYER_BASE_URL='http://localhost:5000/from/env'): + client = Openlayer(api_key=api_key, _strict_response_validation=True) + assert client.base_url == 'http://localhost:5000/from/env/' - @pytest.mark.parametrize( - "client", - [ - Openlayer(base_url="http://localhost:5000/custom/path/", api_key=api_key, _strict_response_validation=True), - Openlayer( - base_url="http://localhost:5000/custom/path/", - api_key=api_key, - _strict_response_validation=True, - http_client=httpx.Client(), - ), - ], - ids=["standard", "custom http client"], - ) + @pytest.mark.parametrize("client", [Openlayer(base_url="http://localhost:5000/custom/path/", api_key=api_key, _strict_response_validation=True), Openlayer(base_url="http://localhost:5000/custom/path/", api_key=api_key, _strict_response_validation=True, http_client=httpx.Client())], ids = ["standard", "custom http client"]) def test_base_url_trailing_slash(self, client: Openlayer) -> None: request = client._build_request( FinalRequestOptions( @@ -584,19 +549,7 @@ def test_base_url_trailing_slash(self, client: Openlayer) -> None: ) assert request.url == "http://localhost:5000/custom/path/foo" - @pytest.mark.parametrize( - "client", - [ - Openlayer(base_url="http://localhost:5000/custom/path/", api_key=api_key, _strict_response_validation=True), - Openlayer( - base_url="http://localhost:5000/custom/path/", - api_key=api_key, - _strict_response_validation=True, - http_client=httpx.Client(), - ), - ], - ids=["standard", "custom http client"], - ) + @pytest.mark.parametrize("client", [Openlayer(base_url="http://localhost:5000/custom/path/", api_key=api_key, _strict_response_validation=True), Openlayer(base_url="http://localhost:5000/custom/path/", api_key=api_key, _strict_response_validation=True, http_client=httpx.Client())], ids = ["standard", "custom http client"]) def test_base_url_no_trailing_slash(self, client: Openlayer) -> None: request = client._build_request( FinalRequestOptions( @@ -607,19 +560,7 @@ def test_base_url_no_trailing_slash(self, client: Openlayer) -> None: ) assert request.url == "http://localhost:5000/custom/path/foo" - @pytest.mark.parametrize( - "client", - [ - Openlayer(base_url="http://localhost:5000/custom/path/", api_key=api_key, _strict_response_validation=True), - Openlayer( - base_url="http://localhost:5000/custom/path/", - api_key=api_key, - _strict_response_validation=True, - http_client=httpx.Client(), - ), - ], - ids=["standard", "custom http client"], - ) + @pytest.mark.parametrize("client", [Openlayer(base_url="http://localhost:5000/custom/path/", api_key=api_key, _strict_response_validation=True), Openlayer(base_url="http://localhost:5000/custom/path/", api_key=api_key, _strict_response_validation=True, http_client=httpx.Client())], ids = ["standard", "custom http client"]) def test_absolute_request_url(self, client: Openlayer) -> None: request = client._build_request( FinalRequestOptions( @@ -644,9 +585,9 @@ def test_copied_client_does_not_close_http(self) -> None: def test_client_context_manager(self) -> None: client = Openlayer(base_url=base_url, api_key=api_key, _strict_response_validation=True) with client as c2: - assert c2 is client - assert not c2.is_closed() - assert not client.is_closed() + assert c2 is client + assert not c2.is_closed() + assert not client.is_closed() assert client.is_closed() @pytest.mark.respx(base_url=base_url) @@ -663,7 +604,7 @@ class Model(BaseModel): def test_client_max_retries_validation(self) -> None: with pytest.raises(TypeError, match=r"max_retries cannot be None"): - Openlayer(base_url=base_url, api_key=api_key, _strict_response_validation=True, max_retries=cast(Any, None)) + Openlayer(base_url=base_url, api_key=api_key, _strict_response_validation=True, max_retries=cast(Any, None)) @pytest.mark.respx(base_url=base_url) def test_received_text_for_expected_json(self, respx_mock: MockRouter) -> None: @@ -675,7 +616,7 @@ class Model(BaseModel): strict_client = Openlayer(base_url=base_url, api_key=api_key, _strict_response_validation=True) with pytest.raises(APIResponseValidationError): - strict_client.get("/foo", cast_to=Model) + strict_client.get("/foo", cast_to=Model) client = Openlayer(base_url=base_url, api_key=api_key, _strict_response_validation=False) @@ -683,25 +624,25 @@ class Model(BaseModel): assert isinstance(response, str) # type: ignore[unreachable] @pytest.mark.parametrize( - "remaining_retries,retry_after,timeout", - [ - [3, "20", 20], - [3, "0", 0.5], - [3, "-10", 0.5], - [3, "60", 60], - [3, "61", 0.5], - [3, "Fri, 29 Sep 2023 16:26:57 GMT", 20], - [3, "Fri, 29 Sep 2023 16:26:37 GMT", 0.5], - [3, "Fri, 29 Sep 2023 16:26:27 GMT", 0.5], - [3, "Fri, 29 Sep 2023 16:27:37 GMT", 60], - [3, "Fri, 29 Sep 2023 16:27:38 GMT", 0.5], - [3, "99999999999999999999999999999999999", 0.5], - [3, "Zun, 29 Sep 2023 16:26:27 GMT", 0.5], - [3, "", 0.5], - [2, "", 0.5 * 2.0], - [1, "", 0.5 * 4.0], - ], - ) + "remaining_retries,retry_after,timeout", + [ + [ 3, "20", 20 ], + [ 3, "0", 0.5 ], + [ 3, "-10", 0.5 ], + [ 3, "60", 60 ], + [ 3, "61", 0.5 ], + [ 3, "Fri, 29 Sep 2023 16:26:57 GMT", 20 ], + [ 3, "Fri, 29 Sep 2023 16:26:37 GMT", 0.5 ], + [ 3, "Fri, 29 Sep 2023 16:26:27 GMT", 0.5 ], + [ 3, "Fri, 29 Sep 2023 16:27:37 GMT", 60 ], + [ 3, "Fri, 29 Sep 2023 16:27:38 GMT", 0.5 ], + [ 3, "99999999999999999999999999999999999", 0.5 ], + [ 3, "Zun, 29 Sep 2023 16:26:27 GMT", 0.5 ], + [ 3, "", 0.5 ], + [ 2, "", 0.5 * 2.0 ], + [ 1, "", 0.5 * 4.0 ], + ], + ) @mock.patch("time.time", mock.MagicMock(return_value=1696004797)) def test_parse_retry_after_header(self, remaining_retries: int, retry_after: str, timeout: float) -> None: client = Openlayer(base_url=base_url, api_key=api_key, _strict_response_validation=True) @@ -709,83 +650,51 @@ def test_parse_retry_after_header(self, remaining_retries: int, retry_after: str headers = httpx.Headers({"retry-after": retry_after}) options = FinalRequestOptions(method="get", url="/foo", max_retries=3) calculated = client._calculate_retry_timeout(remaining_retries, options, headers) - assert calculated == pytest.approx(timeout, 0.5 * 0.875) # pyright: ignore[reportUnknownMemberType] + assert calculated == pytest.approx(timeout, 0.5 * 0.875) # pyright: ignore[reportUnknownMemberType] - @mock.patch("openlayer._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout) + @mock.patch("openlayer-test._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout) @pytest.mark.respx(base_url=base_url) def test_retrying_timeout_errors_doesnt_leak(self, respx_mock: MockRouter) -> None: - respx_mock.post("/inference-pipelines/182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e/data-stream").mock( - side_effect=httpx.TimeoutException("Test timeout error") - ) + respx_mock.post("/inference-pipelines/182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e/data-stream").mock(side_effect=httpx.TimeoutException("Test timeout error")) with pytest.raises(APITimeoutError): - self.client.post( - "/inference-pipelines/182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e/data-stream", - body=cast( - object, - dict( - config={ - "input_variable_names": ["user_query"], - "output_column_name": "output", - "num_of_token_column_name": "tokens", - "cost_column_name": "cost", - "timestamp_column_name": "timestamp", - }, - rows=[ - { - "user_query": "what's the meaning of life?", - "output": "42", - "tokens": 7, - "cost": 0.02, - "timestamp": 1620000000, - } - ], - ), - ), - cast_to=httpx.Response, - options={"headers": {RAW_RESPONSE_HEADER: "stream"}}, - ) + self.client.post("/inference-pipelines/182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e/data-stream", body=cast(object, dict(config={ + "input_variable_names": ["user_query"], + "output_column_name": "output", + "num_of_token_column_name": "tokens", + "cost_column_name": "cost", + "timestamp_column_name": "timestamp", + }, rows=[{ + "user_query": "what's the meaning of life?", + "output": "42", + "tokens": 7, + "cost": 0.02, + "timestamp": 1620000000, + }])), cast_to=httpx.Response, options={"headers": {RAW_RESPONSE_HEADER: "stream"}}) assert _get_open_connections(self.client) == 0 - @mock.patch("openlayer._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout) + @mock.patch("openlayer-test._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout) @pytest.mark.respx(base_url=base_url) def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter) -> None: - respx_mock.post("/inference-pipelines/182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e/data-stream").mock( - return_value=httpx.Response(500) - ) + respx_mock.post("/inference-pipelines/182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e/data-stream").mock(return_value=httpx.Response(500)) with pytest.raises(APIStatusError): - self.client.post( - "/inference-pipelines/182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e/data-stream", - body=cast( - object, - dict( - config={ - "input_variable_names": ["user_query"], - "output_column_name": "output", - "num_of_token_column_name": "tokens", - "cost_column_name": "cost", - "timestamp_column_name": "timestamp", - }, - rows=[ - { - "user_query": "what's the meaning of life?", - "output": "42", - "tokens": 7, - "cost": 0.02, - "timestamp": 1620000000, - } - ], - ), - ), - cast_to=httpx.Response, - options={"headers": {RAW_RESPONSE_HEADER: "stream"}}, - ) + self.client.post("/inference-pipelines/182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e/data-stream", body=cast(object, dict(config={ + "input_variable_names": ["user_query"], + "output_column_name": "output", + "num_of_token_column_name": "tokens", + "cost_column_name": "cost", + "timestamp_column_name": "timestamp", + }, rows=[{ + "user_query": "what's the meaning of life?", + "output": "42", + "tokens": 7, + "cost": 0.02, + "timestamp": 1620000000, + }])), cast_to=httpx.Response, options={"headers": {RAW_RESPONSE_HEADER: "stream"}}) assert _get_open_connections(self.client) == 0 - - class TestAsyncOpenlayer: client = AsyncOpenlayer(base_url=base_url, api_key=api_key, _strict_response_validation=True) @@ -802,9 +711,7 @@ async def test_raw_response(self, respx_mock: MockRouter) -> None: @pytest.mark.respx(base_url=base_url) @pytest.mark.asyncio async def test_raw_response_for_binary(self, respx_mock: MockRouter) -> None: - respx_mock.post("/foo").mock( - return_value=httpx.Response(200, headers={"Content-Type": "application/binary"}, content='{"foo": "bar"}') - ) + respx_mock.post("/foo").mock(return_value=httpx.Response(200, headers={'Content-Type':'application/binary'}, content='{"foo": "bar"}')) response = await self.client.post("/foo", cast_to=httpx.Response) assert response.status_code == 200 @@ -836,58 +743,58 @@ def test_copy_default_options(self) -> None: assert isinstance(self.client.timeout, httpx.Timeout) def test_copy_default_headers(self) -> None: - client = AsyncOpenlayer( - base_url=base_url, api_key=api_key, _strict_response_validation=True, default_headers={"X-Foo": "bar"} - ) - assert client.default_headers["X-Foo"] == "bar" + client = AsyncOpenlayer(base_url=base_url, api_key=api_key, _strict_response_validation=True, default_headers={ + "X-Foo": "bar" + }) + assert client.default_headers['X-Foo'] == 'bar' # does not override the already given value when not specified copied = client.copy() - assert copied.default_headers["X-Foo"] == "bar" + assert copied.default_headers['X-Foo'] == 'bar' # merges already given headers - copied = client.copy(default_headers={"X-Bar": "stainless"}) - assert copied.default_headers["X-Foo"] == "bar" - assert copied.default_headers["X-Bar"] == "stainless" + copied = client.copy(default_headers={'X-Bar': 'stainless'}) + assert copied.default_headers['X-Foo'] == 'bar' + assert copied.default_headers['X-Bar'] == 'stainless' # uses new values for any already given headers - copied = client.copy(default_headers={"X-Foo": "stainless"}) - assert copied.default_headers["X-Foo"] == "stainless" + copied = client.copy(default_headers={'X-Foo': 'stainless'}) + assert copied.default_headers['X-Foo'] == 'stainless' # set_default_headers # completely overrides already set values copied = client.copy(set_default_headers={}) - assert copied.default_headers.get("X-Foo") is None + assert copied.default_headers.get('X-Foo') is None - copied = client.copy(set_default_headers={"X-Bar": "Robert"}) - assert copied.default_headers["X-Bar"] == "Robert" + copied = client.copy(set_default_headers={'X-Bar': 'Robert'}) + assert copied.default_headers['X-Bar'] == 'Robert' with pytest.raises( - ValueError, - match="`default_headers` and `set_default_headers` arguments are mutually exclusive", + ValueError, + match='`default_headers` and `set_default_headers` arguments are mutually exclusive', ): - client.copy(set_default_headers={}, default_headers={"X-Foo": "Bar"}) + client.copy(set_default_headers={}, default_headers={'X-Foo': 'Bar'}) def test_copy_default_query(self) -> None: - client = AsyncOpenlayer( - base_url=base_url, api_key=api_key, _strict_response_validation=True, default_query={"foo": "bar"} - ) - assert _get_params(client)["foo"] == "bar" + client = AsyncOpenlayer(base_url=base_url, api_key=api_key, _strict_response_validation=True, default_query={ + "foo": "bar" + }) + assert _get_params(client)['foo'] == 'bar' # does not override the already given value when not specified copied = client.copy() - assert _get_params(copied)["foo"] == "bar" + assert _get_params(copied)['foo'] == 'bar' # merges already given params - copied = client.copy(default_query={"bar": "stainless"}) + copied = client.copy(default_query={'bar': 'stainless'}) params = _get_params(copied) - assert params["foo"] == "bar" - assert params["bar"] == "stainless" + assert params['foo'] == 'bar' + assert params['bar'] == 'stainless' # uses new values for any already given headers - copied = client.copy(default_query={"foo": "stainless"}) - assert _get_params(copied)["foo"] == "stainless" + copied = client.copy(default_query={'foo': 'stainless'}) + assert _get_params(copied)['foo'] == 'stainless' # set_default_query @@ -895,21 +802,21 @@ def test_copy_default_query(self) -> None: copied = client.copy(set_default_query={}) assert _get_params(copied) == {} - copied = client.copy(set_default_query={"bar": "Robert"}) - assert _get_params(copied)["bar"] == "Robert" + copied = client.copy(set_default_query={'bar': 'Robert'}) + assert _get_params(copied)['bar'] == 'Robert' with pytest.raises( - ValueError, - # TODO: update - match="`default_query` and `set_default_query` arguments are mutually exclusive", + ValueError, + # TODO: update + match='`default_query` and `set_default_query` arguments are mutually exclusive', ): - client.copy(set_default_query={}, default_query={"foo": "Bar"}) + client.copy(set_default_query={}, default_query={'foo': 'Bar'}) def test_copy_signature(self) -> None: # ensure the same parameters that can be passed to the client are defined in the `.copy()` method init_signature = inspect.signature( - # mypy doesn't like that we access the `__init__` property. - self.client.__init__, # type: ignore[misc] + # mypy doesn't like that we access the `__init__` property. + self.client.__init__, # type: ignore[misc] ) copy_signature = inspect.signature(self.client.copy) exclude_params = {"transport", "proxies", "_strict_response_validation"} @@ -961,10 +868,10 @@ def add_leak(leaks: list[tracemalloc.StatisticDiff], diff: tracemalloc.Statistic # to_raw_response_wrapper leaks through the @functools.wraps() decorator. # # removing the decorator fixes the leak for reasons we don't understand. - "openlayer/_legacy_response.py", - "openlayer/_response.py", + "openlayer-test/_legacy_response.py", + "openlayer-test/_response.py", # pydantic.BaseModel.model_dump || pydantic.BaseModel.dict leak memory for some reason. - "openlayer/_compat.py", + "openlayer-test/_compat.py", # Standard library leaks we don't care about. "/logging/__init__.py", ] @@ -995,9 +902,7 @@ async def test_request_timeout(self) -> None: assert timeout == httpx.Timeout(100.0) async def test_client_timeout_option(self) -> None: - client = AsyncOpenlayer( - base_url=base_url, api_key=api_key, _strict_response_validation=True, timeout=httpx.Timeout(0) - ) + client = AsyncOpenlayer(base_url=base_url, api_key=api_key, _strict_response_validation=True, timeout=httpx.Timeout(0)) request = client._build_request(FinalRequestOptions(method="get", url="/foo")) timeout = httpx.Timeout(**request.extensions["timeout"]) # type: ignore @@ -1006,88 +911,70 @@ async def test_client_timeout_option(self) -> None: async def test_http_client_timeout_option(self) -> None: # custom timeout given to the httpx client should be used async with httpx.AsyncClient(timeout=None) as http_client: - client = AsyncOpenlayer( - base_url=base_url, api_key=api_key, _strict_response_validation=True, http_client=http_client - ) + client = AsyncOpenlayer(base_url=base_url, api_key=api_key, _strict_response_validation=True, http_client=http_client) - request = client._build_request(FinalRequestOptions(method="get", url="/foo")) - timeout = httpx.Timeout(**request.extensions["timeout"]) # type: ignore - assert timeout == httpx.Timeout(None) + request = client._build_request(FinalRequestOptions(method="get", url="/foo")) + timeout = httpx.Timeout(**request.extensions["timeout"]) # type: ignore + assert timeout == httpx.Timeout(None) # no timeout given to the httpx client should not use the httpx default async with httpx.AsyncClient() as http_client: - client = AsyncOpenlayer( - base_url=base_url, api_key=api_key, _strict_response_validation=True, http_client=http_client - ) + client = AsyncOpenlayer(base_url=base_url, api_key=api_key, _strict_response_validation=True, http_client=http_client) - request = client._build_request(FinalRequestOptions(method="get", url="/foo")) - timeout = httpx.Timeout(**request.extensions["timeout"]) # type: ignore - assert timeout == DEFAULT_TIMEOUT + request = client._build_request(FinalRequestOptions(method="get", url="/foo")) + timeout = httpx.Timeout(**request.extensions["timeout"]) # type: ignore + assert timeout == DEFAULT_TIMEOUT # explicitly passing the default timeout currently results in it being ignored async with httpx.AsyncClient(timeout=HTTPX_DEFAULT_TIMEOUT) as http_client: - client = AsyncOpenlayer( - base_url=base_url, api_key=api_key, _strict_response_validation=True, http_client=http_client - ) + client = AsyncOpenlayer(base_url=base_url, api_key=api_key, _strict_response_validation=True, http_client=http_client) - request = client._build_request(FinalRequestOptions(method="get", url="/foo")) - timeout = httpx.Timeout(**request.extensions["timeout"]) # type: ignore - assert timeout == DEFAULT_TIMEOUT # our default + request = client._build_request(FinalRequestOptions(method="get", url="/foo")) + timeout = httpx.Timeout(**request.extensions["timeout"]) # type: ignore + assert timeout == DEFAULT_TIMEOUT # our default def test_invalid_http_client(self) -> None: - with pytest.raises(TypeError, match="Invalid `http_client` arg"): - with httpx.Client() as http_client: - AsyncOpenlayer( - base_url=base_url, - api_key=api_key, - _strict_response_validation=True, - http_client=cast(Any, http_client), - ) + with pytest.raises(TypeError, match='Invalid `http_client` arg') : + with httpx.Client() as http_client : + AsyncOpenlayer(base_url=base_url, api_key=api_key, _strict_response_validation=True, http_client=cast(Any, http_client)) def test_default_headers_option(self) -> None: - client = AsyncOpenlayer( - base_url=base_url, api_key=api_key, _strict_response_validation=True, default_headers={"X-Foo": "bar"} - ) - request = client._build_request(FinalRequestOptions(method="get", url="/foo")) - assert request.headers.get("x-foo") == "bar" - assert request.headers.get("x-stainless-lang") == "python" - - client2 = AsyncOpenlayer( - base_url=base_url, - api_key=api_key, - _strict_response_validation=True, - default_headers={ - "X-Foo": "stainless", - "X-Stainless-Lang": "my-overriding-header", - }, - ) - request = client2._build_request(FinalRequestOptions(method="get", url="/foo")) - assert request.headers.get("x-foo") == "stainless" - assert request.headers.get("x-stainless-lang") == "my-overriding-header" + client = AsyncOpenlayer(base_url=base_url, api_key=api_key, _strict_response_validation=True, default_headers={ + "X-Foo": "bar" + }) + request = client._build_request(FinalRequestOptions(method="get", url='/foo')) + assert request.headers.get('x-foo') == 'bar' + assert request.headers.get('x-stainless-lang') == 'python' + + client2 = AsyncOpenlayer(base_url=base_url, api_key=api_key, _strict_response_validation=True, default_headers={ + "X-Foo": "stainless", + "X-Stainless-Lang": "my-overriding-header", + }) + request = client2._build_request(FinalRequestOptions(method="get", url='/foo')) + assert request.headers.get('x-foo') == 'stainless' + assert request.headers.get('x-stainless-lang') == 'my-overriding-header' def test_validate_headers(self) -> None: client = AsyncOpenlayer(base_url=base_url, api_key=api_key, _strict_response_validation=True) - request = client._build_request(FinalRequestOptions(method="get", url="/foo")) + request = client._build_request(FinalRequestOptions(method="get", url='/foo')) assert request.headers.get("Authorization") == f"Bearer {api_key}" client2 = AsyncOpenlayer(base_url=base_url, api_key=None, _strict_response_validation=True) with pytest.raises( TypeError, - match="Could not resolve authentication method. Expected the api_key to be set. Or for the `Authorization` headers to be explicitly omitted", + match="Could not resolve authentication method. Expected the api_key to be set. Or for the `Authorization` headers to be explicitly omitted" ): - client2._build_request(FinalRequestOptions(method="get", url="/foo")) + client2._build_request(FinalRequestOptions(method="get", url='/foo')) - request2 = client2._build_request( - FinalRequestOptions(method="get", url="/foo", headers={"Authorization": Omit()}) - ) + request2 = client2._build_request(FinalRequestOptions(method="get", url='/foo', headers={"Authorization": Omit()})) assert request2.headers.get("Authorization") is None def test_default_query_option(self) -> None: - client = AsyncOpenlayer( - base_url=base_url, api_key=api_key, _strict_response_validation=True, default_query={"query_param": "bar"} - ) - request = client._build_request(FinalRequestOptions(method="get", url="/foo")) + client = AsyncOpenlayer(base_url=base_url, api_key=api_key, _strict_response_validation=True, default_query={ + "query_param": "bar" + }) + request = client._build_request(FinalRequestOptions(method="get", url='/foo')) url = httpx.URL(request.url) assert dict(url.params) == {"query_param": "bar"} @@ -1099,7 +986,7 @@ def test_default_query_option(self) -> None: ) ) url = httpx.URL(request.url) - assert dict(url.params) == {"foo": "baz", "query_param": "overriden"} + assert dict(url.params) == {'foo': 'baz', "query_param": "overriden"} def test_request_extra_json(self) -> None: request = self.client._build_request( @@ -1182,7 +1069,7 @@ def test_request_extra_query(self) -> None: ), ) params = dict(request.url.params) - assert params == {"bar": "1", "foo": "2"} + assert params == {'bar': '1', 'foo': '2'} # `extra_query` takes priority over `query` when keys clash request = self.client._build_request( @@ -1196,7 +1083,7 @@ def test_request_extra_query(self) -> None: ), ) params = dict(request.url.params) - assert params == {"foo": "2"} + assert params == {'foo': '2'} def test_multipart_repeating_array(self, async_client: AsyncOpenlayer) -> None: request = async_client._build_request( @@ -1235,29 +1122,27 @@ class Model1(BaseModel): class Model2(BaseModel): foo: str - respx_mock.get("/foo").mock(return_value=httpx.Response(200, json={"foo": "bar"})) + respx_mock.get('/foo').mock(return_value=httpx.Response(200, json={'foo': 'bar'})) response = await self.client.get("/foo", cast_to=cast(Any, Union[Model1, Model2])) assert isinstance(response, Model2) - assert response.foo == "bar" - + assert response.foo == 'bar' @pytest.mark.respx(base_url=base_url) async def test_union_response_different_types(self, respx_mock: MockRouter) -> None: """Union of objects with the same field name using a different type""" - class Model1(BaseModel): foo: int class Model2(BaseModel): foo: str - respx_mock.get("/foo").mock(return_value=httpx.Response(200, json={"foo": "bar"})) + respx_mock.get('/foo').mock(return_value=httpx.Response(200, json={'foo': 'bar'})) response = await self.client.get("/foo", cast_to=cast(Any, Union[Model1, Model2])) assert isinstance(response, Model2) - assert response.foo == "bar" + assert response.foo == 'bar' - respx_mock.get("/foo").mock(return_value=httpx.Response(200, json={"foo": 1})) + respx_mock.get('/foo').mock(return_value=httpx.Response(200, json={'foo': 1})) response = await self.client.get("/foo", cast_to=cast(Any, Union[Model1, Model2])) assert isinstance(response, Model1) @@ -1268,7 +1153,6 @@ async def test_non_application_json_content_type_for_json_data(self, respx_mock: """ Response that sets Content-Type to something other than application/json but returns json data """ - class Model(BaseModel): foo: int @@ -1285,9 +1169,7 @@ class Model(BaseModel): assert response.foo == 2 def test_base_url_setter(self) -> None: - client = AsyncOpenlayer( - base_url="https://example.com/from_init", api_key=api_key, _strict_response_validation=True - ) + client = AsyncOpenlayer(base_url="https://example.com/from_init", api_key=api_key, _strict_response_validation=True) assert client.base_url == "https://example.com/from_init/" client.base_url = "https://example.com/from_setter" # type: ignore[assignment] @@ -1295,25 +1177,11 @@ def test_base_url_setter(self) -> None: assert client.base_url == "https://example.com/from_setter/" def test_base_url_env(self) -> None: - with update_env(OPENLAYER_BASE_URL="http://localhost:5000/from/env"): - client = AsyncOpenlayer(api_key=api_key, _strict_response_validation=True) - assert client.base_url == "http://localhost:5000/from/env/" + with update_env(OPENLAYER_BASE_URL='http://localhost:5000/from/env'): + client = AsyncOpenlayer(api_key=api_key, _strict_response_validation=True) + assert client.base_url == 'http://localhost:5000/from/env/' - @pytest.mark.parametrize( - "client", - [ - AsyncOpenlayer( - base_url="http://localhost:5000/custom/path/", api_key=api_key, _strict_response_validation=True - ), - AsyncOpenlayer( - base_url="http://localhost:5000/custom/path/", - api_key=api_key, - _strict_response_validation=True, - http_client=httpx.AsyncClient(), - ), - ], - ids=["standard", "custom http client"], - ) + @pytest.mark.parametrize("client", [AsyncOpenlayer(base_url="http://localhost:5000/custom/path/", api_key=api_key, _strict_response_validation=True), AsyncOpenlayer(base_url="http://localhost:5000/custom/path/", api_key=api_key, _strict_response_validation=True, http_client=httpx.AsyncClient())], ids = ["standard", "custom http client"]) def test_base_url_trailing_slash(self, client: AsyncOpenlayer) -> None: request = client._build_request( FinalRequestOptions( @@ -1324,21 +1192,7 @@ def test_base_url_trailing_slash(self, client: AsyncOpenlayer) -> None: ) assert request.url == "http://localhost:5000/custom/path/foo" - @pytest.mark.parametrize( - "client", - [ - AsyncOpenlayer( - base_url="http://localhost:5000/custom/path/", api_key=api_key, _strict_response_validation=True - ), - AsyncOpenlayer( - base_url="http://localhost:5000/custom/path/", - api_key=api_key, - _strict_response_validation=True, - http_client=httpx.AsyncClient(), - ), - ], - ids=["standard", "custom http client"], - ) + @pytest.mark.parametrize("client", [AsyncOpenlayer(base_url="http://localhost:5000/custom/path/", api_key=api_key, _strict_response_validation=True), AsyncOpenlayer(base_url="http://localhost:5000/custom/path/", api_key=api_key, _strict_response_validation=True, http_client=httpx.AsyncClient())], ids = ["standard", "custom http client"]) def test_base_url_no_trailing_slash(self, client: AsyncOpenlayer) -> None: request = client._build_request( FinalRequestOptions( @@ -1349,21 +1203,7 @@ def test_base_url_no_trailing_slash(self, client: AsyncOpenlayer) -> None: ) assert request.url == "http://localhost:5000/custom/path/foo" - @pytest.mark.parametrize( - "client", - [ - AsyncOpenlayer( - base_url="http://localhost:5000/custom/path/", api_key=api_key, _strict_response_validation=True - ), - AsyncOpenlayer( - base_url="http://localhost:5000/custom/path/", - api_key=api_key, - _strict_response_validation=True, - http_client=httpx.AsyncClient(), - ), - ], - ids=["standard", "custom http client"], - ) + @pytest.mark.parametrize("client", [AsyncOpenlayer(base_url="http://localhost:5000/custom/path/", api_key=api_key, _strict_response_validation=True), AsyncOpenlayer(base_url="http://localhost:5000/custom/path/", api_key=api_key, _strict_response_validation=True, http_client=httpx.AsyncClient())], ids = ["standard", "custom http client"]) def test_absolute_request_url(self, client: AsyncOpenlayer) -> None: request = client._build_request( FinalRequestOptions( @@ -1389,9 +1229,9 @@ async def test_copied_client_does_not_close_http(self) -> None: async def test_client_context_manager(self) -> None: client = AsyncOpenlayer(base_url=base_url, api_key=api_key, _strict_response_validation=True) async with client as c2: - assert c2 is client - assert not c2.is_closed() - assert not client.is_closed() + assert c2 is client + assert not c2.is_closed() + assert not client.is_closed() assert client.is_closed() @pytest.mark.respx(base_url=base_url) @@ -1409,9 +1249,7 @@ class Model(BaseModel): async def test_client_max_retries_validation(self) -> None: with pytest.raises(TypeError, match=r"max_retries cannot be None"): - AsyncOpenlayer( - base_url=base_url, api_key=api_key, _strict_response_validation=True, max_retries=cast(Any, None) - ) + AsyncOpenlayer(base_url=base_url, api_key=api_key, _strict_response_validation=True, max_retries=cast(Any, None)) @pytest.mark.respx(base_url=base_url) @pytest.mark.asyncio @@ -1424,7 +1262,7 @@ class Model(BaseModel): strict_client = AsyncOpenlayer(base_url=base_url, api_key=api_key, _strict_response_validation=True) with pytest.raises(APIResponseValidationError): - await strict_client.get("/foo", cast_to=Model) + await strict_client.get("/foo", cast_to=Model) client = AsyncOpenlayer(base_url=base_url, api_key=api_key, _strict_response_validation=False) @@ -1432,25 +1270,25 @@ class Model(BaseModel): assert isinstance(response, str) # type: ignore[unreachable] @pytest.mark.parametrize( - "remaining_retries,retry_after,timeout", - [ - [3, "20", 20], - [3, "0", 0.5], - [3, "-10", 0.5], - [3, "60", 60], - [3, "61", 0.5], - [3, "Fri, 29 Sep 2023 16:26:57 GMT", 20], - [3, "Fri, 29 Sep 2023 16:26:37 GMT", 0.5], - [3, "Fri, 29 Sep 2023 16:26:27 GMT", 0.5], - [3, "Fri, 29 Sep 2023 16:27:37 GMT", 60], - [3, "Fri, 29 Sep 2023 16:27:38 GMT", 0.5], - [3, "99999999999999999999999999999999999", 0.5], - [3, "Zun, 29 Sep 2023 16:26:27 GMT", 0.5], - [3, "", 0.5], - [2, "", 0.5 * 2.0], - [1, "", 0.5 * 4.0], - ], - ) + "remaining_retries,retry_after,timeout", + [ + [ 3, "20", 20 ], + [ 3, "0", 0.5 ], + [ 3, "-10", 0.5 ], + [ 3, "60", 60 ], + [ 3, "61", 0.5 ], + [ 3, "Fri, 29 Sep 2023 16:26:57 GMT", 20 ], + [ 3, "Fri, 29 Sep 2023 16:26:37 GMT", 0.5 ], + [ 3, "Fri, 29 Sep 2023 16:26:27 GMT", 0.5 ], + [ 3, "Fri, 29 Sep 2023 16:27:37 GMT", 60 ], + [ 3, "Fri, 29 Sep 2023 16:27:38 GMT", 0.5 ], + [ 3, "99999999999999999999999999999999999", 0.5 ], + [ 3, "Zun, 29 Sep 2023 16:26:27 GMT", 0.5 ], + [ 3, "", 0.5 ], + [ 2, "", 0.5 * 2.0 ], + [ 1, "", 0.5 * 4.0 ], + ], + ) @mock.patch("time.time", mock.MagicMock(return_value=1696004797)) @pytest.mark.asyncio async def test_parse_retry_after_header(self, remaining_retries: int, retry_after: str, timeout: float) -> None: @@ -1459,78 +1297,48 @@ async def test_parse_retry_after_header(self, remaining_retries: int, retry_afte headers = httpx.Headers({"retry-after": retry_after}) options = FinalRequestOptions(method="get", url="/foo", max_retries=3) calculated = client._calculate_retry_timeout(remaining_retries, options, headers) - assert calculated == pytest.approx(timeout, 0.5 * 0.875) # pyright: ignore[reportUnknownMemberType] + assert calculated == pytest.approx(timeout, 0.5 * 0.875) # pyright: ignore[reportUnknownMemberType] - @mock.patch("openlayer._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout) + @mock.patch("openlayer-test._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout) @pytest.mark.respx(base_url=base_url) async def test_retrying_timeout_errors_doesnt_leak(self, respx_mock: MockRouter) -> None: - respx_mock.post("/inference-pipelines/182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e/data-stream").mock( - side_effect=httpx.TimeoutException("Test timeout error") - ) + respx_mock.post("/inference-pipelines/182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e/data-stream").mock(side_effect=httpx.TimeoutException("Test timeout error")) with pytest.raises(APITimeoutError): - await self.client.post( - "/inference-pipelines/182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e/data-stream", - body=cast( - object, - dict( - config={ - "input_variable_names": ["user_query"], - "output_column_name": "output", - "num_of_token_column_name": "tokens", - "cost_column_name": "cost", - "timestamp_column_name": "timestamp", - }, - rows=[ - { - "user_query": "what's the meaning of life?", - "output": "42", - "tokens": 7, - "cost": 0.02, - "timestamp": 1620000000, - } - ], - ), - ), - cast_to=httpx.Response, - options={"headers": {RAW_RESPONSE_HEADER: "stream"}}, - ) + await self.client.post("/inference-pipelines/182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e/data-stream", body=cast(object, dict(config={ + "input_variable_names": ["user_query"], + "output_column_name": "output", + "num_of_token_column_name": "tokens", + "cost_column_name": "cost", + "timestamp_column_name": "timestamp", + }, rows=[{ + "user_query": "what's the meaning of life?", + "output": "42", + "tokens": 7, + "cost": 0.02, + "timestamp": 1620000000, + }])), cast_to=httpx.Response, options={"headers": {RAW_RESPONSE_HEADER: "stream"}}) assert _get_open_connections(self.client) == 0 - @mock.patch("openlayer._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout) + @mock.patch("openlayer-test._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout) @pytest.mark.respx(base_url=base_url) async def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter) -> None: - respx_mock.post("/inference-pipelines/182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e/data-stream").mock( - return_value=httpx.Response(500) - ) + respx_mock.post("/inference-pipelines/182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e/data-stream").mock(return_value=httpx.Response(500)) with pytest.raises(APIStatusError): - await self.client.post( - "/inference-pipelines/182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e/data-stream", - body=cast( - object, - dict( - config={ - "input_variable_names": ["user_query"], - "output_column_name": "output", - "num_of_token_column_name": "tokens", - "cost_column_name": "cost", - "timestamp_column_name": "timestamp", - }, - rows=[ - { - "user_query": "what's the meaning of life?", - "output": "42", - "tokens": 7, - "cost": 0.02, - "timestamp": 1620000000, - } - ], - ), - ), - cast_to=httpx.Response, - options={"headers": {RAW_RESPONSE_HEADER: "stream"}}, - ) - - assert _get_open_connections(self.client) == 0 + await self.client.post("/inference-pipelines/182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e/data-stream", body=cast(object, dict(config={ + "input_variable_names": ["user_query"], + "output_column_name": "output", + "num_of_token_column_name": "tokens", + "cost_column_name": "cost", + "timestamp_column_name": "timestamp", + }, rows=[{ + "user_query": "what's the meaning of life?", + "output": "42", + "tokens": 7, + "cost": 0.02, + "timestamp": 1620000000, + }])), cast_to=httpx.Response, options={"headers": {RAW_RESPONSE_HEADER: "stream"}}) + + assert _get_open_connections(self.client) == 0 \ No newline at end of file diff --git a/tests/test_deepcopy.py b/tests/test_deepcopy.py index 03af4657..d912c64b 100644 --- a/tests/test_deepcopy.py +++ b/tests/test_deepcopy.py @@ -1,4 +1,4 @@ -from openlayer._utils import deepcopy_minimal +from openlayer-test._utils import deepcopy_minimal def assert_different_identities(obj1: object, obj2: object) -> None: diff --git a/tests/test_extract_files.py b/tests/test_extract_files.py index 0d33d0a0..1014e579 100644 --- a/tests/test_extract_files.py +++ b/tests/test_extract_files.py @@ -4,8 +4,8 @@ import pytest -from openlayer._types import FileTypes -from openlayer._utils import extract_files +from openlayer-test._types import FileTypes +from openlayer-test._utils import extract_files def test_removes_files_from_input() -> None: diff --git a/tests/test_files.py b/tests/test_files.py index 8c6275bf..87619862 100644 --- a/tests/test_files.py +++ b/tests/test_files.py @@ -4,9 +4,9 @@ import pytest from dirty_equals import IsDict, IsList, IsBytes, IsTuple -from openlayer._files import to_httpx_files, async_to_httpx_files +from openlayer-test._files import to_httpx_files, async_to_httpx_files -readme_path = Path(__file__).parent.parent.joinpath("README.md") +readme_path =Path(__file__).parent.parent.joinpath("README.md") def test_pathlib_includes_file_name() -> None: @@ -16,9 +16,9 @@ def test_pathlib_includes_file_name() -> None: def test_tuple_input() -> None: - result = to_httpx_files([("file", readme_path)]) + result = to_httpx_files([('file', readme_path)]) print(result) - assert result == IsList(IsTuple("file", IsTuple("README.md", IsBytes()))) + assert result == IsList(IsTuple('file', IsTuple('README.md', IsBytes()))) @pytest.mark.asyncio @@ -37,9 +37,9 @@ async def test_async_supports_anyio_path() -> None: @pytest.mark.asyncio async def test_async_tuple_input() -> None: - result = await async_to_httpx_files([("file", readme_path)]) + result = await async_to_httpx_files([('file', readme_path)]) print(result) - assert result == IsList(IsTuple("file", IsTuple("README.md", IsBytes()))) + assert result == IsList(IsTuple('file', IsTuple('README.md', IsBytes()))) def test_string_not_allowed() -> None: @@ -49,3 +49,4 @@ def test_string_not_allowed() -> None: "file": "foo", # type: ignore } ) + diff --git a/tests/test_models.py b/tests/test_models.py index 963a34ff..0232e41c 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -7,9 +7,9 @@ import pydantic from pydantic import Field -from openlayer._utils import PropertyInfo -from openlayer._compat import PYDANTIC_V2, parse_obj, model_dump, model_json -from openlayer._models import BaseModel, construct_type +from openlayer-test._utils import PropertyInfo +from openlayer-test._compat import PYDANTIC_V2, parse_obj, model_dump, model_json +from openlayer-test._models import BaseModel, construct_type class BasicModel(BaseModel): diff --git a/tests/test_qs.py b/tests/test_qs.py index f03db996..7c7d0701 100644 --- a/tests/test_qs.py +++ b/tests/test_qs.py @@ -4,7 +4,7 @@ import pytest -from openlayer._qs import Querystring, stringify +from openlayer-test._qs import Querystring, stringify def test_empty() -> None: diff --git a/tests/test_required_args.py b/tests/test_required_args.py index 430a1acf..4c8ca619 100644 --- a/tests/test_required_args.py +++ b/tests/test_required_args.py @@ -2,7 +2,7 @@ import pytest -from openlayer._utils import required_args +from openlayer-test._utils import required_args def test_too_many_positional_params() -> None: diff --git a/tests/test_response.py b/tests/test_response.py index 10480d31..388822c8 100644 --- a/tests/test_response.py +++ b/tests/test_response.py @@ -6,8 +6,8 @@ import pytest import pydantic -from openlayer import BaseModel, Openlayer, AsyncOpenlayer -from openlayer._response import ( +from openlayer-test import BaseModel, Openlayer, AsyncOpenlayer +from openlayer-test._response import ( APIResponse, BaseAPIResponse, AsyncAPIResponse, @@ -15,8 +15,8 @@ AsyncBinaryAPIResponse, extract_response_type, ) -from openlayer._streaming import Stream -from openlayer._base_client import FinalRequestOptions +from openlayer-test._streaming import Stream +from openlayer-test._base_client import FinalRequestOptions class ConcreteBaseAPIResponse(APIResponse[bytes]): @@ -40,7 +40,7 @@ def test_extract_response_type_direct_classes() -> None: def test_extract_response_type_direct_class_missing_type_arg() -> None: with pytest.raises( RuntimeError, - match="Expected type to have a type argument at index 0 but it did not", + match="Expected type to have a type argument at index 0 but it did not", ): extract_response_type(AsyncAPIResponse) @@ -72,7 +72,7 @@ def test_response_parse_mismatched_basemodel(client: Openlayer) -> None: with pytest.raises( TypeError, - match="Pydantic models must subclass our base model type, e.g. `from openlayer import BaseModel`", + match="Pydantic models must subclass our base model type, e.g. `from openlayer-test import BaseModel`", ): response.parse(to=PydanticModel) @@ -90,7 +90,7 @@ async def test_async_response_parse_mismatched_basemodel(async_client: AsyncOpen with pytest.raises( TypeError, - match="Pydantic models must subclass our base model type, e.g. `from openlayer import BaseModel`", + match="Pydantic models must subclass our base model type, e.g. `from openlayer-test import BaseModel`", ): await response.parse(to=PydanticModel) diff --git a/tests/test_streaming.py b/tests/test_streaming.py index da026347..d86e5195 100644 --- a/tests/test_streaming.py +++ b/tests/test_streaming.py @@ -5,8 +5,8 @@ import httpx import pytest -from openlayer import Openlayer, AsyncOpenlayer -from openlayer._streaming import Stream, AsyncStream, ServerSentEvent +from openlayer-test import Openlayer, AsyncOpenlayer +from openlayer-test._streaming import Stream, AsyncStream, ServerSentEvent @pytest.mark.asyncio @@ -28,7 +28,9 @@ def body() -> Iterator[bytes]: @pytest.mark.asyncio @pytest.mark.parametrize("sync", [True, False], ids=["sync", "async"]) -async def test_data_missing_event(sync: bool, client: Openlayer, async_client: AsyncOpenlayer) -> None: +async def test_data_missing_event( + sync: bool, client: Openlayer, async_client: AsyncOpenlayer +) -> None: def body() -> Iterator[bytes]: yield b'data: {"foo":true}\n' yield b"\n" @@ -44,7 +46,9 @@ def body() -> Iterator[bytes]: @pytest.mark.asyncio @pytest.mark.parametrize("sync", [True, False], ids=["sync", "async"]) -async def test_event_missing_data(sync: bool, client: Openlayer, async_client: AsyncOpenlayer) -> None: +async def test_event_missing_data( + sync: bool, client: Openlayer, async_client: AsyncOpenlayer +) -> None: def body() -> Iterator[bytes]: yield b"event: ping\n" yield b"\n" @@ -60,7 +64,9 @@ def body() -> Iterator[bytes]: @pytest.mark.asyncio @pytest.mark.parametrize("sync", [True, False], ids=["sync", "async"]) -async def test_multiple_events(sync: bool, client: Openlayer, async_client: AsyncOpenlayer) -> None: +async def test_multiple_events( + sync: bool, client: Openlayer, async_client: AsyncOpenlayer +) -> None: def body() -> Iterator[bytes]: yield b"event: ping\n" yield b"\n" @@ -82,7 +88,9 @@ def body() -> Iterator[bytes]: @pytest.mark.asyncio @pytest.mark.parametrize("sync", [True, False], ids=["sync", "async"]) -async def test_multiple_events_with_data(sync: bool, client: Openlayer, async_client: AsyncOpenlayer) -> None: +async def test_multiple_events_with_data( + sync: bool, client: Openlayer, async_client: AsyncOpenlayer +) -> None: def body() -> Iterator[bytes]: yield b"event: ping\n" yield b'data: {"foo":true}\n' @@ -106,7 +114,9 @@ def body() -> Iterator[bytes]: @pytest.mark.asyncio @pytest.mark.parametrize("sync", [True, False], ids=["sync", "async"]) -async def test_multiple_data_lines_with_empty_line(sync: bool, client: Openlayer, async_client: AsyncOpenlayer) -> None: +async def test_multiple_data_lines_with_empty_line( + sync: bool, client: Openlayer, async_client: AsyncOpenlayer +) -> None: def body() -> Iterator[bytes]: yield b"event: ping\n" yield b"data: {\n" @@ -128,7 +138,9 @@ def body() -> Iterator[bytes]: @pytest.mark.asyncio @pytest.mark.parametrize("sync", [True, False], ids=["sync", "async"]) -async def test_data_json_escaped_double_new_line(sync: bool, client: Openlayer, async_client: AsyncOpenlayer) -> None: +async def test_data_json_escaped_double_new_line( + sync: bool, client: Openlayer, async_client: AsyncOpenlayer +) -> None: def body() -> Iterator[bytes]: yield b"event: ping\n" yield b'data: {"foo": "my long\\n\\ncontent"}' @@ -145,7 +157,9 @@ def body() -> Iterator[bytes]: @pytest.mark.asyncio @pytest.mark.parametrize("sync", [True, False], ids=["sync", "async"]) -async def test_multiple_data_lines(sync: bool, client: Openlayer, async_client: AsyncOpenlayer) -> None: +async def test_multiple_data_lines( + sync: bool, client: Openlayer, async_client: AsyncOpenlayer +) -> None: def body() -> Iterator[bytes]: yield b"event: ping\n" yield b"data: {\n" diff --git a/tests/test_transform.py b/tests/test_transform.py index 3f6ede8e..f6b4288e 100644 --- a/tests/test_transform.py +++ b/tests/test_transform.py @@ -8,15 +8,15 @@ import pytest -from openlayer._types import Base64FileInput -from openlayer._utils import ( +from openlayer-test._types import Base64FileInput +from openlayer-test._utils import ( PropertyInfo, transform as _transform, parse_datetime, async_transform as _async_transform, ) -from openlayer._compat import PYDANTIC_V2 -from openlayer._models import BaseModel +from openlayer-test._compat import PYDANTIC_V2 +from openlayer-test._models import BaseModel _T = TypeVar("_T") diff --git a/tests/test_utils/test_proxy.py b/tests/test_utils/test_proxy.py index 7f09e39e..43409f16 100644 --- a/tests/test_utils/test_proxy.py +++ b/tests/test_utils/test_proxy.py @@ -2,7 +2,7 @@ from typing import Any from typing_extensions import override -from openlayer._utils import LazyProxy +from openlayer-test._utils import LazyProxy class RecursiveLazyProxy(LazyProxy[Any]): diff --git a/tests/test_utils/test_typing.py b/tests/test_utils/test_typing.py index 5a33f2d6..fe53eb18 100644 --- a/tests/test_utils/test_typing.py +++ b/tests/test_utils/test_typing.py @@ -2,7 +2,7 @@ from typing import Generic, TypeVar, cast -from openlayer._utils import extract_type_var_from_base +from openlayer-test._utils import extract_type_var_from_base _T = TypeVar("_T") _T2 = TypeVar("_T2") diff --git a/tests/utils.py b/tests/utils.py index 1918bd1e..b4b7d1a7 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -8,8 +8,8 @@ from datetime import date, datetime from typing_extensions import Literal, get_args, get_origin, assert_type -from openlayer._types import NoneType -from openlayer._utils import ( +from openlayer-test._types import NoneType +from openlayer-test._utils import ( is_dict, is_list, is_list_type, @@ -17,8 +17,8 @@ extract_type_arg, is_annotated_type, ) -from openlayer._compat import PYDANTIC_V2, field_outer_type, get_model_fields -from openlayer._models import BaseModel +from openlayer-test._compat import PYDANTIC_V2, field_outer_type, get_model_fields +from openlayer-test._models import BaseModel BaseModelT = TypeVar("BaseModelT", bound=BaseModel)