Skip to content

Commit

Permalink
fixup! build: validate build-system table schema
Browse files Browse the repository at this point in the history
  • Loading branch information
layday committed Sep 29, 2021
1 parent f7bae87 commit 1dd2d35
Showing 1 changed file with 16 additions and 19 deletions.
35 changes: 16 additions & 19 deletions tests/test_projectbuilder.py
@@ -1,7 +1,6 @@
# SPDX-License-Identifier: MIT


import contextlib
import copy
import importlib
import logging
Expand Down Expand Up @@ -32,11 +31,6 @@
}


@contextlib.contextmanager
def nullcontext():
yield


class MockDistribution(importlib_metadata.Distribution):
def locate_file(self, path): # pragma: no cover
return ''
Expand Down Expand Up @@ -580,50 +574,53 @@ def test_log(mocker, caplog, test_flit_path):


@pytest.mark.parametrize(
['pyproject_toml', 'raises'],
('pyproject_toml', 'error_message'),
[
(
{'build-system': {}},
pytest.raises(build.BuildSystemTableValidationError, match='`requires` is a required property'),
'`requires` is a required property',
),
(
{'build-system': {'requires': 'not an array'}},
pytest.raises(build.BuildSystemTableValidationError, match='`requires` must be an array of strings'),
'`requires` must be an array of strings',
),
(
{'build-system': {'requires': [1]}},
pytest.raises(build.BuildSystemTableValidationError, match='`requires` must be an array of strings'),
'`requires` must be an array of strings',
),
(
{'build-system': {'requires': ['foo']}},
nullcontext(),
None,
),
(
{'build-system': {'requires': ['foo'], 'build-backend': ['not a string']}},
pytest.raises(build.BuildSystemTableValidationError, match='`build-backend` must be a string'),
'`build-backend` must be a string',
),
(
{'build-system': {'requires': ['foo'], 'build-backend': 'bar'}},
nullcontext(),
None,
),
(
{'build-system': {'requires': ['foo'], 'backend-path': 'not an array'}},
pytest.raises(build.BuildSystemTableValidationError, match='`backend-path` must be an array of strings'),
'`backend-path` must be an array of strings',
),
(
{'build-system': {'requires': ['foo'], 'backend-path': [1]}},
pytest.raises(build.BuildSystemTableValidationError, match='`backend-path` must be an array of strings'),
'`backend-path` must be an array of strings',
),
(
{'build-system': {'requires': ['foo'], 'build-backend': 'bar', 'backend-path': ['baz']}},
nullcontext(),
None,
),
(
{'build-system': {'requires': ['foo'], 'unknown-prop': False}},
pytest.raises(build.BuildSystemTableValidationError, match='Unknown properties: unknown-prop'),
'Unknown properties: unknown-prop',
),
],
)
def test_parse_build_system_table_type_validation(pyproject_toml, raises):
with raises:
def test_parse_build_system_table_type_validation(pyproject_toml, error_message):
if error_message is not None:
with pytest.raises(build.BuildSystemTableValidationError, match=error_message):
build._parse_build_system_table(pyproject_toml)
else:
build._parse_build_system_table(pyproject_toml)

0 comments on commit 1dd2d35

Please sign in to comment.