Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,26 @@ jobs:
run: poetry install
- name: Compile
run: poetry run mypy .
test:
runs-on: ubuntu-20.04
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Set up python
uses: actions/setup-python@v4
with:
python-version: 3.8
- name: Bootstrap poetry
run: |
curl -sSL https://install.python-poetry.org | python - -y --version 1.5.1
- name: Install dependencies
run: poetry install

- name: Test
run: poetry run pytest ./tests/custom/

publish:
needs: [compile]
needs: [compile, test]
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
runs-on: ubuntu-20.04
steps:
Expand Down
8 changes: 4 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "humanloop"
version = "0.8.0b11"
version = "0.8.0b12"
description = ""
readme = "README.md"
authors = []
Expand Down
2 changes: 1 addition & 1 deletion src/humanloop/core/client_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def get_headers(self) -> typing.Dict[str, str]:
headers: typing.Dict[str, str] = {
"X-Fern-Language": "Python",
"X-Fern-SDK-Name": "humanloop",
"X-Fern-SDK-Version": "0.8.0b11",
"X-Fern-SDK-Version": "0.8.0b12",
}
headers["X-API-KEY"] = self.api_key
return headers
Expand Down
7 changes: 7 additions & 0 deletions tests/custom/test_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import pytest


# Get started with writing tests with pytest at https://docs.pytest.org
@pytest.mark.skip(reason="Unimplemented")
def test_client() -> None:
assert True == True
2 changes: 2 additions & 0 deletions tests/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# This file was auto-generated by Fern from our API Definition.

21 changes: 21 additions & 0 deletions tests/utils/assets/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# This file was auto-generated by Fern from our API Definition.

# This file was auto-generated by Fern from our API Definition.

from .circle import CircleParams
from .object_with_defaults import ObjectWithDefaultsParams
from .object_with_optional_field import ObjectWithOptionalFieldParams
from .shape import ShapeParams, Shape_CircleParams, Shape_SquareParams
from .square import SquareParams
from .undiscriminated_shape import UndiscriminatedShapeParams

__all__ = [
"CircleParams",
"ObjectWithDefaultsParams",
"ObjectWithOptionalFieldParams",
"ShapeParams",
"Shape_CircleParams",
"Shape_SquareParams",
"SquareParams",
"UndiscriminatedShapeParams",
]
11 changes: 11 additions & 0 deletions tests/utils/assets/models/circle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# This file was auto-generated by Fern from our API Definition.

# This file was auto-generated by Fern from our API Definition.

import typing_extensions
import typing_extensions
from humanloop.core.serialization import FieldMetadata


class CircleParams(typing_extensions.TypedDict):
radius_measurement: typing_extensions.Annotated[float, FieldMetadata(alias="radiusMeasurement")]
7 changes: 7 additions & 0 deletions tests/utils/assets/models/color.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This file was auto-generated by Fern from our API Definition.

# This file was auto-generated by Fern from our API Definition.

import typing

Color = typing.Union[typing.Literal["red", "blue"], typing.Any]
16 changes: 16 additions & 0 deletions tests/utils/assets/models/object_with_defaults.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# This file was auto-generated by Fern from our API Definition.

# This file was auto-generated by Fern from our API Definition.

import typing_extensions
import typing_extensions


class ObjectWithDefaultsParams(typing_extensions.TypedDict):
"""
Defines properties with default values and validation rules.
"""

decimal: typing_extensions.NotRequired[float]
string: typing_extensions.NotRequired[str]
required_string: str
34 changes: 34 additions & 0 deletions tests/utils/assets/models/object_with_optional_field.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# This file was auto-generated by Fern from our API Definition.

# This file was auto-generated by Fern from our API Definition.

import typing_extensions
import typing
import typing_extensions
from humanloop.core.serialization import FieldMetadata
import datetime as dt
import uuid
from .color import Color
from .shape import ShapeParams
from .undiscriminated_shape import UndiscriminatedShapeParams


