8000 move test code to another file · python/cpython@1d45196 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1d45196

Browse files
committed
move test code to another file
1 parent 5a3cff5 commit 1d45196

File tree

2 files changed

+24
-18
lines changed

2 files changed

+24
-18
lines changed

Lib/test/namespaces-test.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import os
2+
import sys
3+
4+
5+
def main():
6+
fd = os.open('/proc/self/ns/uts', os.O_RDONLY)
7+
try:
8+
print(os.readlink('/proc/self/ns/uts'))
9+
os.unshare(os.CLONE_NEWUTS)
10+
print(os.readlink('/proc/self/ns/uts'))
11+
os.setns(fd, os.CLONE_NEWUTS)
12+
print(os.readlink('/proc/self/ns/uts'))
13+
except OSError as e:
14+
sys.stderr.write(str(e.errno))
15+
sys.exit(2)
16+
finally:
17+
os.close(fd)
18+
19+
20+
if __name__ == '__main__':
21+
main()

Lib/test/test_posix.py

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2176,9 +2176,9 @@ class NamespacesTests(unittest.TestCase):
21762176
"""Tests for os.unshare() and os.setns()."""
21772177

21782178
@support.requires_subprocess()
2179-
def subprocess(self, code):
2179+
def subprocess(self, file_path):
21802180
import subprocess
2181-
with subprocess.Popen((sys.executable, '-c', code),
2181+
with subprocess.Popen((sys.executable, file_path),
21822182
stdout=subprocess.PIPE,
21832183
stderr=subprocess.PIPE,
21842184
encoding="utf-8"
@@ -2195,22 +2195,7 @@ def subprocess(self, code):
21952195
@unittest.skipUnless(os.path.exists('/proc/self/ns/uts'), 'need /proc/self/ns/uts')
21962196
@support.requires_linux_version(3, 0, 0)
21972197
def test_unshare_setns(self):
2198-
rc, out, err = self.subprocess("""if 1:
2199-
import os
2200-
import sys
2201-
fd = os.open('/proc/self/ns/uts', os.O_RDONLY)
2202-
try:
2203-
print(os.readlink('/proc/self/ns/uts'))
2204-
os.unshare(os.CLONE_NEWUTS)
2205-
print(os.readlink('/proc/self/ns/uts'))
2206-
os.setns(fd, os.CLONE_NEWUTS)
2207-
print(os.readlink('/proc/self/ns/uts'))
2208-
except OSError as e:
2209-
sys.stderr.write(str(e.errno))
2210-
sys.exit(2)
2211-
finally:
2212-
os.close(fd)
2213-
""")
2198+
rc, out, err = self.subprocess(support.findfile("namespaces-test.py"))
22142199

22152200
if rc == 2:
22162201
e = int(err[0])

0 commit comments

Comments
 (0)
0