Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Pydantic model_validate to avoid Pyright warnings #586

Merged
merged 2 commits into from
Jan 15, 2025
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
4 changes: 2 additions & 2 deletions tests/component_handlers/kubernetes/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class TestKubernetesManifest:
"""
),
[
KubernetesManifest(
**{
KubernetesManifest.model_validate(
{
"apiVersion": "v1",
"kind": "ServiceAccount",
"metadata": {"labels": {"foo": "bar"}},
Expand Down
4 changes: 2 additions & 2 deletions tests/component_handlers/topic/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ def test_compare_single_config_correctly():


def test_get_effective_config():
topic_config_response = BrokerConfigResponse(
**{
topic_config_response = BrokerConfigResponse.model_validate(
{
"kind": "KafkaBrokerConfigList",
"metadata": {
"self": "https://pkc-00000.region.provider.confluent.cloud/kafka/v3/clusters/cluster-1/brokers/-/configs",
Expand Down
36 changes: 18 additions & 18 deletions tests/components/streams_bootstrap/test_producer_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ def test_cleaner_helm_name_override(self, producer_app: ProducerApp):
)

def test_output_topics(self):
producer_app = ProducerApp(
name=PRODUCER_APP_NAME,
**{
producer_app = ProducerApp.model_validate(
{
"name": PRODUCER_APP_NAME,
"namespace": "test-namespace",
"values": {
"namespace": "test-namespace",
Expand Down Expand Up @@ -366,9 +366,9 @@ async def test_should_clean_producer_app_and_deploy_clean_up_job_and_delete_clea
)

def test_get_output_topics(self):
producer_app = ProducerApp(
name="my-producer",
**{
producer_app = ProducerApp.model_validate(
{
"name": "my-producer",
"namespace": "test-namespace",
"values": {
"image": "producer-app",
Expand Down Expand Up @@ -418,9 +418,9 @@ async def test_should_not_deploy_clean_up_when_rest(self, mocker: MockerFixture)
},
},
)
producer_app = ProducerApp(
name=PRODUCER_APP_NAME,
**{
producer_app = ProducerApp.model_validate(
{
"name": PRODUCER_APP_NAME,
"namespace": "test-namespace",
"values": {
"image": "registry/producer-app",
Expand Down Expand Up @@ -468,9 +468,9 @@ async def test_should_deploy_clean_up_job_with_values_in_cluster_when_clean(
},
},
)
producer_app = ProducerApp(
name=PRODUCER_APP_NAME,
**{
producer_app = ProducerApp.model_validate(
{
"name": PRODUCER_APP_NAME,
"namespace": "test-namespace",
"values": {
"image": "registry/producer-app",
Expand Down Expand Up @@ -536,9 +536,9 @@ async def test_clean_should_fall_back_to_local_values_when_validation_of_cluster
)

# user defined model
producer_app = ProducerApp(
name=PRODUCER_APP_NAME,
**{
producer_app = ProducerApp.model_validate(
{
"name": PRODUCER_APP_NAME,
"namespace": "test-namespace",
"values": {
"image": "registry/producer-app",
Expand Down Expand Up @@ -586,9 +586,9 @@ async def test_clean_should_fall_back_to_local_values_when_validation_of_cluster

def test_validate_cron_expression(self):
with pytest.raises(ValidationError):
ProducerApp(
name=PRODUCER_APP_NAME,
**{
assert ProducerApp.model_validate(
{
"name": PRODUCER_APP_NAME,
"namespace": "test-namespace",
"values": {
"image": "registry/producer-app",
Expand Down
78 changes: 39 additions & 39 deletions tests/components/streams_bootstrap/test_streams_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ def test_release_name(self):

@pytest.fixture()
def streams_app(self) -> StreamsApp:
return StreamsApp(
name=STREAMS_APP_NAME,
**{
return StreamsApp.model_validate(
{
"name": STREAMS_APP_NAME,
"namespace": "test-namespace",
"values": {
"image": "streamsApp",
Expand All @@ -82,9 +82,9 @@ def streams_app(self) -> StreamsApp:

@pytest.fixture()
def stateful_streams_app(self) -> StreamsApp:
return StreamsApp(
name=STREAMS_APP_NAME,
**{
return StreamsApp.model_validate(
{
"name": STREAMS_APP_NAME,
"namespace": "test-namespace",
"values": {
"image": "streamsApp",
Expand Down Expand Up @@ -141,9 +141,9 @@ def test_cleaner_helm_name_override(self, streams_app: StreamsApp):
)

def test_set_topics(self):
streams_app = StreamsApp(
name=STREAMS_APP_NAME,
**{
streams_app = StreamsApp.model_validate(
{
"name": STREAMS_APP_NAME,
"namespace": "test-namespace",
"values": {
"image": "streamsApp",
Expand Down Expand Up @@ -188,9 +188,9 @@ def test_set_topics(self):
assert "labeledInputPatterns" in kafka_config

def test_no_empty_input_topic(self):
streams_app = StreamsApp(
name=STREAMS_APP_NAME,
**{
streams_app = StreamsApp.model_validate(
{
"name": STREAMS_APP_NAME,
"namespace": "test-namespace",
"values": {
"image": "streamsApp",
Expand Down Expand Up @@ -220,9 +220,9 @@ def test_should_validate(self):
with pytest.raises(
ValueError, match="Define label only if `type` is `pattern` or `None`"
):
StreamsApp(
name=STREAMS_APP_NAME,
**{
assert StreamsApp.model_validate(
{
"name": STREAMS_APP_NAME,
"namespace": "test-namespace",
"values": {
"kafka": {"bootstrapServers": "fake-broker:9092"},
Expand All @@ -242,9 +242,9 @@ def test_should_validate(self):
with pytest.raises(
ValueError, match="Define `label` only if `type` is undefined"
):
StreamsApp(
name=STREAMS_APP_NAME,
**{
assert StreamsApp.model_validate(
{
"name": STREAMS_APP_NAME,
"namespace": "test-namespace",
"values": {
"kafka": {"bootstrapServers": "fake-broker:9092"},
Expand All @@ -261,9 +261,9 @@ def test_should_validate(self):
)

def test_set_streams_output_from_to(self):
streams_app = StreamsApp(
name=STREAMS_APP_NAME,
**{
streams_app = StreamsApp.model_validate(
{
"name": STREAMS_APP_NAME,
"namespace": "test-namespace",
"values": {
"image": "streamsApp",
Expand Down Expand Up @@ -301,9 +301,9 @@ def test_set_streams_output_from_to(self):
)

def test_weave_inputs_from_prev_component(self):
streams_app = StreamsApp(
name=STREAMS_APP_NAME,
**{
streams_app = StreamsApp.model_validate(
{
"name": STREAMS_APP_NAME,
"namespace": "test-namespace",
"values": {
"image": "streamsApp",
Expand Down Expand Up @@ -338,9 +338,9 @@ def test_weave_inputs_from_prev_component(self):
]

async def test_deploy_order_when_dry_run_is_false(self, mocker: MockerFixture):
streams_app = StreamsApp(
name=STREAMS_APP_NAME,
**{
streams_app = StreamsApp.model_validate(
{
"name": STREAMS_APP_NAME,
"namespace": "test-namespace",
"values": {
"image": "streamsApp",
Expand Down Expand Up @@ -617,9 +617,9 @@ async def test_should_deploy_clean_up_job_with_values_in_cluster_when_reset(
},
},
)
streams_app = StreamsApp(
name=STREAMS_APP_NAME,
**{
streams_app = StreamsApp.model_validate(
{
"name": STREAMS_APP_NAME,
"namespace": "test-namespace",
"values": {
"image": "registry/streams-app",
Expand Down Expand Up @@ -696,9 +696,9 @@ async def test_should_deploy_clean_up_job_with_values_in_cluster_when_clean(
},
},
)
streams_app = StreamsApp(
name=STREAMS_APP_NAME,
**{
streams_app = StreamsApp.model_validate(
{
"name": STREAMS_APP_NAME,
"namespace": "test-namespace",
"values": {
"image": "registry/streams-app",
Expand Down Expand Up @@ -754,9 +754,9 @@ async def test_should_deploy_clean_up_job_with_values_in_cluster_when_clean(
)

async def test_get_input_output_topics(self):
streams_app = StreamsApp(
name="my-app",
**{
streams_app = StreamsApp.model_validate(
{
"name": "my-app",
"namespace": "test-namespace",
"values": {
"image": "registry/streams-app",
Expand Down Expand Up @@ -985,9 +985,9 @@ async def test_clean_should_fall_back_to_local_values_when_validation_of_cluster
},
)

streams_app = StreamsApp(
name=STREAMS_APP_NAME,
**{
streams_app = StreamsApp.model_validate(
{
"name": STREAMS_APP_NAME,
"namespace": "test-namespace",
"values": {
"image": "registry/streams-app",
Expand Down
22 changes: 11 additions & 11 deletions tests/components/streams_bootstrap/test_streams_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
@pytest.mark.usefixtures("mock_env")
class TestStreamsBootstrap:
def test_default_configs(self):
streams_bootstrap = StreamsBootstrap(
name="example-name",
**{
streams_bootstrap = StreamsBootstrap.model_validate(
{
"name": "example-name",
"namespace": "test-namespace",
"values": {
"image": "streamsBootstrap",
Expand All @@ -46,9 +46,9 @@ def test_default_configs(self):
assert streams_bootstrap.values.image_tag is None

async def test_should_deploy_streams_bootstrap_app(self, mocker: MockerFixture):
streams_bootstrap = StreamsBootstrap(
name="example-name",
**{
streams_bootstrap = StreamsBootstrap.model_validate(
{
"name": "example-name",
"namespace": "test-namespace",
"values": {
"image": "streamsBootstrap",
Expand Down Expand Up @@ -101,8 +101,8 @@ async def test_should_raise_validation_error_for_invalid_image_tag(self):
"1 validation error for StreamsBootstrapValues\nimageTag\n String should match pattern '^[a-zA-Z0-9_][a-zA-Z0-9._-]{0,127}$'"
),
):
StreamsBootstrapValues(
**{
assert StreamsBootstrapValues.model_validate(
{
"image": "streamsBootstrap",
"imageTag": "invalid image tag!",
"kafka": {
Expand All @@ -118,9 +118,9 @@ async def test_should_raise_validation_error_for_invalid_helm_chart_version(self
"When using the streams-bootstrap component your version ('2.1.0') must be at least 3.0.1."
),
):
StreamsBootstrap(
name="example-name",
**{
assert StreamsBootstrap.model_validate(
{
"name": "example-name",
"namespace": "test-namespace",
"values": {
"imageTag": "1.0.0",
Expand Down
36 changes: 18 additions & 18 deletions tests/components/streams_bootstrap_v2/test_producer_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ def test_release_name(self):

@pytest.fixture()
def producer_app(self) -> ProducerAppV2:
return ProducerAppV2(
name=PRODUCER_APP_NAME,
**{
return ProducerAppV2.model_validate(
{
"name": PRODUCER_APP_NAME,
"version": "2.4.2",
"namespace": "test-namespace",
"values": {
Expand Down Expand Up @@ -87,9 +87,9 @@ def test_cleaner_helm_name_override(self, producer_app: ProducerAppV2):
)

def test_output_topics(self):
producer_app = ProducerAppV2(
name=PRODUCER_APP_NAME,
**{
producer_app = ProducerAppV2.model_validate(
{
"name": PRODUCER_APP_NAME,
"namespace": "test-namespace",
"values": {
"namespace": "test-namespace",
Expand Down Expand Up @@ -325,9 +325,9 @@ async def test_should_clean_producer_app_and_deploy_clean_up_job_and_delete_clea
)

def test_get_output_topics(self):
producer_app = ProducerAppV2(
name="my-producer",
**{
producer_app = ProducerAppV2.model_validate(
{
"name": "my-producer",
"namespace": "test-namespace",
"values": {
"namespace": "test-namespace",
Expand Down Expand Up @@ -376,9 +376,9 @@ async def test_should_not_deploy_clean_up_when_rest(self, mocker: MockerFixture)
},
},
)
producer_app = ProducerAppV2(
name=PRODUCER_APP_NAME,
**{
producer_app = ProducerAppV2.model_validate(
{
"name": PRODUCER_APP_NAME,
"namespace": "test-namespace",
"values": {
"imageTag": "2.2.2",
Expand Down Expand Up @@ -425,9 +425,9 @@ async def test_should_deploy_clean_up_job_with_values_in_cluster_when_clean(
},
},
)
producer_app = ProducerAppV2(
name=PRODUCER_APP_NAME,
**{
producer_app = ProducerAppV2.model_validate(
{
"name": PRODUCER_APP_NAME,
"namespace": "test-namespace",
"values": {
"imageTag": "2.2.2",
Expand Down Expand Up @@ -492,9 +492,9 @@ async def test_clean_should_fall_back_to_local_values_when_validation_of_cluster
)

# user defined model
producer_app = ProducerAppV2(
name=PRODUCER_APP_NAME,
**{
producer_app = ProducerAppV2.model_validate(
{
"name": PRODUCER_APP_NAME,
"namespace": "test-namespace",
"values": {
"image": "registry/producer-app",
Expand Down
Loading
Loading