<commit_before>#!/usr/bin/env python

# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import uuid

import pytest

import automl_translation_dataset

project_id = os.environ["GOOGLE_CLOUD_PROJECT"]
compute_region = "us-central1"


@pytest.mark.slow
def test_dataset_create_import_delete(capsys):
    # create dataset
    dataset_name = f"test_{uuid.uuid4().hex[:27]}"
    automl_translation_dataset.create_dataset(
        project_id, compute_region, dataset_name, "en", "ja"
    )
    out, _ = capsys.readouterr()
    create_dataset_output = out.splitlines()
    assert "Dataset id: " in create_dataset_output[1]

    # import data
    dataset_id = create_dataset_output[1].split()[2]
    data = "gs://{}-vcm/en-ja.csv".format(project_id)
    automl_translation_dataset.import_data(
        project_id, compute_region, dataset_id, data
    )
    out, _ = capsys.readouterr()
    assert "Data imported." in out

    # delete dataset
    automl_translation_dataset.delete_dataset(
        project_id, compute_region, dataset_id
    )
    out, _ = capsys.readouterr()
    assert "Dataset deleted." in out


def test_dataset_list_get(capsys):
    # list datasets
    automl_translation_dataset.list_datasets(project_id, compute_region, "")
    out, _ = capsys.readouterr()
    list_dataset_output = out.splitlines()
    assert "Dataset id: " in list_dataset_output[2]

    # get dataset
    dataset_id = list_dataset_output[2].split()[2]
    automl_translation_dataset.get_dataset(
        project_id, compute_region, dataset_id
    )
    out, _ = capsys.readouterr()
    assert "Dataset name: " in out<commit_msg>chore: refactor translation automl test (#113)<commit_after>#!/usr/bin/env python

# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import uuid

import pytest

import automl_translation_dataset

project_id = os.environ["GOOGLE_CLOUD_PROJECT"]
compute_region = "us-central1"
dataset_id = "TRL3876092572857648864"


@pytest.mark.slow
def test_dataset_create_import_delete(capsys):
    # create dataset
    dataset_name = f"test_{uuid.uuid4().hex[:27]}"
    automl_translation_dataset.create_dataset(
        project_id, compute_region, dataset_name, "en", "ja"
    )
    out, _ = capsys.readouterr()
    create_dataset_output = out.splitlines()
    assert "Dataset id: " in create_dataset_output[1]

    # import data
    dataset_id = create_dataset_output[1].split()[2]
    data = "gs://{}-vcm/en-ja.csv".format(project_id)
    automl_translation_dataset.import_data(
        project_id, compute_region, dataset_id, data
    )
    out, _ = capsys.readouterr()
    assert "Data imported." in out

    # delete dataset
    automl_translation_dataset.delete_dataset(
        project_id, compute_region, dataset_id
    )
    out, _ = capsys.readouterr()
    assert "Dataset deleted." in out


def test_dataset_list_get(capsys):
    # list datasets
    automl_translation_dataset.list_datasets(project_id, compute_region, "")
    out, _ = capsys.readouterr()
    list_dataset_output = out.splitlines()
    assert "Dataset id: " in list_dataset_output[2]

    # get dataset
    automl_translation_dataset.get_dataset(
        project_id, compute_region, dataset_id
    )
    out, _ = capsys.readouterr()
    assert "Dataset name: " in out
{'fraction_non_alphanumeric': 0.09156235512285582, 'fraction_numerical': 0.012980992118683357, 'mean_word_length': 3.965477560414269, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7637670', 'n_tokens_mistral': 1353, 'n_tokens_neox': 1325, 'n_words': 362}