def connect(): return CogniteClient( project="powerdummy", api_key=os.environ["POWERDUMMY_API_KEY"], base_url="https://greenfield.cognitedata.com", client_name="powerdummy-populator", )
import re import pytest from cognite.client.data_classes import DataSet, DataSetList, DataSetUpdate, TimestampRange from cognite.client.experimental import CogniteClient from tests.utils import jsgz_load # from unittest import mock COGNITE_CLIENT = CogniteClient() DS_API = COGNITE_CLIENT.data_sets @pytest.fixture def dataset_update(): yield DataSetUpdate(id=1).description.set("_") @pytest.fixture def mock_ds_response(rsps): response_body = { "items": [ { "id": 0, "externalId": "string", "name": "string", "description": "string", "metadata": {"metadata-key": "metadata-value"}, "writeProtected": False,
from unittest import mock from unittest.mock import call import pytest from cognite.client.data_classes import Asset, AssetList, Event, EventList, FileMetadata, FileMetadataList from cognite.client.experimental import CogniteClient c = CogniteClient() class TestAsset: def test_get_events(self): c.events.list = mock.MagicMock() a = Asset(id=1, cognite_client=c) a.events() assert c.events.list.call_args == call(asset_ids=[1]) assert c.events.list.call_count == 1 def test_get_time_series(self): c.time_series.list = mock.MagicMock() a = Asset(id=1, cognite_client=c) a.time_series() assert c.time_series.list.call_args == call(asset_ids=[1]) assert c.time_series.list.call_count == 1 def test_get_sequences(self): c.sequences.list = mock.MagicMock() a = Asset(id=1, cognite_client=c) a.sequences() assert c.sequences.list.call_args == call(asset_ids=[1])
from cognite.client._api_client import APIClient from cognite.client.experimental import CogniteClient def collect_apis(obj, done): if done.get(obj.__class__): return [] done[obj.__class__] = True apis = inspect.getmembers( obj, lambda m: isinstance(m, APIClient) and not done.get(m.__class__)) sub = [(n + "." + sn, sa) for n, c in apis for sn, sa in collect_apis(c, done)] return apis + sub client = CogniteClient(project="_", api_key="_", client_name="_") parser = DocTestParser() apis = collect_apis(client, {}) snippets = { "language": "Python", "label": "Python SDK", "operations": defaultdict(str) } filter_out = [ "from cognite.client import CogniteClient", "c = CogniteClient()", "" ] duplicate_operations = { "listAssets": "getAssets",
import pytest from cognite.client._api.model_hosting.models import EmptyArtifactsDirectory, PredictionError from cognite.client.data_classes.model_hosting.models import ( Model, ModelArtifact, ModelArtifactList, ModelList, ModelVersion, ModelVersionList, ModelVersionLog, ) from cognite.client.experimental import CogniteClient from tests.utils import jsgz_load MODELS_API = CogniteClient().model_hosting.models class TestModels: @pytest.fixture def created_model(self): model_name = "test-model-{}".format(randint(0, 1e5)) model = MODELS_API.create_model(name=model_name, webhook_url="https://bla.bla") yield model MODELS_API.delete_model(model.id) @pytest.fixture def mock_online_predict_ok(self, rsps): rsps.add( rsps.PUT, MODELS_API._get_base_url_with_base_path() + "/analytics/models/1/predict",
from unittest import mock import pytest from cognite.client.data_classes.model_hosting.schedules import Schedule, ScheduleList, ScheduleLog from cognite.client.experimental import CogniteClient from tests.utils import jsgz_load SCHEDULES_API = CogniteClient().model_hosting.schedules class TestSchedules: schedule_response = { "data": { "items": [{ "isDeprecated": False, "name": "test-schedule", "dataSpec": { "spec": "spec" }, "modelId": 123, "createdTime": 0, "metadata": { "k": "v" }, "id": 123, "args": { "k": "v" }, "description": "string", }]
import os import time from random import randint from tempfile import TemporaryDirectory import pytest from cognite.client.data_classes.model_hosting.source_packages import SourcePackage, SourcePackageList from cognite.client.exceptions import CogniteAPIError from cognite.client.experimental import CogniteClient SOURCE_PACKAGES_API = CogniteClient().model_hosting.source_packages class TestSourcePackages: @pytest.fixture(scope="class") def source_package_file_path(self): with TemporaryDirectory() as tmp_dir: file_path = os.path.join(tmp_dir, "sp.tar.gz") with open(file_path, "w") as f: f.write("content") yield file_path @pytest.fixture(scope="class") def created_source_package(self, source_package_file_path): sp_name = "test-sp-{}".format(randint(0, 1e5)) sp = SOURCE_PACKAGES_API.upload_source_package( name=sp_name, package_name="whatever", available_operations=["TRAIN", "PREDICT"], runtime_version="0.1",
import pytest from cognite.client._api.model_hosting.models import PredictionError from cognite.client._api.model_hosting.versions import EmptyArtifactsDirectory from cognite.client.data_classes.model_hosting.versions import ( ModelArtifact, ModelArtifactList, ModelVersion, ModelVersionList, ModelVersionLog, ) from cognite.client.experimental import CogniteClient from tests.utils import jsgz_load MODELS_API = CogniteClient().model_hosting.models VERSIONS_API = CogniteClient().model_hosting.versions class TestVersions: model_version_response = { "isDeprecated": True, "trainingDetails": { "machineType": "string", "scaleTier": "string", "completedTime": 0, "sourcePackageId": "string", "args": "string", }, "name": "version1", "errorMsg": "string",