<commit_before>import os
import shutil
import tempfile
import time

import mock
import pytest
from airtime_analyzer.filemover_analyzer import FileMoverAnalyzer
from .conftest import AUDIO_FILENAME


def test_dont_use_analyze():
    with pytest.raises(Exception):
        FileMoverAnalyzer.analyze("foo", dict())


@pytest.mark.parametrize(
    "params,exception",
    [
        ((42, "", "", dict()), TypeError),
        (("", 23, "", dict()), TypeError),
        (("", "", 5, dict()), TypeError),
        (("", "", "", 12345), TypeError),
    ],
)
def test_move_wrong_params(params, exception):
    with pytest.raises(exception):
        FileMoverAnalyzer.move(*params)


def test_basic(src_dir, dest_dir):
    FileMoverAnalyzer.move(
        os.path.join(src_dir, AUDIO_FILENAME),
        dest_dir,
        AUDIO_FILENAME,
        dict(),
    )
    assert os.path.exists(os.path.join(dest_dir, AUDIO_FILENAME))


def test_basic_samefile(src_dir):
    FileMoverAnalyzer.move(
        os.path.join(src_dir, AUDIO_FILENAME),
        src_dir,
        AUDIO_FILENAME,
        dict(),
    )
    assert os.path.exists(os.path.join(src_dir, AUDIO_FILENAME))


def import_and_restore(src_dir, dest_dir) -> dict:
    # Import the file
    metadata = FileMoverAnalyzer.move(
        os.path.join(src_dir, AUDIO_FILENAME),
        dest_dir,
        AUDIO_FILENAME,
        dict(),
    )

    # Copy it back to the original location
    shutil.copy(
        os.path.join(dest_dir, AUDIO_FILENAME),
        os.path.join(src_dir, AUDIO_FILENAME),
    )

    return metadata
<commit_msg>Add extra comment on helper function<commit_after>import os
import shutil
import tempfile
import time

import mock
import pytest
from airtime_analyzer.filemover_analyzer import FileMoverAnalyzer
from .conftest import AUDIO_FILENAME


def test_dont_use_analyze():
    with pytest.raises(Exception):
        FileMoverAnalyzer.analyze("foo", dict())


@pytest.mark.parametrize(
    "params,exception",
    [
        ((42, "", "", dict()), TypeError),
        (("", 23, "", dict()), TypeError),
        (("", "", 5, dict()), TypeError),
        (("", "", "", 12345), TypeError),
    ],
)
def test_move_wrong_params(params, exception):
    with pytest.raises(exception):
        FileMoverAnalyzer.move(*params)


def test_basic(src_dir, dest_dir):
    FileMoverAnalyzer.move(
        os.path.join(src_dir, AUDIO_FILENAME),
        dest_dir,
        AUDIO_FILENAME,
        dict(),
    )
    assert os.path.exists(os.path.join(dest_dir, AUDIO_FILENAME))


def test_basic_samefile(src_dir):
    FileMoverAnalyzer.move(
        os.path.join(src_dir, AUDIO_FILENAME),
        src_dir,
        AUDIO_FILENAME,
        dict(),
    )
    assert os.path.exists(os.path.join(src_dir, AUDIO_FILENAME))


def import_and_restore(src_dir, dest_dir) -> dict:
    """
    Small helper to test the FileMoverAnalyzer.move function.
    Move the file and restore it back to it's origine.
    """
    # Import the file
    metadata = FileMoverAnalyzer.move(
        os.path.join(src_dir, AUDIO_FILENAME),
        dest_dir,
        AUDIO_FILENAME,
        dict(),
    )

    # Copy it back to the original location
    shutil.copy(
        os.path.join(dest_dir, AUDIO_FILENAME),
        os.path.join(src_dir, AUDIO_FILENAME),
    )

    return metadata

{'fraction_non_alphanumeric': 0.12113870381586916, 'fraction_numerical': 0.0060569351907934586, 'mean_word_length': 2.989130434782609, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '4331478', 'n_tokens_mistral': 1160, 'n_tokens_neox': 1128, 'n_words': 214}