summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/unittests/test_util.py33
1 files changed, 31 insertions, 2 deletions
diff --git a/tests/unittests/test_util.py b/tests/unittests/test_util.py
index ab74311e..5d21b4b7 100644
--- a/tests/unittests/test_util.py
+++ b/tests/unittests/test_util.py
@@ -103,8 +103,8 @@ class TestWriteFile(helpers.TestCase):
self.assertTrue(os.path.isdir(dirname))
self.assertTrue(os.path.isfile(path))
- def test_custom_mode(self):
- """Verify custom mode works properly."""
+ def test_explicit_mode(self):
+ """Verify explicit file mode works properly."""
path = os.path.join(self.tmp, "NewFile.txt")
contents = "Hey there"
@@ -115,6 +115,35 @@ class TestWriteFile(helpers.TestCase):
file_stat = os.stat(path)
self.assertEqual(0o666, stat.S_IMODE(file_stat.st_mode))
+ def test_copy_mode_no_existing(self):
+ """Verify that file is created with mode 0o644 if copy_mode
+ is true and there is no prior existing file."""
+ path = os.path.join(self.tmp, "NewFile.txt")
+ contents = "Hey there"
+
+ util.write_file(path, contents, copy_mode=True)
+
+ self.assertTrue(os.path.exists(path))
+ self.assertTrue(os.path.isfile(path))
+ file_stat = os.stat(path)
+ self.assertEqual(0o644, stat.S_IMODE(file_stat.st_mode))
+
+ def test_copy_mode_with_existing(self):
+ """Verify that file is created using mode of existing file
+ if copy_mode is true."""
+ path = os.path.join(self.tmp, "NewFile.txt")
+ contents = "Hey there"
+
+ open(path, 'w').close()
+ os.chmod(path, 0o666)
+
+ util.write_file(path, contents, copy_mode=True)
+
+ self.assertTrue(os.path.exists(path))
+ self.assertTrue(os.path.isfile(path))
+ file_stat = os.stat(path)
+ self.assertEqual(0o666, stat.S_IMODE(file_stat.st_mode))
+
def test_custom_omode(self):
"""Verify custom omode works properly."""
path = os.path.join(self.tmp, "NewFile.txt")