|
1 | 1 | import os |
| 2 | +import signal |
2 | 3 | import sys |
3 | 4 | import sysconfig |
4 | 5 |
|
@@ -735,6 +736,43 @@ def test_scripts_no_environment(hatch, helpers, temp_dir, config_file): |
735 | 736 | assert os.path.realpath(output_file.read_text().strip()).lower() == os.path.realpath(sys.executable).lower() |
736 | 737 |
|
737 | 738 |
|
| 739 | +def test_interrupt_signal_not_inherited(hatch, temp_dir, config_file): |
| 740 | + config_file.model.template.plugins["default"]["tests"] = False |
| 741 | + config_file.save() |
| 742 | + |
| 743 | + project_name = "My.App" |
| 744 | + |
| 745 | + with temp_dir.as_cwd(): |
| 746 | + result = hatch("new", project_name) |
| 747 | + |
| 748 | + assert result.exit_code == 0, result.output |
| 749 | + |
| 750 | + project_path = temp_dir / "my-app" |
| 751 | + data_path = temp_dir / "data" |
| 752 | + data_path.mkdir() |
| 753 | + |
| 754 | + project = Project(project_path) |
| 755 | + config = dict(project.raw_config) |
| 756 | + config["tool"]["hatch"]["scripts"] = {"py": "python -c {args}"} |
| 757 | + project.save_config(config) |
| 758 | + |
| 759 | + original_handler = signal.getsignal(signal.SIGINT) |
| 760 | + |
| 761 | + with project_path.as_cwd(env_vars={ConfigEnvVars.DATA: str(data_path)}): |
| 762 | + result = hatch( |
| 763 | + "run", |
| 764 | + ":py", |
| 765 | + "import pathlib,signal;pathlib.Path('test.txt').write_text(str(signal.getsignal(signal.SIGINT)))", |
| 766 | + ) |
| 767 | + |
| 768 | + assert result.exit_code == 0, result.output |
| 769 | + |
| 770 | + output_file = project_path / "test.txt" |
| 771 | + assert output_file.read_text() == str(signal.default_int_handler) |
| 772 | + |
| 773 | + assert signal.getsignal(signal.SIGINT) is original_handler |
| 774 | + |
| 775 | + |
738 | 776 | def test_error(hatch, helpers, temp_dir, config_file): |
739 | 777 | config_file.model.template.plugins["default"]["tests"] = False |
740 | 778 | config_file.save() |
|
0 commit comments