Monkeypatch sys.argv instead of using an argument to main()
Just a style thing... didn't want to complicate the main func for the sake of a couple tests
This commit is contained in:
@@ -2,7 +2,7 @@ import argparse
|
||||
import os
|
||||
import sys
|
||||
import textwrap
|
||||
from typing import List, Optional, Set, Union
|
||||
from typing import List, Set, Union
|
||||
|
||||
import cibuildwheel
|
||||
import cibuildwheel.linux
|
||||
@@ -15,7 +15,7 @@ from cibuildwheel.typing import PLATFORMS, PlatformName, assert_never
|
||||
from cibuildwheel.util import BuildSelector, Unbuffered, detect_ci_provider
|
||||
|
||||
|
||||
def main(sys_args: Optional[List[str]] = None) -> None:
|
||||
def main() -> None:
|
||||
platform: PlatformName
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
@@ -98,7 +98,7 @@ def main(sys_args: Optional[List[str]] = None) -> None:
|
||||
help="Enable pre-release Python versions if available.",
|
||||
)
|
||||
|
||||
args = parser.parse_args(args=sys_args, namespace=CommandLineArguments())
|
||||
args = parser.parse_args(namespace=CommandLineArguments())
|
||||
|
||||
if args.platform != "auto":
|
||||
platform = args.platform
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import platform as platform_module
|
||||
import subprocess
|
||||
import sys
|
||||
from contextlib import contextmanager
|
||||
from pathlib import Path
|
||||
from typing import cast
|
||||
@@ -40,9 +41,11 @@ def mock_build_docker(monkeypatch):
|
||||
monkeypatch.setattr("cibuildwheel.util.print_new_wheels", ignore_context_call)
|
||||
|
||||
|
||||
def test_build_default_launches(mock_build_docker, fake_package_dir):
|
||||
def test_build_default_launches(mock_build_docker, fake_package_dir, monkeypatch):
|
||||
monkeypatch.setattr(sys, "argv", ["cibuildwheel", "--platform=linux"])
|
||||
|
||||
main()
|
||||
|
||||
main(["--platform=linux"])
|
||||
build_on_docker = cast(mock.Mock, linux.build_on_docker)
|
||||
|
||||
assert build_on_docker.call_count == 4
|
||||
@@ -106,7 +109,10 @@ before-all = "true"
|
||||
)
|
||||
|
||||
monkeypatch.chdir(pkg_dir)
|
||||
main(["--platform=linux"])
|
||||
monkeypatch.setattr(sys, "argv", ["cibuildwheel", "--platform=linux"])
|
||||
|
||||
main()
|
||||
|
||||
build_on_docker = cast(mock.Mock, linux.build_on_docker)
|
||||
|
||||
assert build_on_docker.call_count == 6
|
||||
|
||||
Reference in New Issue
Block a user