Skip to content

Commit

Permalink
Black formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
jhamon committed Jul 18, 2024
1 parent 2c48823 commit 5818072
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 13 deletions.
4 changes: 1 addition & 3 deletions pinecone/control/pinecone.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,9 +540,7 @@ def describe_index(self, name: str):
host = description.host
self.index_host_store.set_host(self.config, name, host)

return IndexModel(
description
)
return IndexModel(description)

def configure_index(
self,
Expand Down
2 changes: 1 addition & 1 deletion pinecone/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
"ServerlessSpecDefinition",
"IndexList",
"CollectionList",
"IndexModel"
"IndexModel",
]
3 changes: 3 additions & 0 deletions pinecone/models/index_description.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import NamedTuple, Dict, Optional, Union, Literal


class PodSpecDefinition(NamedTuple):
replicas: int
shards: int
Expand All @@ -8,10 +9,12 @@ class PodSpecDefinition(NamedTuple):
environment: str
metadata_config: Optional[Dict]


class ServerlessSpecDefinition(NamedTuple):
cloud: str
region: str


PodKey = Literal["pod"]
PodSpec = Dict[PodKey, PodSpecDefinition]

Expand Down
3 changes: 2 additions & 1 deletion pinecone/models/index_model.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from pinecone.core.openapi.control.models import IndexModel as OpenAPIIndexModel


class IndexModel:
def __init__(self, index: OpenAPIIndexModel):
self.index = index
Expand All @@ -12,4 +13,4 @@ def __repr__(self):
return repr(self.index)

def __getattr__(self, attr):
return getattr(self.index, attr)
return getattr(self.index, attr)
15 changes: 10 additions & 5 deletions tests/integration/control/pod/test_deletion_protection.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import pytest
from pinecone import PodSpec


class TestDeletionProtection:
def test_deletion_protection(self, client, index_name, environment):
client.create_index(name=index_name, dimension=2, deletion_protection="enabled", spec=PodSpec(environment=environment))
client.create_index(
name=index_name, dimension=2, deletion_protection="enabled", spec=PodSpec(environment=environment)
)
desc = client.describe_index(index_name)
print(desc.deletion_protection)
print(desc.deletion_protection.__class__)
assert desc.deletion_protection == "enabled"

with pytest.raises(Exception) as e:
client.delete_index(index_name)
assert "Deletion protection is enabled for this index" in str(e.value)
Expand All @@ -20,11 +23,13 @@ def test_deletion_protection(self, client, index_name, environment):
client.delete_index(index_name)

def test_configure_index_with_deletion_protection(self, client, index_name, environment):
client.create_index(name=index_name, dimension=2, deletion_protection="enabled", spec=PodSpec(environment=environment))
client.create_index(
name=index_name, dimension=2, deletion_protection="enabled", spec=PodSpec(environment=environment)
)
desc = client.describe_index(index_name)
assert desc.deletion_protection == "enabled"

# Changing replicas only should not change deletion protection
# Changing replicas only should not change deletion protection
client.configure_index(name=index_name, replicas=2)
desc = client.describe_index(index_name)
assert desc.spec.pod.replicas == 2
Expand All @@ -37,4 +42,4 @@ def test_configure_index_with_deletion_protection(self, client, index_name, envi
assert desc.deletion_protection == "disabled"

# Cleanup
client.delete_index(index_name)
client.delete_index(index_name)
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def test_create_index(self, client, create_sl_index_params):
assert desc.name == name
assert desc.dimension == dimension
assert desc.metric == "cosine"
assert desc.deletion_protection is "disabled" # default value
assert desc.deletion_protection is "disabled" # default value

@pytest.mark.parametrize("metric", ["cosine", "euclidean", "dotproduct"])
def test_create_index_with_metric(self, client, create_sl_index_params, metric):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import pytest


class TestDeletionProtection:
def test_deletion_protection(self, client, create_sl_index_params):
name = create_sl_index_params["name"]
client.create_index(**create_sl_index_params, deletion_protection=True)
desc = client.describe_index(name)
assert desc.deletion_protection == "enabled"

with pytest.raises(Exception) as e:
client.delete_index(name)
assert "Deletion protection is enabled for this index" in str(e.value)
Expand All @@ -15,4 +16,4 @@ def test_deletion_protection(self, client, create_sl_index_params):
desc = client.describe_index(name)
assert desc.deletion_protection == "disabled"

client.delete_index(name)
client.delete_index(name)

0 comments on commit 5818072

Please sign in to comment.