(self)
| 1128 | |
| 1129 | @warnings_helper.ignore_fork_in_thread_deprecation_warnings() |
| 1130 | def test_sys_exit(self): |
| 1131 | # See Issue 13854 |
| 1132 | if self.TYPE == 'threads': |
| 1133 | self.skipTest('test not appropriate for {}'.format(self.TYPE)) |
| 1134 | |
| 1135 | testfn = os_helper.TESTFN |
| 1136 | self.addCleanup(os_helper.unlink, testfn) |
| 1137 | |
| 1138 | for reason in ( |
| 1139 | [1, 2, 3], |
| 1140 | 'ignore this', |
| 1141 | ): |
| 1142 | p = self.Process(target=self._test_sys_exit, args=(reason, testfn)) |
| 1143 | p.daemon = True |
| 1144 | p.start() |
| 1145 | join_process(p) |
| 1146 | self.assertEqual(p.exitcode, 1) |
| 1147 | |
| 1148 | with open(testfn, encoding="utf-8") as f: |
| 1149 | content = f.read() |
| 1150 | self.assertEqual(content.rstrip(), str(reason)) |
| 1151 | |
| 1152 | os.unlink(testfn) |
| 1153 | |
| 1154 | cases = [ |
| 1155 | ((True,), 1), |
| 1156 | ((False,), 0), |
| 1157 | ((8,), 8), |
| 1158 | ((None,), 0), |
| 1159 | ((), 0), |
| 1160 | ] |
| 1161 | |
| 1162 | for args, expected in cases: |
| 1163 | with self.subTest(args=args): |
| 1164 | p = self.Process(target=sys.exit, args=args) |
| 1165 | p.daemon = True |
| 1166 | p.start() |
| 1167 | join_process(p) |
| 1168 | self.assertEqual(p.exitcode, expected) |
| 1169 | |
| 1170 | # |
| 1171 | # |
nothing calls this directly
no test coverage detected