File: test_utils.py

package info (click to toggle)
python-whey 0.1.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,912 kB
  • sloc: python: 4,433; makefile: 7
file content (84 lines) | stat: -rw-r--r-- 2,742 bytes parent folder | download | duplicates (2)
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
# stdlib
from typing import TYPE_CHECKING, Dict, Type

# 3rd party
import click
import pytest
from coincidence.regressions import AdvancedDataRegressionFixture, AdvancedFileRegressionFixture
from domdf_python_tools.paths import PathPlus
from pyproject_examples import MINIMAL_CONFIG

# this package
from whey.builder import AbstractBuilder, SDistBuilder, WheelBuilder
from whey.foreman import Foreman
from whey.utils import parse_custom_builders, print_builder_names

if TYPE_CHECKING:
	# 3rd party
	from _pytest.capture import CaptureFixture


@pytest.mark.parametrize(
		"config",
		[
				pytest.param(MINIMAL_CONFIG, id="default"),
				pytest.param(f'{MINIMAL_CONFIG}\n[tool.whey.builders]\nsdist = "whey_sdist"', id="sdist"),
				pytest.param(f'{MINIMAL_CONFIG}\n[tool.whey.builders]\nwheel = "whey_wheel"', id="wheel"),
				pytest.param(f'{MINIMAL_CONFIG}\n[tool.whey.builders]\nbinary = "whey_wheel"', id="binary_wheel"),
				pytest.param(
						f'{MINIMAL_CONFIG}\n[tool.whey.builders]\nsdist = "whey_sdist"\nwheel = "whey_wheel"',
						id="sdist_and_wheel",
						),
				]
		)
@pytest.mark.parametrize(
		"builders",
		[
				pytest.param({"sdist": True}, id="sdist_true"),
				pytest.param({"wheel": True}, id="wheel_true"),
				pytest.param({"binary": True}, id="binary_true"),
				pytest.param({"sdist": True, "wheel": True}, id="sdist_and_wheel"),
				pytest.param({"binary": False, "wheel": True}, id="true_and_false"),
				]
		)
@pytest.mark.parametrize(
		"custom_builders",
		[
				pytest.param({}, id="none"),
				]

		)
@pytest.mark.skip(reason="unknown error")
def test_print_builder_names(
		tmp_pathplus: PathPlus,
		config: str,
		builders: Dict[str, bool],
		custom_builders: Dict[str, Type[AbstractBuilder]],
		advanced_file_regression: AdvancedFileRegressionFixture,
		capsys: "CaptureFixture[str]",
		):
	(tmp_pathplus / "pyproject.toml").write_clean(config)

	foreman = Foreman(project_dir=tmp_pathplus)
	print_builder_names(foreman, custom_builders, **builders)
	advanced_file_regression.check(capsys.readouterr().out)


@pytest.mark.skip(reason="unknown error")
def test_parse_custom_builders(advanced_data_regression: AdvancedDataRegressionFixture, ):

	assert parse_custom_builders(None) == {}
	assert parse_custom_builders([]) == {}
	assert parse_custom_builders(()) == {}
	assert parse_custom_builders(iter([])) == {}
	assert parse_custom_builders(_ for _ in ()) == {}

	assert parse_custom_builders(["whey_sdist"]) == {"whey_sdist": SDistBuilder}
	assert parse_custom_builders(["whey_wheel"]) == {"whey_wheel": WheelBuilder}


	with pytest.raises(
			click.BadArgumentUsage,
			match=f"Unknown builder 'foo'. \nIs it registered as an entry point under 'whey.builder'?"
			):
		parse_custom_builders(["foo"])