class ObjectWithOptionalFieldParams(typing_extensions.TypedDict):
literal: typing.Literal["lit_one"]
string: typing_extensions.NotRequired[str]
integer: typing_extensions.NotRequired[int]
long_: typing_extensions.NotRequired[typing_extensions.Annotated[int, FieldMetadata(alias="long")]]
double: typing_extensions.NotRequired[float]
bool_: typing_extensions.NotRequired[typing_extensions.Annotated[bool, FieldMetadata(alias="bool")]]
datetime: typing_extensions.NotRequired[dt.datetime]
date: typing_extensions.NotRequired[dt.date]
uuid_: typing_extensions.NotRequired[typing_extensions.Annotated[uuid.UUID, FieldMetadata(alias="uuid")]]
base_64: typing_extensions.NotRequired[typing_extensions.Annotated[str, FieldMetadata(alias="base64")]]
list_: typing_extensions.NotRequired[typing_extensions.Annotated[typing.Sequence[str], FieldMetadata(alias="list")]]
set_: typing_extensions.NotRequired[typing_extensions.Annotated[typing.Set[str], FieldMetadata(alias="set")]]
map_: typing_extensions.NotRequired[typing_extensions.Annotated[typing.Dict[int, str], FieldMetadata(alias="map")]]
enum: typing_extensions.NotRequired[Color]
union: typing_extensions.NotRequired[ShapeParams]
second_union: typing_extensions.NotRequired[ShapeParams]
undiscriminated_union: typing_extensions.NotRequired[UndiscriminatedShapeParams]
any: typing.Optional[typing.Any]
26 changes: 26 additions & 0 deletions tests/utils/assets/models/shape.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# This file was auto-generated by Fern from our API Definition.

# This file was auto-generated by Fern from our API Definition.

from __future__ import annotations
import typing_extensions
import typing_extensions
import typing
from humanloop.core.serialization import FieldMetadata


class Base(typing_extensions.TypedDict):
id: str


class Shape_CircleParams(Base):
shape_type: typing_extensions.Annotated[typing.Literal["circle"], FieldMetadata(alias="shapeType")]
radius_measurement: typing_extensions.Annotated[float, FieldMetadata(alias="radiusMeasurement")]


class Shape_SquareParams(Base):
shape_type: typing_extensions.Annotated[typing.Literal["square"], FieldMetadata(alias="shapeType")]
length_measurement: typing_extensions.Annotated[float, FieldMetadata(alias="lengthMeasurement")]


ShapeParams = typing.Union[Shape_CircleParams, Shape_SquareParams]
11 changes: 11 additions & 0 deletions tests/utils/assets/models/square.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# This file was auto-generated by Fern from our API Definition.

# This file was auto-generated by Fern from our API Definition.

import typing_extensions
import typing_extensions
from humanloop.core.serialization import FieldMetadata


class SquareParams(typing_extensions.TypedDict):
length_measurement: typing_extensions.Annotated[float, FieldMetadata(alias="lengthMeasurement")]
9 changes: 9 additions & 0 deletions tests/utils/assets/models/undiscriminated_shape.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# This file was auto-generated by Fern from our API Definition.

# This file was auto-generated by Fern from our API Definition.

import typing
from .circle import CircleParams
from .square import SquareParams

UndiscriminatedShapeParams = typing.Union[CircleParams, SquareParams]
61 changes: 61 additions & 0 deletions tests/utils/test_http_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# This file was auto-generated by Fern from our API Definition.

from humanloop.core.http_client import get_request_body
from humanloop.core.request_options import RequestOptions


def get_request_options() -> RequestOptions:
return {"additional_body_parameters": {"see you": "later"}}


def test_get_json_request_body() -> None:
json_body, data_body = get_request_body(json={"hello": "world"}, data=None, request_options=None, omit=None)
assert json_body == {"hello": "world"}
assert data_body is None

json_body_extras, data_body_extras = get_request_body(
json={"goodbye": "world"}, data=None, request_options=get_request_options(), omit=None
)

assert json_body_extras == {"goodbye": "world", "see you": "later"}
assert data_body_extras is None


def test_get_files_request_body() -> None:
json_body, data_body = get_request_body(json=None, data={"hello": "world"}, request_options=None, omit=None)
assert data_body == {"hello": "world"}
assert json_body is None

json_body_extras, data_body_extras = get_request_body(
json=None, data={"goodbye": "world"}, request_options=get_request_options(), omit=None
)

assert data_body_extras == {"goodbye": "world", "see you": "later"}
assert json_body_extras is None


def test_get_none_request_body() -> None:
json_body, data_body = get_request_body(json=None, data=None, request_options=None, omit=None)
assert data_body is None
assert json_body is None

json_body_extras, data_body_extras = get_request_body(
json=None, data=None, request_options=get_request_options(), omit=None
)

assert json_body_extras == {"see you": "later"}
assert data_body_extras is None


