def test_new_theme_name_only(project_cli_runner):
    result = project_cli_runner.invoke(
        cli,
        ["dev", "new-theme"],
        input='Lektor Name Theme\n'
        '\n'
        '\n'
        '\n'
        'y\n',
    )
    assert "Create Theme?" in result.output
    assert result.exit_code == 0
    path = os.path.join('themes', 'lektor-theme-name')
    assert set(os.listdir(path)) == set(
        ['example-site', 'images', 'README.md', 'theme.ini'])
    assert set(os.listdir(os.path.join(path,
                                       'images'))) == set(['homepage.png'])
    assert set(os.listdir(os.path.join(path, 'example-site'))) == set(
        ['lektor-theme-name.lektorproject', 'README.md', 'themes'])
    try:
        assert os.readlink(os.path.join(
            path, 'example-site/themes/lektor-theme-name')) == \
            '../../../lektor-theme-name'
    except AttributeError:
        pass

    theme_inifile = IniFile(os.path.join(path, 'theme.ini'))
    assert theme_inifile['theme.name'] == 'Lektor Name Theme'
    assert theme_inifile['author.email'] == get_default_author_email()
    assert theme_inifile['author.name'] == get_default_author()

    with open(os.path.join(path, 'README.md')) as f:
        readme_contents = f.read().strip()
    assert "Lektor Name Theme" in readme_contents
Exemplo n.º 2
0
def test_new_theme_name_only(project_cli_runner):
    result = project_cli_runner.invoke(
        cli,
        ["dev", "new-theme"],
        input="Lektor Name Theme\n" "\n" "\n" "\n" "y\n",
    )
    assert "Create Theme?" in result.output
    assert result.exit_code == 0
    path = os.path.join("themes", "lektor-theme-name")
    assert set(os.listdir(path)) == set(
        ["example-site", "images", "README.md", "theme.ini"]
    )
    assert set(os.listdir(os.path.join(path, "images"))) == set(["homepage.png"])
    assert set(os.listdir(os.path.join(path, "example-site"))) == set(
        ["lektor-theme-name.lektorproject", "README.md", "themes"]
    )
    try:
        assert (
            os.readlink(os.path.join(path, "example-site/themes/lektor-theme-name"))
            == "../../../lektor-theme-name"
        )
    except AttributeError:
        pass

    theme_inifile = IniFile(os.path.join(path, "theme.ini"))
    assert theme_inifile["theme.name"] == "Lektor Name Theme"
    assert theme_inifile["author.email"] == get_default_author_email()
    assert theme_inifile["author.name"] == get_default_author()

    with open(os.path.join(path, "README.md")) as f:
        readme_contents = f.read().strip()
    assert "Lektor Name Theme" in readme_contents
def test_new_plugin_name_only(project_cli_runner):
    result = project_cli_runner.invoke(
        cli,
        ["dev", "new-plugin"],
        input='Plugin Name\n'
        '\n'
        '\n'
        '\n'
        'y\n',
    )
    assert "Create Plugin?" in result.output
    assert result.exit_code == 0
    path = 'packages'
    assert os.listdir(path) == ['plugin-name']

    # setup.py
    author = get_default_author()
    author_email = get_default_author_email()
    setup_expected = textwrap.dedent("""
        import ast
        import io
        import re

        from setuptools import setup, find_packages

        with io.open('README.md', 'rt', encoding="utf8") as f:
            readme = f.read()

        _description_re = re.compile(r'description\\s+=\\s+(?P<description>.*)')

        with open('lektor_plugin_name.py', 'rb') as f:
            description = str(ast.literal_eval(_description_re.search(
                f.read().decode('utf-8')).group(1)))

        setup(
            author={}'{}',
            author_email='{}',
            description=description,
            keywords='Lektor plugin',
            license='MIT',
            long_description=readme,
            long_description_content_type='text/markdown',
            name='lektor-plugin-name',
            packages=find_packages(),
            py_modules=['lektor_plugin_name'],
            # url='[link to your repository]',
            version='0.1',
            classifiers=[
                'Framework :: Lektor',
                'Environment :: Plugins',
            ],
            entry_points={{
                'lektor.plugins': [
                    'plugin-name = lektor_plugin_name:PluginNamePlugin',
                ]
            }}
        )
    """).strip()
    if PY2:
        setup_expected = setup_expected.format("u", author, author_email)
    else:
        setup_expected = setup_expected.format("", author, author_email)
    with open(os.path.join(path, 'plugin-name', 'setup.py')) as f:
        setup_contents = f.read().strip()
    assert setup_contents == setup_expected
Exemplo n.º 4
0
def test_default_author_email(git_user_email):
    from lektor.quickstart import get_default_author_email
    assert get_default_author_email() == "*****@*****.**"
def test_default_author_email():
    assert isinstance(get_default_author_email(), text_type)
Exemplo n.º 6
0
def test_default_author_email_no_default(monkeypatch):
    monkeypatch.delitem(os.environ, "EMAIL", raising=False)
    assert get_default_author_email() is None
Exemplo n.º 7
0
def test_default_author_email_from_EMAIL(monkeypatch):
    email = "*****@*****.**"
    monkeypatch.setitem(os.environ, "EMAIL", email)
    assert get_default_author_email() == email
Exemplo n.º 8
0
def test_default_author_email(git_config_file):
    git_config_file.write_text("[user]\n\temail = [email protected]\n")
    assert get_default_author_email() == "*****@*****.**"