From 02cbd89ae6f7e338b732992051c927af24daf7cb Mon Sep 17 00:00:00 2001 From: Joe Rickerby Date: Sat, 28 Aug 2021 11:15:33 +0100 Subject: [PATCH] Improve troubleshooting tests and add test for repair step --- test/test_troubleshooting.py | 54 +++++++++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 13 deletions(-) diff --git a/test/test_troubleshooting.py b/test/test_troubleshooting.py index 6a58ca1f..0c3c04c1 100644 --- a/test/test_troubleshooting.py +++ b/test/test_troubleshooting.py @@ -3,25 +3,23 @@ import subprocess import pytest from . import utils -from .test_projects import TestProject +from .test_projects import TestProject, new_c_project -so_file_project = TestProject() - -so_file_project.files["libnothing.so"] = "" - -so_file_project.files[ - "setup.py" -] = """ -raise Exception('this build will fail') -""" +SO_FILE_WARNING = "NOTE: Shared object (.so) files found in this project." -def test_failed_project_with_so_files(tmp_path, capfd, build_frontend_env): +@pytest.mark.parametrize("project_contains_so_files", [False, True]) +def test_failed_build_with_so_files(tmp_path, capfd, build_frontend_env, project_contains_so_files): + project = TestProject() + project.files["setup.py"] = "raise Exception('this build will fail')\n" + if project_contains_so_files: + project.files["libnothing.so"] = "" + if utils.platform != "linux": pytest.skip("this test is only relevant to the linux build") project_dir = tmp_path / "project" - so_file_project.generate(project_dir) + project.generate(project_dir) with pytest.raises(subprocess.CalledProcessError): utils.cibuildwheel_run(project_dir, add_env=build_frontend_env) @@ -29,4 +27,34 @@ def test_failed_project_with_so_files(tmp_path, capfd, build_frontend_env): captured = capfd.readouterr() print("out", captured.out) print("err", captured.err) - assert "NOTE: Shared object (.so) files found in this project." in captured.err + + if project_contains_so_files: + assert SO_FILE_WARNING in captured.err + else: + assert SO_FILE_WARNING not in captured.err + + +@pytest.mark.parametrize("project_contains_so_files", [False, True]) +def test_failed_repair_with_so_files(tmp_path, capfd, project_contains_so_files): + if utils.platform != "linux": + pytest.skip("this test is only relevant to the linux build") + + project = new_c_project() + + if project_contains_so_files: + project.files["libnothing.so"] = "" + + project_dir = tmp_path / "project" + project.generate(project_dir) + + with pytest.raises(subprocess.CalledProcessError): + utils.cibuildwheel_run(project_dir, add_env={"CIBW_REPAIR_COMMAND": "false"}) + + captured = capfd.readouterr() + print("out", captured.out) + print("err", captured.err) + + if project_contains_so_files: + assert SO_FILE_WARNING in captured.err + else: + assert SO_FILE_WARNING not in captured.err