def test_get_empty_json_request_body() -> None:
unrelated_request_options: RequestOptions = {"max_retries": 3}
json_body, data_body = get_request_body(json=None, data=None, request_options=unrelated_request_options, omit=None)
assert json_body is None
assert data_body is None

json_body_extras, data_body_extras = get_request_body(
json={}, data=None, request_options=unrelated_request_options, omit=None
)

assert json_body_extras is None
assert data_body_extras is None
37 changes: 37 additions & 0 deletions tests/utils/test_query_encoding.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# This file was auto-generated by Fern from our API Definition.


from humanloop.core.query_encoder import encode_query


def test_query_encoding_deep_objects() -> None:
assert encode_query({"hello world": "hello world"}) == [("hello world", "hello world")]
assert encode_query({"hello_world": {"hello": "world"}}) == [("hello_world[hello]", "world")]
assert encode_query({"hello_world": {"hello": {"world": "today"}, "test": "this"}, "hi": "there"}) == [
("hello_world[hello][world]", "today"),
("hello_world[test]", "this"),
("hi", "there"),
]


def test_query_encoding_deep_object_arrays() -> None:
assert encode_query({"objects": [{"key": "hello", "value": "world"}, {"key": "foo", "value": "bar"}]}) == [
("objects[key]", "hello"),
("objects[value]", "world"),
("objects[key]", "foo"),
("objects[value]", "bar"),
]
assert encode_query(
{"users": [{"name": "string", "tags": ["string"]}, {"name": "string2", "tags": ["string2", "string3"]}]}
) == [
("users[name]", "string"),
("users[tags]", "string"),
("users[name]", "string2"),
("users[tags]", "string2"),
("users[tags]", "string3"),
]


def test_encode_query_with_none() -> None:
encoded = encode_query(None)
assert encoded == None
66 changes: 66 additions & 0 deletions tests/utils/test_serialization.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# This file was auto-generated by Fern from our API Definition.

from typing import List, Any

from humanloop.core.serialization import convert_and_respect_annotation_metadata
from .assets.models import ShapeParams, ObjectWithOptionalFieldParams


UNION_TEST: ShapeParams = {"radius_measurement": 1.0, "shape_type": "circle", "id": "1"}
UNION_TEST_CONVERTED = {"shapeType": "circle", "radiusMeasurement": 1.0, "id": "1"}


def test_convert_and_respect_annotation_metadata() -> None:
data: ObjectWithOptionalFieldParams = {
"string": "string",
"long_": 12345,
"bool_": True,
"literal": "lit_one",
"any": "any",
}
converted = convert_and_respect_annotation_metadata(object_=data, annotation=ObjectWithOptionalFieldParams)
assert converted == {"string": "string", "long": 12345, "bool": True, "literal": "lit_one", "any": "any"}


def test_convert_and_respect_annotation_metadata_in_list() -> None:
data: List[ObjectWithOptionalFieldParams] = [
{"string": "string", "long_": 12345, "bool_": True, "literal": "lit_one", "any": "any"},
{"string": "another string", "long_": 67890, "list_": [], "literal": "lit_one", "any": "any"},
]
converted = convert_and_respect_annotation_metadata(object_=data, annotation=List[ObjectWithOptionalFieldParams])

assert converted == [
{"string": "string", "long": 12345, "bool": True, "literal": "lit_one", "any": "any"},
{"string": "another string", "long": 67890, "list": [], "literal": "lit_one", "any": "any"},
]


def test_convert_and_respect_annotation_metadata_in_nested_object() -> None:
data: ObjectWithOptionalFieldParams = {
"string": "string",
"long_": 12345,
"union": UNION_TEST,
"literal": "lit_one",
"any": "any",
}
converted = convert_and_respect_annotation_metadata(object_=data, annotation=ObjectWithOptionalFieldParams)

assert converted == {
"string": "string",
"long": 12345,
"union": UNION_TEST_CONVERTED,
"literal": "lit_one",
"any": "any",
}


def test_convert_and_respect_annotation_metadata_in_union() -> None:
converted = convert_and_respect_annotation_metadata(object_=UNION_TEST, annotation=ShapeParams)

assert converted == UNION_TEST_CONVERTED


def test_convert_and_respect_annotation_metadata_with_empty_object() -> None:
data: Any = {}
converted = convert_and_respect_annotation_metadata(object_=data, annotation=ShapeParams)
assert converted == data