diff options
author | Daniel Watkins <oddbloke@ubuntu.com> | 2020-06-19 12:03:53 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-19 12:03:53 -0400 |
commit | 40e72860e6a7d8876731cc1cfda4e499d119f2a1 (patch) | |
tree | cdf607d7bd9242a0ac27642c8820fc6226e3b411 /tests/unittests | |
parent | d083a0315faf67c00acdecdc3f95c700edf6ba06 (diff) | |
download | vyos-cloud-init-40e72860e6a7d8876731cc1cfda4e499d119f2a1.tar.gz vyos-cloud-init-40e72860e6a7d8876731cc1cfda4e499d119f2a1.zip |
util: add ensure_dir_exists parameter to write_file (#443)
This allows us to disable the `ensure_dir` call when it isn't
appropriate.
Diffstat (limited to 'tests/unittests')
-rw-r--r-- | tests/unittests/test_util.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/tests/unittests/test_util.py b/tests/unittests/test_util.py index 0821341f..409dba61 100644 --- a/tests/unittests/test_util.py +++ b/tests/unittests/test_util.py @@ -98,6 +98,17 @@ class TestWriteFile(helpers.TestCase): self.assertTrue(os.path.isdir(dirname)) self.assertTrue(os.path.isfile(path)) + def test_dir_is_not_created_if_ensure_dir_false(self): + """Verify directories are not created if ensure_dir_exists is False.""" + dirname = os.path.join(self.tmp, "subdir") + path = os.path.join(dirname, "NewFile.txt") + contents = "Hey there" + + with self.assertRaises(FileNotFoundError): + util.write_file(path, contents, ensure_dir_exists=False) + + self.assertFalse(os.path.isdir(dirname)) + def test_explicit_mode(self): """Verify explicit file mode works properly.""" path = os.path.join(self.tmp, "NewFile.txt") |