-
-
Notifications
You must be signed in to change notification settings - Fork 202
Expand file tree
/
Copy pathtest_pyproject_toml.py
More file actions
99 lines (84 loc) · 3.35 KB
/
test_pyproject_toml.py
File metadata and controls
99 lines (84 loc) · 3.35 KB
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
import pathlib
import tempfile
import unittest
from pyperformance import _pyproject_toml
class TestPyProjectToml(unittest.TestCase):
def test_parse_project_with_readme_string(self):
with tempfile.TemporaryDirectory() as tmpdir:
tmp_path = pathlib.Path(tmpdir)
toml_content = """
[project]
name = "my-test-bench"
version = "1.0"
readme = "README.md"
"""
(tmp_path / "README.md").touch()
data = _pyproject_toml.parse_pyproject_toml(
toml_content, rootdir=str(tmp_path), requirefiles=True
)
self.assertEqual(data["project"]["readme"]["file"], "README.md")
def test_parse_full_valid_project_section(self):
with tempfile.TemporaryDirectory() as tmpdir:
toml_content = """
[project]
name = "my-full-bench"
version = "2.1.3"
dependencies = [
"pyperf",
"six",
]
requires-python = ">=3.12"
"""
data = _pyproject_toml.parse_pyproject_toml(
toml_content, rootdir=str(tmpdir)
)
project = data["project"]
self.assertEqual(project["name"], "my-full-bench")
self.assertEqual(project["version"], "2.1.3")
self.assertEqual(project["dependencies"], ["pyperf", "six"])
self.assertEqual(project["requires-python"], ">=3.12")
def test_parse_fails_on_missing_name(self):
with tempfile.TemporaryDirectory() as tmpdir:
toml_content = """
[project]
version = "1.0"
"""
with self.assertRaisesRegex(ValueError, r'missing required "name" field'):
_pyproject_toml.parse_pyproject_toml(toml_content, rootdir=str(tmpdir))
def test_parse_fails_on_unsupported_section(self):
with tempfile.TemporaryDirectory() as tmpdir:
toml_content = """
[project]
name = "my-test-bench"
version = "1.0"
[foobar]
key = "value"
"""
with self.assertRaisesRegex(ValueError, "unsupported sections"):
_pyproject_toml.parse_pyproject_toml(toml_content, rootdir=str(tmpdir))
def test_parse_readme_file_missing_with_requirefiles_true(self):
with tempfile.TemporaryDirectory() as tmpdir:
toml_content = """
[project]
name = "my-test-bench"
version = "1.0"
readme = "MISSING_README.md"
"""
with self.assertRaisesRegex(ValueError, "does not exist"):
_pyproject_toml.parse_pyproject_toml(
toml_content, rootdir=str(tmpdir), requirefiles=True
)
def test_parse_readme_file_missing_with_requirefiles_false(self):
with tempfile.TemporaryDirectory() as tmpdir:
toml_content = """
[project]
name = "my-test-bench"
version = "1.0"
readme = "MISSING_README.md"
"""
data = _pyproject_toml.parse_pyproject_toml(
toml_content, rootdir=str(tmpdir), requirefiles=False
)
self.assertEqual(data["project"]["readme"]["file"], "MISSING_README.md")
if __name__ == "__main__":
unittest.main()