Skip to content

Commit 4cd5e95

Browse files
authored
Migrate more test examples to use pytest parametrization (#1278)
1 parent f4967e8 commit 4cd5e95

4 files changed

Lines changed: 415 additions & 304 deletions

File tree

constructor/exceptions.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,9 @@ def error_body(self):
5757
"""),
5858
]
5959
)
60+
61+
62+
class InvalidInstallerTypeError(Exception):
63+
"""Raised when installer_type is invalid for the target platform."""
64+
65+
pass

constructor/main.py

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from .construct import parse as construct_parse
3131
from .construct import render as construct_render
3232
from .construct import verify as construct_verify
33+
from .exceptions import InvalidInstallerTypeError
3334
from .fcp import main as fcp_main
3435
from .utils import (
3536
StandaloneExe,
@@ -46,6 +47,13 @@
4647

4748

4849
def get_installer_type(info: dict):
50+
"""Return the installer type(s) to build for the given platform.
51+
52+
Raises
53+
------
54+
InvalidInstallerTypeError
55+
If the installer type is not valid for the target platform.
56+
"""
4957
osname, unused_arch = info["_platform"].split("-")
5058

5159
os_allowed = {"linux": ("sh",), "osx": ("sh", "pkg"), "win": ("exe", "msi")}
@@ -62,28 +70,31 @@ def get_installer_type(info: dict):
6270
for t in itype:
6371
if t not in all_allowed:
6472
all_allowed_str = ", ".join(sorted(all_allowed))
65-
sys.exit("Error: invalid installer type '%s'; allowed: %s" % (t, all_allowed_str))
73+
raise InvalidInstallerTypeError(
74+
f"invalid installer type '{t}'; allowed: {all_allowed_str}"
75+
)
6676
if t not in os_allowed[osname]:
6777
os_allowed_str = ", ".join(sorted(os_allowed[osname]))
68-
sys.exit(
69-
"Error: invalid installer type '%s' for %s; allowed: %s"
70-
% (t, osname, os_allowed_str)
78+
raise InvalidInstallerTypeError(
79+
f"invalid installer type '{t}' for {osname}; allowed: {os_allowed_str}"
7180
)
7281
return tuple(itype)
7382
elif itype not in all_allowed:
74-
all_allowed = ", ".join(sorted(all_allowed))
75-
sys.exit("Error: invalid installer type '%s'; allowed: %s" % (itype, all_allowed))
83+
all_allowed_str = ", ".join(sorted(all_allowed))
84+
raise InvalidInstallerTypeError(
85+
f"invalid installer type '{itype}'; allowed: {all_allowed_str}"
86+
)
7687
elif itype == "docker":
7788
if osname != "linux":
78-
sys.exit(
79-
"Error: Docker features are only supported for Linux target platforms. "
89+
raise InvalidInstallerTypeError(
90+
"Docker features are only supported for Linux target platforms. "
8091
"Use --platform linux-ARCH to build a Docker artifact."
8192
)
8293
return ("sh", "docker")
8394
elif itype not in os_allowed[osname]:
84-
os_allowed = ", ".join(sorted(os_allowed[osname]))
85-
sys.exit(
86-
"Error: invalid installer type '%s' for %s; allowed: %s" % (itype, osname, os_allowed)
95+
os_allowed_str = ", ".join(sorted(os_allowed[osname]))
96+
raise InvalidInstallerTypeError(
97+
f"invalid installer type '{itype}' for {osname}; allowed: {os_allowed_str}"
8798
)
8899
else:
89100
return (itype,)
@@ -234,7 +245,10 @@ def main_build(
234245
info["_debug"] = debug
235246
if installer_type:
236247
info["installer_type"] = installer_type
237-
itypes = get_installer_type(info)
248+
try:
249+
itypes = get_installer_type(info)
250+
except InvalidInstallerTypeError as e:
251+
sys.exit(f"Error: {e}")
238252

239253
if "docker" in itypes:
240254
if not info.get("docker_base_image"):

examples/azure_signtool/construct.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

44
name: Signed_AzureSignTool
55
version: 1.0.0
6-
installer_type: [exe, msi]
6+
installer_type:
7+
- exe
8+
- msi
79
channels:
810
- https://repo.anaconda.com/pkgs/main/
911
specs:

0 commit comments

Comments
 (0)