summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/test_find_top_level.py4
-rw-r--r--tests/test_verify.py3
-rw-r--r--tests/testutil.py12
3 files changed, 19 insertions, 0 deletions
diff --git a/tests/test_find_top_level.py b/tests/test_find_top_level.py
index 184fe72..c4df873 100644
--- a/tests/test_find_top_level.py
+++ b/tests/test_find_top_level.py
@@ -11,6 +11,8 @@ import pytest
from gemato.find_top_level import find_top_level_manifest
+from tests.testutil import disallow_writes
+
@pytest.fixture(scope='module')
def plain_tree(tmp_path_factory):
@@ -33,6 +35,7 @@ IGNORE ignored-empty-dir
'ignored-dir/Manifest'):
with open(tmp_path / f, 'w'):
pass
+ disallow_writes(tmp_path)
yield tmp_path
@@ -107,6 +110,7 @@ IGNORE ignored-empty-dir
'ignored-dir/Manifest.gz'):
with gzip.GzipFile(tmp_path / f, 'w'):
pass
+ disallow_writes(tmp_path)
yield tmp_path
diff --git a/tests/test_verify.py b/tests/test_verify.py
index 79c5513..1f3170b 100644
--- a/tests/test_verify.py
+++ b/tests/test_verify.py
@@ -24,6 +24,8 @@ from gemato.verify import (
verify_entry_compatibility,
)
+from tests.testutil import disallow_writes
+
TEST_STRING = b'The quick brown fox jumps over the lazy dog'
@@ -46,6 +48,7 @@ def test_tree(tmp_path_factory):
unix_sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
unix_sock.bind(str(tmp_path / 'unix-socket'))
unix_sock.listen(1)
+ disallow_writes(tmp_path)
yield tmp_path
unix_sock.close()
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()