test/objectstore: proper path concatenation
Instead of using string interpolation and concatenation to build file system paths, use `os.path.join` or directly the constructor for `pathlib.Path`, which can take path segments.
This commit is contained in:
parent
6813fa4acc
commit
80e96c8494
1 changed files with 17 additions and 17 deletions
|
|
@ -36,7 +36,7 @@ class TestObjectStore(unittest.TestCase):
|
||||||
|
|
||||||
with object_store.new() as tree:
|
with object_store.new() as tree:
|
||||||
with tree.write() as path:
|
with tree.write() as path:
|
||||||
p = Path(f"{path}/A")
|
p = Path(path, "A")
|
||||||
p.touch()
|
p.touch()
|
||||||
object_store.commit(tree, "a")
|
object_store.commit(tree, "a")
|
||||||
|
|
||||||
|
|
@ -49,9 +49,9 @@ class TestObjectStore(unittest.TestCase):
|
||||||
|
|
||||||
with object_store.new() as tree:
|
with object_store.new() as tree:
|
||||||
with tree.write() as path:
|
with tree.write() as path:
|
||||||
p = Path(f"{path}/A")
|
p = Path(path, "A")
|
||||||
p.touch()
|
p.touch()
|
||||||
p = Path(f"{path}/B")
|
p = Path(path, "B")
|
||||||
p.touch()
|
p.touch()
|
||||||
object_store.commit(tree, "b")
|
object_store.commit(tree, "b")
|
||||||
|
|
||||||
|
|
@ -74,7 +74,7 @@ class TestObjectStore(unittest.TestCase):
|
||||||
tree = object_store.new()
|
tree = object_store.new()
|
||||||
self.assertEqual(len(os.listdir(object_store.tmp)), 1)
|
self.assertEqual(len(os.listdir(object_store.tmp)), 1)
|
||||||
with tree.write() as path:
|
with tree.write() as path:
|
||||||
p = Path(f"{path}/A")
|
p = Path(path, "A")
|
||||||
p.touch()
|
p.touch()
|
||||||
# there should be no temporary Objects dirs anymore
|
# there should be no temporary Objects dirs anymore
|
||||||
self.assertEqual(len(os.listdir(object_store.tmp)), 0)
|
self.assertEqual(len(os.listdir(object_store.tmp)), 0)
|
||||||
|
|
@ -85,14 +85,14 @@ class TestObjectStore(unittest.TestCase):
|
||||||
object_store = objectstore.ObjectStore(tmp)
|
object_store = objectstore.ObjectStore(tmp)
|
||||||
with object_store.new() as tree:
|
with object_store.new() as tree:
|
||||||
with tree.write() as path:
|
with tree.write() as path:
|
||||||
p = Path(f"{path}/A")
|
p = Path(path, "A")
|
||||||
p.touch()
|
p.touch()
|
||||||
object_store.commit(tree, "a")
|
object_store.commit(tree, "a")
|
||||||
|
|
||||||
with object_store.new() as tree:
|
with object_store.new() as tree:
|
||||||
with tree.write() as path:
|
with tree.write() as path:
|
||||||
shutil.copy2(f"{object_store.refs}/a/A",
|
shutil.copy2(f"{object_store.refs}/a/A",
|
||||||
f"{path}/A")
|
os.path.join(path, "A"))
|
||||||
object_store.commit(tree, "b")
|
object_store.commit(tree, "b")
|
||||||
|
|
||||||
assert os.path.exists(f"{object_store.refs}/a")
|
assert os.path.exists(f"{object_store.refs}/a")
|
||||||
|
|
@ -111,7 +111,7 @@ class TestObjectStore(unittest.TestCase):
|
||||||
object_store = objectstore.ObjectStore(tmp)
|
object_store = objectstore.ObjectStore(tmp)
|
||||||
with object_store.new() as tree:
|
with object_store.new() as tree:
|
||||||
with tree.write() as path:
|
with tree.write() as path:
|
||||||
p = Path(f"{path}/A")
|
p = Path(path, "A")
|
||||||
p.touch()
|
p.touch()
|
||||||
object_store.commit(tree, "a")
|
object_store.commit(tree, "a")
|
||||||
|
|
||||||
|
|
@ -122,7 +122,7 @@ class TestObjectStore(unittest.TestCase):
|
||||||
with object_store.new() as tree:
|
with object_store.new() as tree:
|
||||||
tree.base = "b"
|
tree.base = "b"
|
||||||
with tree.write() as path:
|
with tree.write() as path:
|
||||||
p = Path(f"{path}/C")
|
p = Path(path, "C")
|
||||||
p.touch()
|
p.touch()
|
||||||
object_store.commit(tree, "c")
|
object_store.commit(tree, "c")
|
||||||
|
|
||||||
|
|
@ -146,7 +146,7 @@ class TestObjectStore(unittest.TestCase):
|
||||||
with object_store.new() as tree:
|
with object_store.new() as tree:
|
||||||
path = tree.write()
|
path = tree.write()
|
||||||
with tree.write() as path, \
|
with tree.write() as path, \
|
||||||
open(f"{path}/data", "w") as f:
|
open(os.path.join(path, "data"), "w") as f:
|
||||||
f.write(data)
|
f.write(data)
|
||||||
st = os.fstat(f.fileno())
|
st = os.fstat(f.fileno())
|
||||||
data_inode = st.st_ino
|
data_inode = st.st_ino
|
||||||
|
|
@ -158,7 +158,7 @@ class TestObjectStore(unittest.TestCase):
|
||||||
# check that "data" is still the very
|
# check that "data" is still the very
|
||||||
# same file after committing
|
# same file after committing
|
||||||
with tree.read() as path:
|
with tree.read() as path:
|
||||||
with open(f"{path}/data", "r") as f:
|
with open(os.path.join(path, "data"), "r") as f:
|
||||||
st = os.fstat(f.fileno())
|
st = os.fstat(f.fileno())
|
||||||
self.assertEqual(st.st_ino, data_inode)
|
self.assertEqual(st.st_ino, data_inode)
|
||||||
data_read = f.read()
|
data_read = f.read()
|
||||||
|
|
@ -172,7 +172,7 @@ class TestObjectStore(unittest.TestCase):
|
||||||
self.assertEqual(tree.base, "x")
|
self.assertEqual(tree.base, "x")
|
||||||
self.assertEqual(tree.treesum, x_hash)
|
self.assertEqual(tree.treesum, x_hash)
|
||||||
with tree.read() as path:
|
with tree.read() as path:
|
||||||
with open(f"{path}/data", "r") as f:
|
with open(os.path.join(path, "data"), "r") as f:
|
||||||
# copy-on-write: since we have not written
|
# copy-on-write: since we have not written
|
||||||
# to the tree yet, "data" should be the
|
# to the tree yet, "data" should be the
|
||||||
# very same file as that one of object "x"
|
# very same file as that one of object "x"
|
||||||
|
|
@ -182,11 +182,11 @@ class TestObjectStore(unittest.TestCase):
|
||||||
self.assertEqual(data, data_read)
|
self.assertEqual(data, data_read)
|
||||||
with tree.write() as path:
|
with tree.write() as path:
|
||||||
# "data" must of course still be present
|
# "data" must of course still be present
|
||||||
assert os.path.exists(f"{path}/data")
|
assert os.path.exists(os.path.join(path, "data"))
|
||||||
# but since it is a copy, have a different inode
|
# but since it is a copy, have a different inode
|
||||||
st = os.stat(f"{path}/data")
|
st = os.stat(os.path.join(path, "data"))
|
||||||
self.assertNotEqual(st.st_ino, data_inode)
|
self.assertNotEqual(st.st_ino, data_inode)
|
||||||
p = Path(f"{path}/other_data")
|
p = Path(path, "other_data")
|
||||||
p.touch()
|
p.touch()
|
||||||
# now that we have written, the treesum
|
# now that we have written, the treesum
|
||||||
# should have changed
|
# should have changed
|
||||||
|
|
@ -250,13 +250,13 @@ class TestObjectStore(unittest.TestCase):
|
||||||
object_store = objectstore.ObjectStore(self.store)
|
object_store = objectstore.ObjectStore(self.store)
|
||||||
with object_store.new() as tree:
|
with object_store.new() as tree:
|
||||||
with tree.write() as path:
|
with tree.write() as path:
|
||||||
p = Path(f"{path}/A")
|
p = Path(path, "A")
|
||||||
p.touch()
|
p.touch()
|
||||||
assert not object_store.contains("a")
|
assert not object_store.contains("a")
|
||||||
object_store.commit(tree, "a")
|
object_store.commit(tree, "a")
|
||||||
assert object_store.contains("a")
|
assert object_store.contains("a")
|
||||||
with tree.write() as path:
|
with tree.write() as path:
|
||||||
p = Path(f"{path}/B")
|
p = Path(path, "B")
|
||||||
p.touch()
|
p.touch()
|
||||||
object_store.commit(tree, "b")
|
object_store.commit(tree, "b")
|
||||||
|
|
||||||
|
|
@ -282,6 +282,6 @@ class TestObjectStore(unittest.TestCase):
|
||||||
|
|
||||||
# check we actually cannot write to the path
|
# check we actually cannot write to the path
|
||||||
with host.read() as path:
|
with host.read() as path:
|
||||||
p = Path(f"{path}/osbuild-test-file")
|
p = Path(path, "osbuild-test-file")
|
||||||
with self.assertRaises(OSError):
|
with self.assertRaises(OSError):
|
||||||
p.touch()
|
p.touch()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue