summaryrefslogtreecommitdiff
path: root/tests/test_util.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_util.py')
-rw-r--r--tests/test_util.py19
1 files changed, 18 insertions, 1 deletions
diff --git a/tests/test_util.py b/tests/test_util.py
index 8e4fbd6b0..1ec283187 100644
--- a/tests/test_util.py
+++ b/tests/test_util.py
@@ -9,12 +9,15 @@
:license: BSD, see LICENSE for details.
"""
+import os
+import tempfile
+
import pytest
from mock import patch
from sphinx.testing.util import strip_escseq
from sphinx.util import (
- display_chunk, encode_uri, parselinenos, status_iterator, xmlname_checker
+ display_chunk, encode_uri, ensuredir, parselinenos, status_iterator, xmlname_checker
)
from sphinx.util import logging
@@ -34,6 +37,20 @@ def test_encode_uri():
assert expected, encode_uri(uri)
+def test_ensuredir():
+ with tempfile.TemporaryDirectory() as tmp_path:
+ # Does not raise an exception for an existing directory.
+ ensuredir(tmp_path)
+
+ path = os.path.join(tmp_path, 'a', 'b', 'c')
+ ensuredir(path)
+ assert os.path.isdir(path)
+
+ with tempfile.NamedTemporaryFile() as tmp:
+ with pytest.raises(OSError):
+ ensuredir(tmp.name)
+
+
def test_display_chunk():
assert display_chunk('hello') == 'hello'
assert display_chunk(['hello']) == 'hello'