diff options
author | Michał Górny <mgorny@gentoo.org> | 2020-08-31 19:05:34 +0200 |
---|---|---|
committer | Michał Górny <mgorny@gentoo.org> | 2020-09-05 11:15:10 +0200 |
commit | 6ad33d2d0abe1cec2c19d1e1d14a8b81c3a14c43 (patch) | |
tree | a5144f3ab7f74b2ed39721ca51fe6e13d271ce6d /tests/testutil.py | |
parent | 653b7927c146c1549ddaf23afaeea9f97fdee065 (diff) | |
download | gemato-6ad33d2d0abe1cec2c19d1e1d14a8b81c3a14c43.tar.gz |
tests: Mark module-scope test dirs read-only
Signed-off-by: Michał Górny <mgorny@gentoo.org>
Diffstat (limited to 'tests/testutil.py')
-rw-r--r-- | tests/testutil.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/tests/testutil.py b/tests/testutil.py index 092a4d2..bde84f7 100644 --- a/tests/testutil.py +++ b/tests/testutil.py @@ -11,6 +11,7 @@ import os import os.path import random import shutil +import stat import tempfile import threading import unittest @@ -21,6 +22,17 @@ from http.server import HTTPServer, BaseHTTPRequestHandler from urllib.parse import urlparse, parse_qs +def disallow_writes(path): + """Mark path non-writable, recursively""" + for dirpath, dirs, files in os.walk(path, topdown=False): + for f in files + dirs: + st = os.lstat(os.path.join(dirpath, f)) + if not stat.S_ISLNK(st.st_mode): + os.chmod(os.path.join(dirpath, f), + st.st_mode & ~0o222) + os.chmod(path, 0o555) + + class LoggingTestCase(unittest.TestCase): def setUp(self): self.log = io.StringIO() |