Debian Codegraph @

extra_tests/test_startup.py

raw symbols SCIP
1 import signal
2 import time
3 import os
4 import subprocess
5 import sys
6
7 def test_platform_not_imported():
8 import subprocess
9 out = subprocess.check_output([sys.executable, '-c',
10 'import sys; print(list(sys.modules.keys()))'], universal_newlines=True)
11 modules = [x.strip(' "\'') for x in out.strip().strip('[]').split(',')]
12 assert 'platform' not in modules
13 assert 'threading' not in modules
14
15
16 def test_executable_win32():
17 # issue #4003
18 import os
19 import sys
20
21 out = subprocess.check_output([r'*', '-c',
22 'import sys; print (repr(sys.executable))'], universal_newlines=True, executable=sys.executable)
23 if sys.platform == 'win32':
24 assert out.strip() == repr(sys.executable)
25
26 fake_executable = r'C:\Windows\System32\cmd.exe'
27 assert os.path.isfile(fake_executable) # should exist always
28 out = subprocess.check_output([fake_executable, '-c',
29 'import sys; print (repr(sys.executable))'], universal_newlines=True, executable=sys.executable)
30 assert out.strip() == repr(sys.executable)
31 else:
32 assert out.strip() == repr('')
33
34
35 def test_ctrl_c_causes_atexit():
36 process = subprocess.Popen(
37 [sys.executable,
38 '-c',
39 "import atexit, time, sys; atexit.register(lambda : print('called atexit')); print('sleeping'); sys.stdout.flush(); time.sleep(100)"],
40 stdout=subprocess.PIPE, stderr=subprocess.PIPE)
41 line = process.stdout.readline()
42 assert line == b'sleeping\n'
43 os.kill(process.pid, signal.SIGINT)
44 process.wait()
45 assert process.returncode == -signal.SIGINT
46 line = process.stdout.read()
47 assert line == b'called atexit\n'
48