diff options
author | Stefano Rivera <stefano@rivera.za.net> | 2020-10-09 23:47:58 -0700 |
---|---|---|
committer | Stefano Rivera <stefano@rivera.za.net> | 2020-10-09 23:47:58 -0700 |
commit | 561a10722008ff11486eb312a49e9e109f775115 (patch) | |
tree | 4f65b1fc7064dfeb07b7542a23dae3431fb4eb2d /extra_tests | |
parent | bpo-30058: Fixed buffer overflow in select.kqueue.control(). (diff) | |
parent | typo (diff) | |
download | pypy-561a10722008ff11486eb312a49e9e109f775115.tar.gz pypy-561a10722008ff11486eb312a49e9e109f775115.tar.bz2 pypy-561a10722008ff11486eb312a49e9e109f775115.zip |
merge default into stdlib-2.7.18-3
Diffstat (limited to 'extra_tests')
-rw-r--r-- | extra_tests/cffi_tests/test_c.py | 4 | ||||
-rw-r--r-- | extra_tests/test_os.py | 103 |
2 files changed, 105 insertions, 2 deletions
diff --git a/extra_tests/cffi_tests/test_c.py b/extra_tests/cffi_tests/test_c.py index 95ca81274a..643cc904ee 100644 --- a/extra_tests/cffi_tests/test_c.py +++ b/extra_tests/cffi_tests/test_c.py @@ -4515,5 +4515,5 @@ def test_unaligned_types(): pbuf1 = cast(new_pointer_type(p), pbuf + 1) pbuf1[0] = num assert pbuf1[0] == num - assert buf[0] == '\x00' - assert buf[1 + size] == '\x00' + assert buf[0] == b'\x00' + assert buf[1 + size] == b'\x00' diff --git a/extra_tests/test_os.py b/extra_tests/test_os.py new file mode 100644 index 0000000000..0f60f370b8 --- /dev/null +++ b/extra_tests/test_os.py @@ -0,0 +1,103 @@ +import os +import sys +from pytest import raises, skip + +python = sys.executable + +if hasattr(os, "execv"): + def test_execv(): + if not hasattr(os, "fork"): + skip("Need fork() to test execv()") + if not os.path.isdir('/tmp'): + skip("Need '/tmp' for test") + pid = os.fork() + if pid == 0: + os.execv("/usr/bin/env", ["env", python, "-c", + ("fid = open('/tmp/onefile0', 'w'); " + "fid.write('1'); " + "fid.close()")]) + os.waitpid(pid, 0) + assert open("/tmp/onefile0").read() == "1" + os.unlink("/tmp/onefile0") + + def test_execv_raising(): + with raises(OSError): + os.execv("saddsadsadsadsa", ["saddsadsasaddsa"]) + + def test_execv_no_args(): + with raises(ValueError): + os.execv("notepad", []) + # PyPy needs at least one arg, CPython 2.7 is fine without + with raises(ValueError): + os.execve("notepad", [], {}) + + def test_execv_raising2(): + for n in 3, [3, "a"]: + with raises(TypeError): + os.execv("xxx", n) + + def test_execv_unicode(): + if not hasattr(os, "fork"): + skip("Need fork() to test execv()") + if not os.path.isdir('/tmp'): + skip("Need '/tmp' for test") + try: + output = u"caf\xe9 \u1234\n".encode(sys.getfilesystemencoding()) + except UnicodeEncodeError: + skip("encoding not good enough") + pid = os.fork() + if pid == 0: + os.execv(u"/bin/sh", ["sh", "-c", + u"echo caf\xe9 \u1234 > /tmp/onefile1"]) + os.waitpid(pid, 0) + with open("/tmp/onefile1") as fid: + assert fid.read() == output + os.unlink("/tmp/onefile1") + + def test_execve(): + if not hasattr(os, "fork"): + skip("Need fork() to test execve()") + if not os.path.isdir('/tmp'): + skip("Need '/tmp' for test") + pid = os.fork() + if pid == 0: + os.execve("/bin/sh", + ["sh", "-c", "echo -n $ddd > /tmp/onefile2"], + {'ddd': 'xxx'}, + ) + os.waitpid(pid, 0) + assert open("/tmp/onefile2").read() == "xxx" + os.unlink("/tmp/onefile2") + + def test_execve_unicode(): + if not hasattr(os, "fork"): + skip("Need fork() to test execve()") + if not os.path.isdir('/tmp'): + skip("Need '/tmp' for test") + try: + output = u"caf\xe9 \u1234\n".encode(sys.getfilesystemencoding()) + except UnicodeEncodeError: + skip("encoding not good enough") + pid = os.fork() + if pid == 0: + os.execve(u"/bin/sh", ["sh", "-c", + u"echo caf\xe9 \u1234 > /tmp/onefile3"], + {'ddd': 'xxx'}) + os.waitpid(pid, 0) + with open("/tmp/onefile3") as fid: + assert fid.read() == output + os.unlink("/tmp/onefile3") + pass # <- please, inspect.getsource(), don't crash + +if hasattr(os, "spawnv"): + def test_spawnv(): + ret = os.spawnv(os.P_WAIT, python, + [python, '-c', 'raise(SystemExit(42))']) + assert ret == 42 + +if hasattr(os, "spawnve"): + def test_spawnve(): + env = {'FOOBAR': '42'} + cmd = "exit $FOOBAR" + ret = os.spawnve(os.P_WAIT, "/bin/sh", ["sh", '-c', cmd], env) + assert ret == 42 |