pypa-hatch/tests/files/readme/test_markdown.py

255 lines
7.8 KiB
Python

import os
from parse import parse
from hatch.create import create_package
from hatch.settings import copy_default_settings
from hatch.utils import temp_chdir
from hatch.files.readme.markdown import TEMPLATE
from ...utils import read_file
def test_format():
with temp_chdir() as d:
settings = copy_default_settings()
settings['readme']['format'] = 'md'
create_package(d, 'ok', settings)
assert os.path.exists(os.path.join(d, 'README.md'))
def test_title():
with temp_chdir() as d:
settings = copy_default_settings()
settings['readme']['format'] = 'md'
create_package(d, 'ok', settings)
contents = read_file(os.path.join(d, 'README.md'))
parsed = parse(TEMPLATE, contents)
assert parsed['title'] == 'ok'
def test_package_name():
with temp_chdir() as d:
settings = copy_default_settings()
settings['readme']['format'] = 'md'
create_package(d, 'ok', settings)
contents = read_file(os.path.join(d, 'README.md'))
parsed = parse(TEMPLATE, contents)
assert parsed['package_name'] == 'ok'
def test_supported_versions_none():
with temp_chdir() as d:
settings = copy_default_settings()
settings['readme']['format'] = 'md'
settings['pyversions'] = []
create_package(d, 'ok', settings)
contents = read_file(os.path.join(d, 'README.md'))
parsed = parse(TEMPLATE, contents)
assert parsed['supported_versions'] == '2.7/3.5+ and PyPy'
def test_supported_versions_py2_single():
with temp_chdir() as d:
settings = copy_default_settings()
settings['readme']['format'] = 'md'
settings['pyversions'] = ['2.7']
create_package(d, 'ok', settings)
contents = read_file(os.path.join(d, 'README.md'))
parsed = parse(TEMPLATE, contents)
assert parsed['supported_versions'] == '2.7'
def test_supported_versions_py2():
with temp_chdir() as d:
settings = copy_default_settings()
settings['readme']['format'] = 'md'
settings['pyversions'] = ['2.7', '2.6']
create_package(d, 'ok', settings)
contents = read_file(os.path.join(d, 'README.md'))
parsed = parse(TEMPLATE, contents)
assert parsed['supported_versions'] == '2.6-2.7'
def test_supported_versions_py3():
with temp_chdir() as d:
settings = copy_default_settings()
settings['readme']['format'] = 'md'
settings['pyversions'] = ['3.5', '3.6', '3.3', '3.4']
create_package(d, 'ok', settings)
contents = read_file(os.path.join(d, 'README.md'))
parsed = parse(TEMPLATE, contents)
assert parsed['supported_versions'] == '3.3+'
def test_supported_versions_all():
with temp_chdir() as d:
settings = copy_default_settings()
settings['readme']['format'] = 'md'
settings['pyversions'] = ['pypy3', 'pypy', '3.4', '3.3', '3.6', '3.5', '2.7']
create_package(d, 'ok', settings)
contents = read_file(os.path.join(d, 'README.md'))
parsed = parse(TEMPLATE, contents)
assert parsed['supported_versions'] == '2.7/3.3+ and PyPy'
def test_licenses_single():
with temp_chdir() as d:
settings = copy_default_settings()
settings['readme']['format'] = 'md'
settings['licenses'] = ['mit']
create_package(d, 'ok', settings)
contents = read_file(os.path.join(d, 'README.md'))
parsed = parse(TEMPLATE, contents)
assert parsed['license_info'] == (
'the\n[MIT License](https://choosealicense.com/licenses/mit)'
)
def test_licenses_multiple():
with temp_chdir() as d:
settings = copy_default_settings()
settings['readme']['format'] = 'md'
settings['licenses'] = ['mit', 'apache2']
create_package(d, 'ok', settings)
contents = read_file(os.path.join(d, 'README.md'))
parsed = parse(TEMPLATE, contents)
assert parsed['license_info'] == (
'both\n\n'
'- [MIT License](https://choosealicense.com/licenses/mit)\n'
'- [Apache License, Version 2.0](https://choosealicense.com/licenses/apache-2.0)'
'\n\nat your option'
)
def test_badges_none():
with temp_chdir() as d:
settings = copy_default_settings()
settings['basic'] = False
settings['readme']['format'] = 'md'
settings['readme']['badges'] = []
create_package(d, 'ok', settings)
contents = read_file(os.path.join(d, 'README.md'))
parsed = parse(TEMPLATE, contents)
assert parsed['badges'] == '\n'
def test_badges_basic():
with temp_chdir() as d:
settings = copy_default_settings()
settings['readme']['format'] = 'md'
create_package(d, 'ok', settings)
contents = read_file(os.path.join(d, 'README.md'))
parsed = parse(TEMPLATE, contents)
assert parsed['badges'] == '\n'
def test_badges_single():
with temp_chdir() as d:
settings = copy_default_settings()
settings['basic'] = False
settings['readme']['format'] = 'md'
settings['readme']['badges'] = [
{
'image': 'https://img.shields.io/pypi/v/ok.svg',
'target': 'https://pypi.org/project/ok',
'alt': 'Latest PyPI version'
}
]
create_package(d, 'ok', settings)
contents = read_file(os.path.join(d, 'README.md'))
parsed = parse(TEMPLATE, contents)
assert parsed['badges'] == (
'\n'
'[![Latest PyPI version](https://img.shields.io/pypi/v/ok.svg)](https://pypi.org/project/ok)\n'
'\n'
)
def test_badges_multiple():
with temp_chdir() as d:
settings = copy_default_settings()
settings['basic'] = False
settings['readme']['format'] = 'md'
settings['readme']['badges'] = [
{
'image': 'https://img.shields.io/pypi/v/ok.svg',
'target': 'https://pypi.org/project/ok',
'alt': 'Latest PyPI version'
},
{
'image': 'https://img.shields.io/pypi/l/ok.svg',
'target': 'https://choosealicense.com/licenses',
'alt': 'License'
}
]
create_package(d, 'ok', settings)
contents = read_file(os.path.join(d, 'README.md'))
parsed = parse(TEMPLATE, contents)
assert parsed['badges'] == (
'\n'
'[![Latest PyPI version](https://img.shields.io/pypi/v/ok.svg)](https://pypi.org/project/ok)\n'
'[![License](https://img.shields.io/pypi/l/ok.svg)](https://choosealicense.com/licenses)\n'
'\n'
)
def test_badges_params():
with temp_chdir() as d:
settings = copy_default_settings()
settings['basic'] = False
settings['readme']['format'] = 'md'
settings['readme']['badges'] = [
{
'image': 'https://img.shields.io/pypi/v/ok.svg',
'target': 'https://pypi.org/project/ok',
'alt': 'Latest PyPI version',
'style': 'flat-square'
},
{
'image': 'https://img.shields.io/pypi/l/ok.svg',
'target': 'https://choosealicense.com/licenses',
'alt': 'License',
'style': 'flat-square'
}
]
create_package(d, 'ok', settings)
contents = read_file(os.path.join(d, 'README.md'))
parsed = parse(TEMPLATE, contents)
assert parsed['badges'] == (
'\n'
'[![Latest PyPI version](https://img.shields.io/pypi/v/ok.svg?style=flat-square)]'
'(https://pypi.org/project/ok)\n'
'[![License](https://img.shields.io/pypi/l/ok.svg?style=flat-square)]'
'(https://choosealicense.com/licenses)\n'
'\n'
)