Skip to content

Commit 12614cc

Browse files
author
Franziska Geiger
committed
Added test case
1 parent 9e6f597 commit 12614cc

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

graalpython/com.oracle.graal.python.test/src/tests/test_posix.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,16 @@
3838
# SOFTWARE.
3939

4040
import unittest
41+
import os
42+
import sys
43+
import posix
44+
import stat
4145

4246

4347
class PosixTests(unittest.TestCase):
4448

4549
def test_uname(self):
4650
# just like cpython, a simple smoke test
47-
import posix
4851
uname = posix.uname()
4952
self.assertRaises(TypeError, lambda: posix.uname(1))
5053
self.assertIsNotNone(uname.sysname)
@@ -56,28 +59,30 @@ def test_uname(self):
5659
def test_execv(self):
5760
# test creates a shell script, which again creates a file, to ensure script execution
5861
# Both files are deleted again in the end
59-
import os
60-
import sys
6162
new_file_path, cwd = self.create_file()
62-
# os.execv(new_file_path, [new_file_path, 'the_input'])
6363
os.system("%s -c \"import os; os.execv('%s', ['%s', 'the_input'])\"" % (sys.executable, new_file_path, new_file_path))
6464
assert os.path.isfile(cwd + '/test.txt')
6565
self.delete_file(new_file_path, cwd)
6666

6767
def test_execl(self):
6868
# test creates a shell script, which again creates a file, to ensure script execution
6969
# Both files are deleted again in the end
70-
import os
71-
import sys
7270
new_file_path, cwd = self.create_file()
73-
# os.execl(new_file_path, [new_file_path, 'the_input'])
7471
os.system("%s -c \"import os; os.execl('%s', ['%s', 'the_input'])\"" % (sys.executable, new_file_path, new_file_path))
7572
assert os.path.isfile(cwd + '/test.txt')
7673
self.delete_file(new_file_path, cwd)
7774

75+
def test_execv_with_env(self):
76+
new_file_path, cwd = self.create_file()
77+
with open(new_file_path, 'w') as script:
78+
script.write('echo $ENV_VAR> {}/test.txt\n'.format(cwd))
79+
os.system("%s -c \"import os; os.environ['ENV_VAR']='the_text'; os.execl('%s', ['%s', 'the_input'])\"" % (sys.executable, new_file_path, new_file_path))
80+
assert os.path.isfile(cwd + '/test.txt')
81+
with open(cwd+'/test.txt', 'r') as result:
82+
assert 'the_text' in result.readline()
83+
self.delete_file(new_file_path, cwd)
84+
7885
def create_file(self):
79-
import os
80-
import stat
8186
cwd = os.getcwd()
8287
new_file_path = os.path.join(cwd , 'myscript.sh')
8388
with open(new_file_path, 'w') as script:
@@ -90,6 +95,5 @@ def create_file(self):
9095
return new_file_path, cwd
9196

9297
def delete_file(self, new_file_path, cwd):
93-
import os
9498
os.remove(new_file_path)
9599
os.remove(cwd + '/test.txt')

0 commit comments

Comments
 (0)