-
Notifications
You must be signed in to change notification settings - Fork 27
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
enable diagram detect based on file instance id #1887
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1887 +/- ##
==========================================
+ Coverage 90.62% 90.69% +0.06%
==========================================
Files 126 126
Lines 19609 19617 +8
==========================================
+ Hits 17771 17791 +20
+ Misses 1838 1826 -12
|
…to DOG-3974_dm_reference_in_diagram_detect
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some nit picking :)
if self.file_id is None and self.file_external_id is not None: | ||
item: dict[str, str | int | dict[str, int]] = {"fileExternalId": self.file_external_id} | ||
item: dict[str, str | int | dict[str, int] | dict[str, str]] = {"fileExternalId": self.file_external_id} | ||
if self.file_id is not None and self.file_external_id is None: | ||
item = {"fileId": self.file_id} | ||
if self.file_instance_id is not None: | ||
item = {"fileInstanceId": self.file_instance_id.dump(include_instance_type=False)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A situation that should never happen, but this is more robust:
item: dict[str, str | int | dict[str, int] | dict[str, str]] = {}
if self.file_id is None and self.file_external_id is not None and self.file_instance_id is None:
item["fileExternalId"] = self.file_external_id
elif self.file_id is not None and self.file_external_id is None and self.file_instance_id is None:
item["fileId"] = self.file_id
elif self.file_instance_id is not None and self.file_id is None and self.file_external_id is None:
item["fileInstanceId"] = self.file_instance_id.dump(include_instance_type=False)
else:
raise ValueError("Exactly one of file_id, file_external_id and file_instance_id must be set")
|
||
PNID_FILE_ID = 3261066797848581 | ||
DIAGRAM_SPACE = "diagram_space" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you make a fixture to guarantee that this space will exist?
Something like
@pytest.fixture(scope="session")
def diagram_space(cognite_client: CogniteClient) -> Space:
return cognite_client.data_modeling.spaces.apply(SpaceApply(space=DIAGRAM_SPACE))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, could do that, but should also make sure that the file exists in that case. If the space does not exist, then the file cant exist either, so maybe add a file to the repo and upload it if it is not there or what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I missed that. I would also make another fixture for the file then. If the file is not too big or sensitive then commit it to the repo.
@@ -103,3 +106,20 @@ def test_run_diagram_detect_in_pattern_mode(self, cognite_client): | |||
|
|||
assert len(detected_by_resource_type["file_reference"]) >= 10 # 14 seen when making the test | |||
assert len(detected_by_resource_type["instrument"]) >= 60 # 72 seen when making the test | |||
|
|||
def test_run_diagram_detect_with_file_instance_id(self, cognite_client): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def test_run_diagram_detect_with_file_instance_id(self, cognite_client): | |
@pytest.mark.usefixtures("diagram_space") | |
def test_run_diagram_detect_with_file_instance_id(self, cognite_client): |
Description
Make diagram detect available by file_instance_id.
I have done it similarly to id and external id, but could consider to only make it available with file references, since file references with page ranges is the recommended way to run (at least when documents have variable numbers of pages).
PR in context-api is here
Checklist:
If a new method has been added it should be referenced in cognite.rst in order to generate docs based on its docstring.