diff options
author | Matti Picus <matti.picus@gmail.com> | 2020-10-03 19:32:57 +0300 |
---|---|---|
committer | Matti Picus <matti.picus@gmail.com> | 2020-10-03 19:32:57 +0300 |
commit | 43ae3dec8b6fd8152f99c311767f7023c26545fe (patch) | |
tree | 34760a3a39835673879eda1bc45c8a54f2e28889 /extra_tests | |
parent | move translated os.* tests to extra_tests (diff) | |
download | pypy-43ae3dec8b6fd8152f99c311767f7023c26545fe.tar.gz pypy-43ae3dec8b6fd8152f99c311767f7023c26545fe.tar.bz2 pypy-43ae3dec8b6fd8152f99c311767f7023c26545fe.zip |
redo moved tests, flake8
Diffstat (limited to 'extra_tests')
-rw-r--r-- | extra_tests/test_os.py | 69 |
1 files changed, 28 insertions, 41 deletions
diff --git a/extra_tests/test_os.py b/extra_tests/test_os.py index 2f101f8ab4..df692355de 100644 --- a/extra_tests/test_os.py +++ b/extra_tests/test_os.py @@ -1,13 +1,16 @@ import os +import sys +from pytest import raises, skip -if hasattr(__import__(os.name), "execv"): - def test_execv(self): - os = self.posix +python = sys.executable + +if hasattr(os, "execv"): + def test_execv(): if not hasattr(os, "fork"): skip("Need fork() to test execv()") pid = os.fork() if pid == 0: - os.execv("/usr/bin/env", ["env", self.python, "-c", + os.execv("/usr/bin/env", ["env", python, "-c", ("fid = open('onefile', 'w'); " "fid.write('1'); " "fid.close()")]) @@ -15,27 +18,23 @@ if hasattr(__import__(os.name), "execv"): assert open("onefile").read() == "1" os.unlink("onefile") - def test_execv_raising(self): - os = self.posix + def test_execv_raising(): with raises(OSError): os.execv("saddsadsadsadsa", ["saddsadsasaddsa"]) - def test_execv_no_args(self): - os = self.posix + 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(self): - os = self.posix + def test_execv_raising2(): for n in 3, [3, "a"]: - with raises(TypeError) as excinfo: + with raises(TypeError): os.execv("xxx", n) - def test_execv_unicode(self): - os = self.posix - import sys + def test_execv_unicode(): if not hasattr(os, "fork"): skip("Need fork() to test execv()") try: @@ -51,24 +50,21 @@ if hasattr(__import__(os.name), "execv"): assert fid.read() == output os.unlink("onefile") - def test_execve(self): - os = self.posix + def test_execve(): if not hasattr(os, "fork"): skip("Need fork() to test execve()") pid = os.fork() if pid == 0: - os.execve("/usr/bin/env", ["env", self.python, "-c", + os.execve("/usr/bin/env", ["env", python, "-c", ("import os; fid = open('onefile', 'w'); " "fid.write(os.environ['ddd']); " "fid.close()")], - {'ddd':'xxx'}) + {'ddd': 'xxx'}) os.waitpid(pid, 0) assert open("onefile").read() == "xxx" os.unlink("onefile") - def test_execve_unicode(self): - os = self.posix - import sys + def test_execve_unicode(): if not hasattr(os, "fork"): skip("Need fork() to test execve()") try: @@ -78,32 +74,23 @@ if hasattr(__import__(os.name), "execv"): pid = os.fork() if pid == 0: os.execve(u"/bin/sh", ["sh", "-c", - u"echo caf\xe9 \u1234 > onefile"], + u"echo caf\xe9 \u1234 > onefile"], {'ddd': 'xxx'}) os.waitpid(pid, 0) with open("onefile") as fid: assert fid.read() == output os.unlink("onefile") - pass # <- please, inspect.getsource(), don't crash + pass # <- please, inspect.getsource(), don't crash -if hasattr(__import__(os.name), "spawnv"): - # spawnv is from stdlib's os, so this test is never run - def test_spawnv(self): - os = self.posix - import sys - ret = os.spawnv(os.P_WAIT, self.python, - [self.python, '-c', 'raise(SystemExit(42))']) +if hasattr(os, "spawnv"): + def test_spawnv(): + ret = os.spawnv(os.P_WAIT, python, + [python, '-c', 'raise(SystemExit(42))']) assert ret == 42 -if hasattr(__import__(os.name), "spawnve"): - # spawnve is from stdlib's os, so this test is never run - def test_spawnve(self): - os = self.posix - env = {'PATH':os.environ['PATH'], 'FOOBAR': '42'} - ret = os.spawnve(os.P_WAIT, self.python, - [self.python, '-c', - "raise(SystemExit(int(__import__('os').environ['FOOBAR'])))"], - env) +if hasattr(os, "spawnve"): + def test_spawnve(): + env = {'PATH': os.environ['PATH'], 'FOOBAR': '42'} + cmd = "raise(SystemExit(int(__import__('os').environ['FOOBAR'])))" + ret = os.spawnve(os.P_WAIT, python, [python, '-c', cmd], env) assert ret == 42 - - |