1#!/usr/bin/env python 2# -*- coding: utf-8 -*- 3 4"""test_outside_project_root 5---------------------------------- 6 7Tries to build the `fail-outside-project-root` sample project. Ensures that the 8attempt fails with a SystemExit exception that has an SKBuildError exception as 9its value. 10""" 11 12import pytest 13 14from skbuild.exceptions import SKBuildError 15from skbuild.utils import push_dir 16 17from . import project_setup_py_test 18 19 20@pytest.mark.parametrize("option", [ 21 None, 22 '-DINSTALL_FILE:BOOL=1', 23 '-DINSTALL_PROJECT:BOOL=1' 24]) 25def test_outside_project_root_fails(option): 26 27 with push_dir(): 28 29 expected_failure = False 30 31 cmd = ["install"] 32 if option is not None: 33 expected_failure = True 34 cmd.extend(["--", option]) 35 36 @project_setup_py_test("fail-outside-project-root", cmd, disable_languages_test=True) 37 def should_fail(): 38 pass 39 40 failed = False 41 msg = "" 42 try: 43 should_fail() 44 except SystemExit as e: 45 failed = isinstance(e.code, SKBuildError) 46 msg = str(e) 47 except SKBuildError as e: 48 failed = True 49 msg = str(e) 50 51 assert expected_failure == failed 52 53 if expected_failure: 54 assert "CMake-installed files must be within the project root." in msg 55