1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
|
# 3rd party
import pytest
from coincidence.regressions import AdvancedFileRegressionFixture
from domdf_python_tools.paths import PathPlus
from pyproject_examples.example_configs import COMPLETE_A, COMPLETE_A_WITH_FILES, COMPLETE_B, COMPLETE_PROJECT_A
# this package
from pyproject_parser import PyProject
UNORDERED = """\
[project]
keywords = [ "pep517", "pep621", "build", "sdist", "wheel", "packaging", "distribution",]
version = "2021.0.0"
description = "A simple Python wheel builder for simple projects."
dynamic = [ "classifiers", "requires-python",]
dependencies = [
"httpx",
"gidgethub[httpx]>4.0.0",
"django>2.1; os_name != 'nt'",
"django>2.0; os_name == 'nt'"
]
name = "whey"
[build-system]
requires = [ "whey",]
build-backend = "whey"
[project.urls]
Homepage = "https://whey.readthedocs.io/en/latest"
Documentation = "https://whey.readthedocs.io/en/latest"
"Issue Tracker" = "https://github.com/repo-helper/whey/issues"
"Source Code" = "https://github.com/repo-helper/whey"
[tool.whey]
base-classifiers = [ "Development Status :: 4 - Beta",]
python-versions = [ "3.6", "3.7", "3.8", "3.9", "3.10",]
python-implementations = [ "CPython", "PyPy",]
platforms = [ "Windows", "macOS", "Linux",]
license-key = "MIT"
[[project.authors]]
email = "dominic@davis-foster.co.uk"
name = "Dominic Davis-Foster"
"""
DUMPS_README_TEMPLATE = """\
[build-system]
requires = [ "whey",]
build-backend = "whey"
[project]
name = "Whey"
version = "2021.0.0"
description = "A simple Python wheel builder for simple projects."
keywords = [ "pep517", "pep621", "build", "sdist", "wheel", "packaging", "distribution",]
dynamic = [ "classifiers", "requires-python",]
dependencies = [
"httpx",
"gidgethub[httpx]>4.0.0",
"django>2.1; os_name != 'nt'",
"django>2.0; os_name == 'nt'"
]
{readme_block}
[[project.authors]]
email = "dominic@davis-foster.co.uk"
name = "Dominic Davis-Foster"
[project.urls]
Homepage = "https://whey.readthedocs.io/en/latest"
Documentation = "https://whey.readthedocs.io/en/latest"
"Issue Tracker" = "https://github.com/repo-helper/whey/issues"
"Source Code" = "https://github.com/repo-helper/whey"
"""
COMPLETE_UNDERSCORE_NAME = """\
[build-system]
requires = [ "whey",]
build-backend = "whey"
[project]
name = "toctree_plus"
version = "2021.0.0"
description = "A simple Python wheel builder for simple projects."
keywords = [ "pep517", "pep621", "build", "sdist", "wheel", "packaging", "distribution",]
dynamic = [ "classifiers", "requires-python",]
dependencies = [
"httpx",
"gidgethub[httpx]>4.0.0",
"django>2.1; os_name != 'nt'",
"django>2.0; os_name == 'nt'"
]
[[project.authors]]
email = "dominic@davis-foster.co.uk"
name = "Dominic Davis-Foster"
[project.urls]
Homepage = "https://whey.readthedocs.io/en/latest"
Documentation = "https://whey.readthedocs.io/en/latest"
"Issue Tracker" = "https://github.com/repo-helper/whey/issues"
"Source Code" = "https://github.com/repo-helper/whey"
[tool.whey]
base-classifiers = [ "Development Status :: 4 - Beta",]
python-versions = [ "3.6", "3.7", "3.8", "3.9", "3.10",]
python-implementations = [ "CPython", "PyPy",]
platforms = [ "Windows", "macOS", "Linux",]
license-key = "MIT"
package = "whey"
"""
@pytest.mark.parametrize(
"toml_string",
[
pytest.param(COMPLETE_A, id="COMPLETE_A"),
pytest.param(COMPLETE_B, id="COMPLETE_B"),
pytest.param(COMPLETE_PROJECT_A, id="COMPLETE_PROJECT_A"),
]
)
def test_dumps(
tmp_pathplus: PathPlus,
toml_string: str,
advanced_file_regression: AdvancedFileRegressionFixture,
):
(tmp_pathplus / "pyproject.toml").write_clean(toml_string)
config = PyProject.load(filename=tmp_pathplus / "pyproject.toml")
config.dump(tmp_pathplus / "pyproject.toml")
advanced_file_regression.check_file(tmp_pathplus / "pyproject.toml")
advanced_file_regression.check(config.dumps(), extension=".toml")
def _param(readme_block: str, **kwargs): # noqa: MAN002
return pytest.param(DUMPS_README_TEMPLATE.format(readme_block=readme_block), **kwargs)
@pytest.mark.parametrize(
"toml_string",
[
_param(readme_block="readme = 'README.rst'", id="string"),
_param(
readme_block="[project.readme]\ntext = 'This is the README'\ncontent-type = 'text/x-rst'",
id="dict_text"
),
_param(
readme_block="[project.readme]\nfile = 'README.rst'\ncontent-type = 'text/x-rst'",
id="dict_file"
),
]
)
def test_dumps_readme(
tmp_pathplus: PathPlus,
toml_string: str,
advanced_file_regression: AdvancedFileRegressionFixture,
):
(tmp_pathplus / "pyproject.toml").write_clean(toml_string)
(tmp_pathplus / "README.rst").write_clean("This is the README")
config = PyProject.load(filename=tmp_pathplus / "pyproject.toml")
config.dump(tmp_pathplus / "pyproject.toml")
advanced_file_regression.check_file(tmp_pathplus / "pyproject.toml")
advanced_file_regression.check(config.dumps(), extension=".toml")
@pytest.mark.parametrize(
"toml_string",
[
pytest.param(COMPLETE_A, id="COMPLETE_A"),
pytest.param(COMPLETE_A_WITH_FILES, id="COMPLETE_A_WITH_FILES"),
pytest.param(COMPLETE_B, id="COMPLETE_B"),
pytest.param(COMPLETE_PROJECT_A, id="COMPLETE_PROJECT_A"),
pytest.param(UNORDERED, id="UNORDERED"),
pytest.param(COMPLETE_UNDERSCORE_NAME, id="COMPLETE_UNDERSCORE_NAME"),
]
)
def test_reformat(
tmp_pathplus: PathPlus,
toml_string: str,
advanced_file_regression: AdvancedFileRegressionFixture,
):
(tmp_pathplus / "pyproject.toml").write_clean(toml_string)
(tmp_pathplus / "README.rst").write_clean("This is the README")
(tmp_pathplus / "LICENSE").write_clean("This is the LICENSE")
PyProject.reformat(tmp_pathplus / "pyproject.toml")
advanced_file_regression.check_file(tmp_pathplus / "pyproject.toml")
# Should be no changes
PyProject.reformat(tmp_pathplus / "pyproject.toml")
advanced_file_regression.check_file(tmp_pathplus / "pyproject.toml")
|