Skip to content

Commit

Permalink
add tests for both ContainerProperty and data_types.Enum
Browse files Browse the repository at this point in the history
  • Loading branch information
haakonvt committed Jan 14, 2025
1 parent 6a28412 commit 0765c9e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest

from cognite.client.data_classes._base import UnknownCogniteObject
from cognite.client.data_classes.data_modeling import data_types
from cognite.client.data_classes.data_modeling.containers import (
Constraint,
Container,
Expand Down Expand Up @@ -43,6 +44,18 @@ def test_load_dump__only_required(self, data: dict) -> None:
actual = ContainerProperty.load(data).dump(camel_case=True)
assert data == actual

def test_dump_no_longer_camelCases_everything_when_used(self) -> None:
cp = ContainerProperty(
data_types.Enum(
{
"Closed_I_think": data_types.EnumValue("Valve_is_closed"),
"Opened or not": data_types.EnumValue("Valve is opened"),
}
)
)
assert ContainerProperty._load(cp.dump()) == cp
assert sorted(cp.dump(camel_case=True)["type"]["values"]) == ["Closed_I_think", "Opened or not"] # type: ignore [index]


class TestConstraint:
@pytest.mark.parametrize(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from cognite.client.data_classes._base import UnknownCogniteObject
from cognite.client.data_classes.data_modeling.data_types import (
DirectRelationReference,
Enum,
PropertyType,
PropertyTypeWithUnit,
Text,
Expand Down Expand Up @@ -66,7 +67,7 @@ def test_load_ignore_unknown_properties(self) -> None:
data.pop("unknownProperty")
assert data == actual

def test_load_dump_unkown_property(self) -> None:
def test_load_dump_unknown_property(self) -> None:
data = {"type": "unknowngibberish", "list": True, "unit": {"externalId": "known"}}
obj = PropertyType.load(data)
assert isinstance(obj, UnknownCogniteObject)
Expand All @@ -82,6 +83,29 @@ def test_load_text_without_collation(self) -> None:
data["collation"] = "ucs_basic"
assert data == actual

def test_dump_enum_no_camel_casing_of_user_values(self) -> None:
obj = PropertyType.load(
{
"type": "enum",
"values": {
"string_valWe ird_Case": {
"name": "string_valWe ird_Case",
"description": "Time series with string data points.",
},
"numeric_valWe ird_Case": {
"name": "numeric_valWe ird_Case",
"description": "Time series with double floating point data points.",
},
},
}
)
assert isinstance(obj, Enum)

expected_values = ["numeric_valWe ird_Case", "string_valWe ird_Case"]
assert sorted(obj.values) == expected_values
assert sorted(obj.dump(camel_case=False)["values"]) == expected_values
assert sorted(obj.dump(camel_case=True)["values"]) == expected_values


class TestUnitSupport:
@pytest.mark.parametrize(
Expand Down

0 comments on commit 0765c9e

Please sign in to comment.