Skip to content

Commit

Permalink
move test code to another file
Browse files Browse the repository at this point in the history
  • Loading branch information
noamcohen97 committed Jul 26, 2022
1 parent 5a3cff5 commit 1d45196
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
21 changes: 21 additions & 0 deletions Lib/test/namespaces-test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import os
import sys


def main():
fd = os.open('/proc/self/ns/uts', os.O_RDONLY)
try:
print(os.readlink('/proc/self/ns/uts'))
os.unshare(os.CLONE_NEWUTS)
print(os.readlink('/proc/self/ns/uts'))
os.setns(fd, os.CLONE_NEWUTS)
print(os.readlink('/proc/self/ns/uts'))
except OSError as e:
sys.stderr.write(str(e.errno))
sys.exit(2)
finally:
os.close(fd)


if __name__ == '__main__':
main()
21 changes: 3 additions & 18 deletions Lib/test/test_posix.py
Original file line number Diff line number Diff line change
Expand Up @@ -2176,9 +2176,9 @@ class NamespacesTests(unittest.TestCase):
"""Tests for os.unshare() and os.setns()."""

@support.requires_subprocess()
def subprocess(self, code):
def subprocess(self, file_path):
import subprocess
with subprocess.Popen((sys.executable, '-c', code),
with subprocess.Popen((sys.executable, file_path),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
encoding="utf-8"
Expand All @@ -2195,22 +2195,7 @@ def subprocess(self, code):
@unittest.skipUnless(os.path.exists('/proc/self/ns/uts'), 'need /proc/self/ns/uts')
@support.requires_linux_version(3, 0, 0)
def test_unshare_setns(self):
rc, out, err = self.subprocess("""if 1:
import os
import sys
fd = os.open('/proc/self/ns/uts', os.O_RDONLY)
try:
print(os.readlink('/proc/self/ns/uts'))
os.unshare(os.CLONE_NEWUTS)
print(os.readlink('/proc/self/ns/uts'))
os.setns(fd, os.CLONE_NEWUTS)
print(os.readlink('/proc/self/ns/uts'))
except OSError as e:
sys.stderr.write(str(e.errno))
sys.exit(2)
finally:
os.close(fd)
""")
rc, out, err = self.subprocess(support.findfile("namespaces-test.py"))

if rc == 2:
e = int(err[0])
Expand Down

0 comments on commit 1d45196

Please sign in to comment.