Skip to content

Commit 4df79c5

Browse files
committed
Fix lint
1 parent 28859b0 commit 4df79c5

File tree

2 files changed

+69
-69
lines changed

2 files changed

+69
-69
lines changed

libs/labelbox/src/labelbox/client.py

+9-12
Original file line numberDiff line numberDiff line change
@@ -1808,7 +1808,6 @@ def _format_failed_rows(
18081808

18091809
def get_catalog(self) -> Catalog:
18101810
return Catalog(client=self)
1811-
18121811

18131812
def get_catalog_slices(self) -> List[CatalogSlice]:
18141813
"""
@@ -1829,12 +1828,9 @@ def get_catalog_slices(self) -> List[CatalogSlice]:
18291828
"""
18301829
res = self.execute(query_str)
18311830
return [CatalogSlice(self, sl) for sl in res["catalogSavedQueries"]]
1832-
18331831

18341832
def get_catalog_slice(
1835-
self,
1836-
slice_id: Optional[str] = None,
1837-
slice_name: Optional[str] = None
1833+
self, slice_id: Optional[str] = None, slice_name: Optional[str] = None
18381834
) -> Union[CatalogSlice, List[CatalogSlice]]:
18391835
"""
18401836
Fetches a Slice using either the slice ID or the slice name.
@@ -1844,17 +1840,19 @@ def get_catalog_slice(
18441840
slice_name (Optional[str]): The name of the Slice.
18451841
18461842
Returns:
1847-
Union[CatalogSlice, List[CatalogSlice], ModelSlice, List[ModelSlice]]:
1843+
Union[CatalogSlice, List[CatalogSlice], ModelSlice, List[ModelSlice]]:
18481844
The corresponding Slice object or list of Slice objects.
18491845
18501846
Raises:
18511847
ValueError: If neither or both id and name are provided.
18521848
ResourceNotFoundError: If the slice is not found.
18531849
"""
1854-
if (slice_id is None and slice_name is None) or (slice_id is not None and slice_name is not None):
1850+
if (slice_id is None and slice_name is None) or (
1851+
slice_id is not None and slice_name is not None
1852+
):
18551853
raise ValueError("Provide exactly one of id or name")
18561854

1857-
if slice_id is not None:
1855+
if slice_id is not None:
18581856
query_str = """query getSavedQueryPyApi($id: ID!) {
18591857
getSavedQuery(id: $id) {
18601858
id
@@ -1866,13 +1864,13 @@ def get_catalog_slice(
18661864
}
18671865
}
18681866
"""
1869-
1867+
18701868
res = self.execute(query_str, {"id": slice_id})
18711869
if res is None:
18721870
raise ResourceNotFoundError(CatalogSlice, {"id": slice_id})
1873-
1871+
18741872
return CatalogSlice(self, res["getSavedQuery"])
1875-
1873+
18761874
else:
18771875
slices = self.get_catalog_slices()
18781876
matches = [s for s in slices if s.name == slice_name]
@@ -1883,7 +1881,6 @@ def get_catalog_slice(
18831881
return matches
18841882
else:
18851883
return matches[0]
1886-
18871884

18881885
def is_feature_schema_archived(
18891886
self, ontology_id: str, feature_schema_id: str

libs/labelbox/tests/integration/test_slice.py

+60-57
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
1-
import pytest
21
from typing import Optional
32
from labelbox import Client, CatalogSlice
43

54

6-
def _create_catalog_slice(client: Client, name: str, description: Optional[str] = None) -> str:
7-
"""Creates a catalog slice for testing purposes.
5+
def _create_catalog_slice(
6+
client: Client, name: str, description: Optional[str] = None
7+
) -> str:
8+
"""Creates a catalog slice for testing purposes.
89
9-
Args:
10-
client (Client): Labelbox client instance
11-
name (str): Name of the catalog slice
12-
description (str): Description of the catalog slice
10+
Args:
11+
client (Client): Labelbox client instance
12+
name (str): Name of the catalog slice
13+
description (str): Description of the catalog slice
1314
14-
Returns:
15-
str: ID of the created catalog slice
16-
"""
15+
Returns:
16+
str: ID of the created catalog slice
17+
"""
1718

18-
mutation = """mutation CreateCatalogSlicePyApi($name: String!, $description: String, $query: SearchServiceQuery!, $sorting: [SearchServiceSorting!]) {
19+
mutation = """mutation CreateCatalogSlicePyApi($name: String!, $description: String, $query: SearchServiceQuery!, $sorting: [SearchServiceSorting!]) {
1920
createCatalogSavedQuery(
2021
args: {name: $name, description: $description, filter: $query, sorting: $sorting}
2122
) {
@@ -31,72 +32,72 @@ def _create_catalog_slice(client: Client, name: str, description: Optional[str]
3132
}
3233
"""
3334

34-
params = {
35-
"description": description,
36-
"name": name,
37-
"query": [
38-
{
39-
"type": "media_attribute_asset_type",
40-
"assetType": {
41-
"type": "asset_type",
42-
"assetTypes": [
43-
"image"
44-
]
45-
}
46-
}
47-
],
48-
"sorting": [
49-
{
50-
"field": {
51-
"field": "dataRowCreatedAt",
52-
"verboseName": "Created At"
53-
},
54-
"direction": "DESC",
55-
"metadataSchemaId": None
56-
}
57-
]
58-
}
35+
params = {
36+
"description": description,
37+
"name": name,
38+
"query": [
39+
{
40+
"type": "media_attribute_asset_type",
41+
"assetType": {"type": "asset_type", "assetTypes": ["image"]},
42+
}
43+
],
44+
"sorting": [
45+
{
46+
"field": {
47+
"field": "dataRowCreatedAt",
48+
"verboseName": "Created At",
49+
},
50+
"direction": "DESC",
51+
"metadataSchemaId": None,
52+
}
53+
],
54+
}
5955

60-
result = client.execute(mutation, params, experimental=True)
56+
result = client.execute(mutation, params, experimental=True)
6157

62-
return result["createCatalogSavedQuery"].get("id")
58+
return result["createCatalogSavedQuery"].get("id")
6359

6460

6561
def _delete_catalog_slice(client, slice_id: str) -> bool:
66-
67-
mutation = """mutation DeleteCatalogSlicePyApi($id: ID!) {
62+
mutation = """mutation DeleteCatalogSlicePyApi($id: ID!) {
6863
deleteSavedQuery(args: { id: $id }) {
6964
success
7065
}
7166
}
7267
"""
7368

74-
params = {
75-
"id": slice_id
76-
}
69+
params = {"id": slice_id}
7770

78-
operation_done = True
79-
try:
80-
client.execute(mutation, params, experimental=True)
81-
except Exception as ex:
82-
operation_done = False
71+
operation_done = True
72+
try:
73+
client.execute(mutation, params, experimental=True)
74+
except Exception as ex:
75+
operation_done = False
8376

84-
return operation_done
77+
return operation_done
8578

8679

8780
def test_get_slice(client):
88-
8981
# Pre-cleaning
90-
slices = ( s for s in client.get_catalog_slices()
91-
if s.name in ["Test Slice 1", "Test Slice 2"])
82+
slices = (
83+
s
84+
for s in client.get_catalog_slices()
85+
if s.name in ["Test Slice 1", "Test Slice 2"]
86+
)
9287
for slice in slices:
9388
_delete_catalog_slice(client, slice.id)
94-
89+
9590
# Create slices
96-
slice_id_1 = _create_catalog_slice(client, "Test Slice 1", "Slice created for SDK test.")
97-
slice_id_2 = _create_catalog_slice(client, "Test Slice 2", "Slice created for SDK test.")
91+
slice_id_1 = _create_catalog_slice(
92+
client, "Test Slice 1", "Slice created for SDK test."
93+
)
94+
slice_id_2 = _create_catalog_slice(
95+
client, "Test Slice 2", "Slice created for SDK test."
96+
)
9897
# Create slice 2b - with the same name as slice 2
99-
slice_id_2b = _create_catalog_slice(client, "Test Slice 2", "Slice created for SDK test.")
98+
slice_id_2b = _create_catalog_slice(
99+
client, "Test Slice 2", "Slice created for SDK test."
100+
)
100101

101102
# Assert get slice 1 by ID
102103
slice_1 = client.get_catalog_slice(slice_id_1)
@@ -107,7 +108,9 @@ def test_get_slice(client):
107108

108109
slices_2 = client.get_catalog_slice(slice_name="Test Slice 2")
109110
assert len(slices_2) == 2
110-
assert isinstance(slices_2, list) and all([isinstance(item, CatalogSlice) for item in slices_2])
111+
assert isinstance(slices_2, list) and all(
112+
[isinstance(item, CatalogSlice) for item in slices_2]
113+
)
111114

112115
# Cleaning - Delete slices
113116
_delete_catalog_slice(client, slice_id_1)

0 commit comments

Comments
 (0)