|
2 | 2 |
|
3 | 3 | import math |
4 | 4 | import random |
5 | | -import time |
6 | 5 | import unittest |
7 | 6 | from collections.abc import Iterator |
8 | 7 | from contextlib import contextmanager |
9 | | -from datetime import datetime |
10 | 8 |
|
11 | 9 | import numpy as np |
12 | 10 | import pandas as pd |
13 | 11 | import pytest |
14 | 12 |
|
15 | 13 | from cognite.client import CogniteClient |
16 | | -from cognite.client.data_classes import TimeSeries, TimeSeriesWrite, filters |
| 14 | +from cognite.client.data_classes import TimeSeriesWrite, filters |
17 | 15 | from cognite.client.data_classes.data_modeling import NodeId, SpaceApply |
18 | 16 | from cognite.client.data_classes.data_modeling.cdm.v1 import CogniteTimeSeriesApply |
19 | 17 | from cognite.client.data_classes.datapoints_subscriptions import ( |
@@ -302,6 +300,7 @@ def test_iterate_data_subscription_changed_time_series( |
302 | 300 | assert {a.external_id for a in batch.subscription_changes.removed} == {first_ts} |
303 | 301 | assert len(batch.updates) == 0 |
304 | 302 |
|
| 303 | + @pytest.mark.allow_no_semaphore("Part of the tests hits DatapointsAPI._insert_datapoints") |
305 | 304 | def test_iterate_data_subscription_datapoints_added( |
306 | 305 | self, cognite_client: CogniteClient, time_series_external_ids: list[str] |
307 | 306 | ) -> None: |
@@ -384,6 +383,7 @@ def test_iterate_data_subscription_start_1m_ago( |
384 | 383 | "you run these tests, please wait 1 minute and try again.", |
385 | 384 | ) |
386 | 385 |
|
| 386 | + @pytest.mark.allow_no_semaphore("Part of the tests hits DatapointsAPI._insert_datapoints") |
387 | 387 | def test_iterate_data__using_status_codes( |
388 | 388 | self, cognite_client: CogniteClient, sub_for_status_codes: DatapointSubscription |
389 | 389 | ) -> None: |
@@ -429,63 +429,3 @@ def test_iterate_data__using_status_codes( |
429 | 429 | assert bad_upsert_value[0] is None |
430 | 430 | assert all(isinstance(v, float) for v in bad_upsert_value[1:]) |
431 | 431 | assert no_bad[0].upserts.status_symbol == ["Uncertain", "Good", "Good", "Good"] |
432 | | - |
433 | | - @pytest.mark.skip(reason="Using a filter (as opposed to specific identifiers) is eventually consistent") |
434 | | - def test_update_filter_subscription_added_times_series( |
435 | | - self, cognite_client: CogniteClient, time_series_external_ids: list[str] |
436 | | - ) -> None: |
437 | | - f = filters |
438 | | - p = DatapointSubscriptionProperty |
439 | | - numerical_timeseries = f.And( |
440 | | - f.Equals(p.is_string, False), f.Prefix(p.external_id, "PYSDK DataPoint Subscription Test") |
441 | | - ) |
442 | | - new_subscription = DataPointSubscriptionWrite( |
443 | | - external_id=f"PYSDKDataPointSubscriptionUpdateFilterTest-{random_string(10)}", |
444 | | - name="PYSDKDataPointSubscriptionUpdateFilterTest", |
445 | | - filter=numerical_timeseries, |
446 | | - partition_count=1, |
447 | | - ) |
448 | | - created_timeseries: TimeSeries | None = None |
449 | | - with create_subscription_with_cleanup(cognite_client, new_subscription) as created: |
450 | | - assert created.created_time |
451 | | - |
452 | | - initial_added_count = 0 |
453 | | - for batch in cognite_client.time_series.subscriptions.iterate_data( |
454 | | - new_subscription.external_id, |
455 | | - poll_timeout=0, |
456 | | - ): |
457 | | - initial_added_count += len(batch.subscription_changes.added) |
458 | | - if not batch.has_next: |
459 | | - break |
460 | | - |
461 | | - assert initial_added_count > 0, "There should be at least one numerical timeseries added" |
462 | | - |
463 | | - new_numerical_timeseries = TimeSeriesWrite( |
464 | | - external_id=f"PYSDK DataPoint Subscription Test 42 ({random_string(10)})", |
465 | | - name="PYSDK DataPoint Subscription Test 42", |
466 | | - is_string=False, |
467 | | - ) |
468 | | - try: |
469 | | - created_timeseries = cognite_client.time_series.create(new_numerical_timeseries) |
470 | | - cognite_client.time_series.data.insert( |
471 | | - [(datetime.now(), 42)], external_id=new_numerical_timeseries.external_id |
472 | | - ) |
473 | | - # Ensure that the subscription has been updated |
474 | | - time.sleep(10) |
475 | | - |
476 | | - updated_added_count = 0 |
477 | | - for batch in cognite_client.time_series.subscriptions.iterate_data( |
478 | | - new_subscription.external_id, |
479 | | - poll_timeout=0, |
480 | | - ): |
481 | | - updated_added_count += len(batch.subscription_changes.added) |
482 | | - if not batch.has_next: |
483 | | - break |
484 | | - |
485 | | - assert initial_added_count + 1 == updated_added_count, ( |
486 | | - "The new timeseries should be added. This is most likely because using a filter with " |
487 | | - "datapoint subscriptions is eventually consistent." |
488 | | - ) |
489 | | - finally: |
490 | | - if created_timeseries: |
491 | | - cognite_client.time_series.delete(created_timeseries.id) |
0 commit comments