<commit_before>"""Test the ``dtool dataset create`` command."""

import os
import shutil

from click.testing import CliRunner

from dtoolcore import DataSet

from . import chdir_fixture, tmp_dir_fixture  # NOQA
from . import SAMPLE_FILES_DIR


def test_dataset_freeze_functional(chdir_fixture):  # NOQA
    from dtool_create.dataset import freeze
    runner = CliRunner()

    # Create an empty dataset
    dataset_name = "my_dataset"
    dataset = DataSet(dataset_name, data_directory="data")
    dataset.persist_to_path(".")

    # Add some files to it.
    dest_dir = os.path.join(".", dataset.data_directory, "sample_files")
    shutil.copytree(SAMPLE_FILES_DIR, dest_dir)

    # At this point the manifest has not been updated.
    assert len(dataset.identifiers) == 0

    result = runner.invoke(freeze, ["."])
    assert result.exit_code == 0

    # Manifest has been updated.
    assert len(dataset.identifiers) == 2<commit_msg>Fix the freeze functional test<commit_after>"""Test the ``dtool dataset create`` command."""

import os
import shutil

from click.testing import CliRunner

from dtoolcore import DataSet, ProtoDataSet

from . import chdir_fixture, tmp_dir_fixture  # NOQA
from . import SAMPLE_FILES_DIR


def test_dataset_freeze_functional(chdir_fixture):  # NOQA
    from dtool_create.dataset import create, freeze
    runner = CliRunner()

    dataset_name = "my_dataset"
    result = runner.invoke(create, [dataset_name])
    assert result.exit_code == 0

    # At this point we have a proto dataset
    dataset_abspath = os.path.abspath(dataset_name)
    dataset_uri = "disk:{}".format(dataset_abspath)
    dataset = ProtoDataSet.from_uri(dataset_uri)

    # Add a file to the proto dataset.
    sample_file_abspath = os.path.join(dataset_abspath, "data", "hello.txt")
    with open(sample_file_abspath, "w") as fh:
        fh.write("hello world")

    result = runner.invoke(freeze, [dataset_uri])
    assert result.exit_code == 0


    # Now we have a dataset.
    dataset = DataSet.from_uri(dataset_uri)

    # Manifest has been updated.
    assert len(dataset.identifiers) == 1
{'fraction_non_alphanumeric': 0.09462672372800761, 'fraction_numerical': 0.0028530670470756064, 'mean_word_length': 3.927400468384075, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6419714', 'n_tokens_mistral': 691, 'n_tokens_neox': 657, 'n_words': 180}