<commit_before># -*- coding: utf-8 -*-

from unittest import mock

from nikola.plugins.command.init import (
    SAMPLE_CONF, CommandInit, format_default_translations_config)

import pytest
from .base import cd


def test_command_init_with_defaults(init_command, ask_questions, copy_sample_site, create_configuration, create_empty_site):
    init_command.execute()

    assert ask_questions.called
    assert create_configuration.called
    assert not copy_sample_site.called
    assert create_empty_site.called


def test_command_init_with_arguments(init_command, ask_questions, copy_sample_site, create_configuration, create_empty_site):
    arguments = dict(
        options={'demo': True, 'quiet': True},
        args=['destination'])
    init_command.execute(**arguments)

    assert not ask_questions.called
    assert create_configuration.called
    assert copy_sample_site.called
    assert not create_empty_site.called


def test_init_called_without_target_quiet(init_command, ask_questions, copy_sample_site, create_configuration, create_empty_site):
    init_command.execute(**{"options": {'quiet': True}})

    assert not ask_questions.called
    assert not create_configuration.called
    assert not copy_sample_site.called
    assert not create_empty_site.called


def test_command_init_with_empty_dir(init_command, ask_questions, copy_sample_site, create_configuration, create_empty_site):
    init_command.execute(args=['destination'])

    assert ask_questions.called
    assert create_configuration.called
    assert not copy_sample_site.called
    assert create_empty_site.called


def test_configure_translations_without_additional_languages():
    """
    Testing the configuration of the translation when no additional language has been found.
    """
    translations_cfg = format_default_translations_config(set())
    assert SAMPLE_CONF["TRANSLATIONS"] == translations_cfg


def test_configure_translations_with_2_additional_languages():
    """
    Testing the configuration of the translation when two additional languages are given.
    """
    translations_cfg = format_default_translations_config(set(["es", "en"]))
    assert translations_cfg == """{
    DEFAULT_LANG: "",
    "en": "./en",
    "es": "./es",
}"""


@pytest.fixture
def init_command(tmpdir, ask_questions, copy_sample_site, create_configuration, create_empty_site):
    with mock.patch('nikola.plugins.command.init.CommandInit.ask_questions', ask_questions):
        with mock.patch('nikola.plugins.command.init.CommandInit.copy_sample_site', copy_sample_site):
            with mock.patch('nikola.plugins.command.init.CommandInit.create_configuration', create_configuration):
                with mock.patch('nikola.plugins.command.init.CommandInit.create_empty_site', create_empty_site):
                    with cd(tmpdir):
                        yield CommandInit()


@pytest.fixture
def ask_questions():
    return mock.MagicMock()


@pytest.fixture
def copy_sample_site():
    return mock.MagicMock()

<commit_msg>Older Python versions can only handle strings.<commit_after># -*- coding: utf-8 -*-

from unittest import mock

from nikola.plugins.command.init import (
    SAMPLE_CONF, CommandInit, format_default_translations_config)

import pytest
from .base import cd


def test_command_init_with_defaults(init_command, ask_questions, copy_sample_site, create_configuration, create_empty_site):
    init_command.execute()

    assert ask_questions.called
    assert create_configuration.called
    assert not copy_sample_site.called
    assert create_empty_site.called


def test_command_init_with_arguments(init_command, ask_questions, copy_sample_site, create_configuration, create_empty_site):
    arguments = dict(
        options={'demo': True, 'quiet': True},
        args=['destination'])
    init_command.execute(**arguments)

    assert not ask_questions.called
    assert create_configuration.called
    assert copy_sample_site.called
    assert not create_empty_site.called


def test_init_called_without_target_quiet(init_command, ask_questions, copy_sample_site, create_configuration, create_empty_site):
    init_command.execute(**{"options": {'quiet': True}})

    assert not ask_questions.called
    assert not create_configuration.called
    assert not copy_sample_site.called
    assert not create_empty_site.called


def test_command_init_with_empty_dir(init_command, ask_questions, copy_sample_site, create_configuration, create_empty_site):
    init_command.execute(args=['destination'])

    assert ask_questions.called
    assert create_configuration.called
    assert not copy_sample_site.called
    assert create_empty_site.called


def test_configure_translations_without_additional_languages():
    """
    Testing the configuration of the translation when no additional language has been found.
    """
    translations_cfg = format_default_translations_config(set())
    assert SAMPLE_CONF["TRANSLATIONS"] == translations_cfg


def test_configure_translations_with_2_additional_languages():
    """
    Testing the configuration of the translation when two additional languages are given.
    """
    translations_cfg = format_default_translations_config(set(["es", "en"]))
    assert translations_cfg == """{
    DEFAULT_LANG: "",
    "en": "./en",
    "es": "./es",
}"""


@pytest.fixture
def init_command(tmpdir, ask_questions, copy_sample_site, create_configuration, create_empty_site):
    with mock.patch('nikola.plugins.command.init.CommandInit.ask_questions', ask_questions):
        with mock.patch('nikola.plugins.command.init.CommandInit.copy_sample_site', copy_sample_site):
            with mock.patch('nikola.plugins.command.init.CommandInit.create_configuration', create_configuration):
                with mock.patch('nikola.plugins.command.init.CommandInit.create_empty_site', create_empty_site):
                    with cd(str(tmpdir)):
                        yield CommandInit()


@pytest.fixture
def ask_questions():
    return mock.MagicMock()


@pytest.fixture
def copy_sample_site():
    return mock.MagicMock()


{'fraction_non_alphanumeric': 0.08775107013500165, 'fraction_numerical': 0.0006585446163977609, 'mean_word_length': 4.731132075471698, 'pattern_counts': {'":': 6, '<': 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': '2237199', 'n_tokens_mistral': 1762, 'n_tokens_neox': 1682, 'n_words': 352}