From bb91f9862294c119d5b1d74c3e36b48283c6bbce Mon Sep 17 00:00:00 2001 From: maurycy <5383+maurycy@users.noreply.github.com> Date: Sat, 13 Sep 2025 23:54:27 +0200 Subject: [PATCH 1/5] ups? --- pyperformance/_pyproject_toml.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyperformance/_pyproject_toml.py b/pyperformance/_pyproject_toml.py index 0d0f11ca..e97576af 100644 --- a/pyperformance/_pyproject_toml.py +++ b/pyperformance/_pyproject_toml.py @@ -167,7 +167,7 @@ def _normalize_project(data, rootdir, name, requirefiles, **_ignored): key = 'readme' if key in data: readme = data[key] - if isinstance(readme, 'str'): + if isinstance(readme, str): readme = data[key] = {'file': readme} # XXX Check the suffix. # XXX Handle 'content-type'. From bd5e2d208a7a2590a9bca0dec23c3c372561be13 Mon Sep 17 00:00:00 2001 From: maurycy <5383+maurycy@users.noreply.github.com> Date: Sat, 20 Sep 2025 05:02:55 +0200 Subject: [PATCH 2/5] test pyproject --- pyperformance/tests/test_pyproject_toml.py | 98 ++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 pyperformance/tests/test_pyproject_toml.py diff --git a/pyperformance/tests/test_pyproject_toml.py b/pyperformance/tests/test_pyproject_toml.py new file mode 100644 index 00000000..83e27dea --- /dev/null +++ b/pyperformance/tests/test_pyproject_toml.py @@ -0,0 +1,98 @@ +import unittest +import tempfile +import pathlib +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() From 4e4b2d811711ff8caf0b51f694bb3b44a813bd8a Mon Sep 17 00:00:00 2001 From: maurycy <5383+maurycy@users.noreply.github.com> Date: Mon, 22 Sep 2025 19:44:39 +0200 Subject: [PATCH 3/5] uvx ruff format pyperformance/tests/test_pyproject_toml.py --- pyperformance/tests/test_pyproject_toml.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/pyperformance/tests/test_pyproject_toml.py b/pyperformance/tests/test_pyproject_toml.py index 83e27dea..904424d9 100644 --- a/pyperformance/tests/test_pyproject_toml.py +++ b/pyperformance/tests/test_pyproject_toml.py @@ -1,6 +1,7 @@ -import unittest -import tempfile import pathlib +import tempfile +import unittest + from pyperformance import _pyproject_toml @@ -44,17 +45,17 @@ def test_parse_full_valid_project_section(self): def test_parse_fails_on_missing_name(self): with tempfile.TemporaryDirectory() as tmpdir: - toml_content = """ + 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)) + 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 = """ + toml_content = """ [project] name = "my-test-bench" version = "1.0" @@ -63,8 +64,8 @@ def test_parse_fails_on_unsupported_section(self): key = "value" """ - with self.assertRaisesRegex(ValueError, "unsupported sections"): - _pyproject_toml.parse_pyproject_toml(toml_content, rootdir=str(tmpdir)) + 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: @@ -94,5 +95,6 @@ def test_parse_readme_file_missing_with_requirefiles_false(self): ) self.assertEqual(data["project"]["readme"]["file"], "MISSING_README.md") + if __name__ == "__main__": unittest.main() From 24846a8036038d6a717ca4f01b3165ccb66b5f2a Mon Sep 17 00:00:00 2001 From: maurycy <5383+maurycy@users.noreply.github.com> Date: Mon, 22 Sep 2025 20:54:13 +0200 Subject: [PATCH 4/5] fix odd indent --- pyperformance/tests/test_pyproject_toml.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/pyperformance/tests/test_pyproject_toml.py b/pyperformance/tests/test_pyproject_toml.py index 904424d9..be8a43e3 100644 --- a/pyperformance/tests/test_pyproject_toml.py +++ b/pyperformance/tests/test_pyproject_toml.py @@ -46,9 +46,9 @@ def test_parse_full_valid_project_section(self): def test_parse_fails_on_missing_name(self): with tempfile.TemporaryDirectory() as tmpdir: toml_content = """ - [project] - version = "1.0" - """ + [project] + version = "1.0" + """ with self.assertRaisesRegex(ValueError, r'missing required "name" field'): _pyproject_toml.parse_pyproject_toml(toml_content, rootdir=str(tmpdir)) @@ -56,13 +56,13 @@ def test_parse_fails_on_missing_name(self): def test_parse_fails_on_unsupported_section(self): with tempfile.TemporaryDirectory() as tmpdir: toml_content = """ - [project] - name = "my-test-bench" - version = "1.0" + [project] + name = "my-test-bench" + version = "1.0" - [foobar] - key = "value" - """ + [foobar] + key = "value" + """ with self.assertRaisesRegex(ValueError, "unsupported sections"): _pyproject_toml.parse_pyproject_toml(toml_content, rootdir=str(tmpdir)) From d31b6448a3abe959475c5d04df7995f398fde08a Mon Sep 17 00:00:00 2001 From: maurycy <5383+maurycy@users.noreply.github.com> Date: Mon, 22 Sep 2025 20:56:03 +0200 Subject: [PATCH 5/5] consistent new lines --- pyperformance/tests/test_pyproject_toml.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pyperformance/tests/test_pyproject_toml.py b/pyperformance/tests/test_pyproject_toml.py index be8a43e3..022dd4aa 100644 --- a/pyperformance/tests/test_pyproject_toml.py +++ b/pyperformance/tests/test_pyproject_toml.py @@ -89,7 +89,6 @@ def test_parse_readme_file_missing_with_requirefiles_false(self): version = "1.0" readme = "MISSING_README.md" """ - data = _pyproject_toml.parse_pyproject_toml( toml_content, rootdir=str(tmpdir), requirefiles=False )