| 1 |
import os |
| 2 |
import sys |
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
def test_have_functions(): |
| 7 |
assert os.stat in os.supports_fd |
| 8 |
if os.name != 'nt': |
| 9 |
assert os.chdir in os.supports_fd |
| 10 |
else: |
| 11 |
assert os.chdir not in os.supports_fd |
| 12 |
if os.name == 'posix': |
| 13 |
assert os.open in os.supports_dir_fd |
| 14 |
|
| 15 |
def test_popen(): |
| 16 |
for i in range(5): |
| 17 |
stream = os.popen('echo 1') |
| 18 |
res = stream.read() |
| 19 |
assert res == '1\n' |
| 20 |
assert stream.close() is None |
| 21 |
|
| 22 |
def test_popen_with(): |
| 23 |
stream = os.popen('echo 1') |
| 24 |
with stream as fp: |
| 25 |
res = fp.read() |
| 26 |
assert res == '1\n' |
| 27 |
|
| 28 |
def test_pickle(): |
| 29 |
import pickle |
| 30 |
st = os.stat('.') |
| 31 |
|
| 32 |
s = pickle.dumps(st) |
| 33 |
|
| 34 |
new = pickle.loads(s) |
| 35 |
assert new == st |
| 36 |
assert type(new) is type(st) |
| 37 |
|
| 38 |
if hasattr(os, "fork") and not sys.platform == 'darwin': |
| 39 |
def test_fork_hook_creates_thread_bug(): |
| 40 |
|
| 41 |
import threading |
| 42 |
def daemon(): |
| 43 |
while 1: |
| 44 |
time.sleep(10) |
| 45 |
|
| 46 |
daemon_thread = None |
| 47 |
def create_thread(): |
| 48 |
nonlocal daemon_thread |
| 49 |
daemon_thread = threading.Thread(name="b", target=daemon, daemon=True) |
| 50 |
daemon_thread.start() |
| 51 |
|
| 52 |
os.register_at_fork(after_in_child=create_thread) |
| 53 |
pid = os.fork() |
| 54 |
if pid == 0: |
| 55 |
os._exit(daemon_thread._ident in threading._active) |
| 56 |
|
| 57 |
pid1, status1 = os.waitpid(pid, 0) |
| 58 |
assert status1 == 0 |