Skip to content

Commit 1c009ab

Browse files
committed
Docs update
1 parent 4dfe9ab commit 1c009ab

File tree

2 files changed

+27
-30
lines changed

2 files changed

+27
-30
lines changed

src/superannotate/lib/app/interface/sdk_interface.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3632,13 +3632,12 @@ def item_context(
36323632
overwrite: bool = True,
36333633
) -> ItemContext:
36343634
"""
3635-
Creates an `ItemContext` instance for managing item annotations and metadata.
3635+
Creates an ItemContext for managing item annotations and metadata.
36363636
3637-
The function retrieves the specified project and folder based on the given `path`
3638-
(can be a string path or a tuple of project and folder names/IDs) and locates the
3639-
item by name or ID. It then returns an `ItemContext` object to handle the annotations
3640-
of the specified item. Changes to annotations are automatically saved upon exiting
3641-
the context.
3637+
This function allows you to manage annotations and metadata for an item located within a
3638+
specified project and folder. The path to the item can be provided either as a string or a tuple,
3639+
and you can specify the item using its name or ID.
3640+
It returns an “ItemContext” that automatically saves any changes to annotations when the context is exited.
36423641
36433642
:param path: Specifies the project and folder containing the item. Can be one of:
36443643
- A string path, e.g., "project_name/folder_name".
@@ -3649,7 +3648,7 @@ def item_context(
36493648
:param item: The name or ID of the item for which the context is being created.
36503649
:type item: Union[str, int]
36513650
3652-
:param overwrite: If `True`, annotations are overwritten during saving. Defaults to `True`.
3651+
:param overwrite: If `True`, annotations are overwritten during saving. Defaults is `True`.
36533652
If `False`, raises a `FileChangedError` if the item was modified concurrently.
36543653
:type overwrite: bool
36553654
@@ -3680,20 +3679,23 @@ def item_context(
36803679
Create an `ItemContext` using a tuple of IDs and an item name:
36813680
36823681
.. code-block:: python
3682+
36833683
with client.item_context((101, 202), "item_name") as context:
36843684
value = context.get_component_value("component_id")
36853685
print(value)
36863686
36873687
Save annotations automatically after modifying component values:
36883688
36893689
.. code-block:: python
3690+
36903691
with client.item_context("project_name/folder_name", "item_name", overwrite=True) as context:
36913692
context.set_component_value("component_id", "new_value")
36923693
# No need to call .save(), changes are saved automatically on context exit.
36933694
36943695
Handle exceptions during context execution:
36953696
36963697
.. code-block:: python
3698+
36973699
from superannotate import FileChangedError
36983700
36993701
try:

tests/integration/items/test_item_context.py

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -48,48 +48,43 @@ def _attach_item(path, name):
4848

4949
def _base_test(self, path, item):
5050
with sa.item_context(path, item, overwrite=True) as ic:
51-
print(1111111)
5251
ic.set_component_value("component_id_1", None)
5352
with sa.item_context(path, item, overwrite=False) as ic:
54-
print(222222)
5553
assert ic.get_component_value("component_id_1") is None
56-
print(333333)
5754
ic.set_component_value("component_id_1", "value")
5855
with self.assertRaisesRegexp(
5956
FileChangedError, "The file has changed and overwrite is set to False."
6057
):
6158
with sa.item_context(path, item, overwrite=False) as ic:
62-
print(4444444)
6359
assert ic.get_component_value("component_id_1") == "value"
6460
sa.item_context(path, item, overwrite=True).set_component_value(
6561
"component_id_1", "to crash"
6662
).save()
67-
print(555555)
6863
ic.set_component_value("component_id_1", "value")
6964

7065
def test_overwrite_false(self):
7166
# test root by folder name
7267
self._attach_item(self.PROJECT_NAME, "dummy")
7368
time.sleep(2)
7469
self._base_test(self.PROJECT_NAME, "dummy")
75-
#
76-
# folder = sa.create_folder(self.PROJECT_NAME, folder_name="folder")
77-
# # test from folder by project and folder names
78-
# time.sleep(2)
79-
# path = f"{self.PROJECT_NAME}/folder"
80-
# self._attach_item(path, "dummy")
81-
# self._base_test(path, "dummy")
82-
#
83-
# # test from folder by project and folder names as tuple
84-
# path = (self.PROJECT_NAME, 'folder')
85-
# self._base_test(path, "dummy")
86-
#
87-
# # test from folder by project and folder ids as tuple item name as dict
88-
# self._base_test((self._project['id'], folder['id']), "dummy")
89-
#
90-
# # test from folder by project and folder ids as tuple and item id
91-
# item = sa.search_items(f"{self.PROJECT_NAME}/folder", "dummy")[0]
92-
# self._base_test((self._project['id'], folder['id']), item['id'])
70+
71+
folder = sa.create_folder(self.PROJECT_NAME, folder_name="folder")
72+
# test from folder by project and folder names
73+
time.sleep(2)
74+
path = f"{self.PROJECT_NAME}/folder"
75+
self._attach_item(path, "dummy")
76+
self._base_test(path, "dummy")
77+
78+
# test from folder by project and folder names as tuple
79+
path = (self.PROJECT_NAME, "folder")
80+
self._base_test(path, "dummy")
81+
82+
# test from folder by project and folder ids as tuple item name as dict
83+
self._base_test((self._project["id"], folder["id"]), "dummy")
84+
85+
# test from folder by project and folder ids as tuple and item id
86+
item = sa.search_items(f"{self.PROJECT_NAME}/folder", "dummy")[0]
87+
self._base_test((self._project["id"], folder["id"]), item["id"])
9388

9489

9590
def test_():

0 commit comments

Comments
 (0)