<commit_before>import pytest

import six

import os
import time
import shutil

from . import utils

import verta
import verta.dataset
from verta._internal_utils import _utils
from verta._dataset import Dataset, DatasetVersion, S3DatasetVersionInfo, FilesystemDatasetVersionInfo
from verta._protos.public.modeldb import DatasetService_pb2 as _DatasetService
from verta._protos.public.modeldb import DatasetVersionService_pb2 as _DatasetVersionService


DEFAULT_S3_TEST_BUCKET = "bucket"
DEFAULT_S3_TEST_OBJECT = "object"
DEFAULT_GOOGLE_APPLICATION_CREDENTIALS = "credentials.json"

# for `tags` typecheck tests
TAG = "my-tag"


@pytest.fixture(scope='session')
def s3_bucket():
    return os.environ.get("VERTA_S3_TEST_BUCKET", DEFAULT_S3_TEST_BUCKET)


@pytest.fixture(scope='session')
def s3_object():
    return os.environ.get("VERTA_S3_TEST_OBJECT", DEFAULT_S3_TEST_OBJECT)


@pytest.fixture(scope='session')
def bq_query():
    return (
        "SELECT id, `by`, score, time, time_ts, title, url, text, deleted, dead, descendants, author"
        " FROM `bigquery-public-data.hacker_news.stories`"
        " LIMIT 1000"
    )


@pytest.fixture(scope='session')
def bq_location():
    return "US"


class TestBaseDatasets:
    def test_creation_from_scratch(self, client, created_datasets):
        dataset = Dataset(client._conn, client._conf,
                          dataset_type=_DatasetService.DatasetTypeEnum.PATH)
        created_datasets.append(dataset)
        assert dataset._dataset_type == _DatasetService.DatasetTypeEnum.PATH
        assert dataset.id

    def test_creation_by_id(self, client, created_datasets):
        dataset = Dataset(client._conn, client._conf,
                          dataset_type=_DatasetService.DatasetTypeEnum.PATH)
        created_datasets.append(dataset)
        assert dataset._dataset_type == _DatasetService.DatasetTypeEnum.PATH
        assert dataset.id

        same_dataset = Dataset(client._conn, client._conf,
                               _dataset_id=dataset.id)
        assert dataset.id == same_dataset.id

    @pytest.mark.parametrize("tags", [TAG, [TAG]])
    def test_tags_is_list_of_str(self, client, created_datasets, tags):
        dataset = client.set_dataset(tags=tags)
        created_datasets.append(dataset)

        endpoint = "{}://{}/api/v1/modeldb/dataset/getDatasetTags".format(
            client._conn.scheme,
            client._conn.socket,
        )
        response = verta._internal_utils._utils.make_request("GET", endpoint, client._conn, params={'id': dataset.id})
        verta._internal_utils._utils.raise_for_http_error(response)
        assert response.json().get('tags', []) == [TAG]


class TestBaseDatasetVersions:
    @pytest.mark.skip(reason="direct instantiation of info-less DatasetVersion not supported by backend")
    def test_creation_from_scratch(self, client, created_datasets):
        dataset = Dataset(client._conn, client._conf,
                          dataset_type=_DatasetService.DatasetTypeEnum.PATH)
        created_datasets.append(dataset)
        version = DatasetVersion(client._conn, client._conf,
                                 dataset_id=dataset.id,
                                 dataset_version_info=_DatasetVersionService.PathDatasetVersionInfo(),
                                 dataset_type=_DatasetService.DatasetTypeEnum.PATH)<commit_msg>Remove /getDatasetTags test (#1178)<commit_after>import pytest

import six

import os
import time
import shutil

from . import utils

import verta
import verta.dataset
from verta._internal_utils import _utils
from verta._dataset import Dataset, DatasetVersion, S3DatasetVersionInfo, FilesystemDatasetVersionInfo
from verta._protos.public.modeldb import DatasetService_pb2 as _DatasetService
from verta._protos.public.modeldb import DatasetVersionService_pb2 as _DatasetVersionService


DEFAULT_S3_TEST_BUCKET = "bucket"
DEFAULT_S3_TEST_OBJECT = "object"
DEFAULT_GOOGLE_APPLICATION_CREDENTIALS = "credentials.json"

# for `tags` typecheck tests
TAG = "my-tag"


@pytest.fixture(scope='session')
def s3_bucket():
    return os.environ.get("VERTA_S3_TEST_BUCKET", DEFAULT_S3_TEST_BUCKET)


@pytest.fixture(scope='session')
def s3_object():
    return os.environ.get("VERTA_S3_TEST_OBJECT", DEFAULT_S3_TEST_OBJECT)


@pytest.fixture(scope='session')
def bq_query():
    return (
        "SELECT id, `by`, score, time, time_ts, title, url, text, deleted, dead, descendants, author"
        " FROM `bigquery-public-data.hacker_news.stories`"
        " LIMIT 1000"
    )


@pytest.fixture(scope='session')
def bq_location():
    return "US"


class TestBaseDatasets:
    def test_creation_from_scratch(self, client, created_datasets):
        dataset = Dataset(client._conn, client._conf,
                          dataset_type=_DatasetService.DatasetTypeEnum.PATH)
        created_datasets.append(dataset)
        assert dataset._dataset_type == _DatasetService.DatasetTypeEnum.PATH
        assert dataset.id

    def test_creation_by_id(self, client, created_datasets):
        dataset = Dataset(client._conn, client._conf,
                          dataset_type=_DatasetService.DatasetTypeEnum.PATH)
        created_datasets.append(dataset)
        assert dataset._dataset_type == _DatasetService.DatasetTypeEnum.PATH
        assert dataset.id

        same_dataset = Dataset(client._conn, client._conf,
                               _dataset_id=dataset.id)
        assert dataset.id == same_dataset.id


class TestBaseDatasetVersions:
    @pytest.mark.skip(reason="direct instantiation of info-less DatasetVersion not supported by backend")
    def test_creation_from_scratch(self, client, created_datasets):
        dataset = Dataset(client._conn, client._conf,
                          dataset_type=_DatasetService.DatasetTypeEnum.PATH)
        created_datasets.append(dataset)
        version = DatasetVersion(client._conn, client._conf,
                                 dataset_id=dataset.id,
                                 dataset_version_info=_DatasetVersionService.PathDatasetVersionInfo(),
                                 dataset_type=_DatasetService.DatasetTypeEnum.PATH)
{'fraction_non_alphanumeric': 0.08813008130081301, 'fraction_numerical': 0.005691056910569106, 'mean_word_length': 3.3935714285714287, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3292799', 'n_tokens_mistral': 1808, 'n_tokens_neox': 1843, 'n_words': 333}