Skip to content

Commit 88bc2f9

Browse files
authored
Wrapped tempfile.gettempdir (#7)
This patch adds a very thin wrapper for `tempfile.gettempdir`. Fixes #6.
1 parent 4342abc commit 88bc2f9

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

temppathlib/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,3 +241,13 @@ def __enter__(self) -> 'NamedTemporaryFile':
241241
def __exit__(self, exc_type, exc_val, exc_tb) -> None: # type: ignore
242242
"""Close the temporary file."""
243243
self.close()
244+
245+
246+
def gettempdir() -> pathlib.Path:
247+
"""
248+
Wrap ``tempfile.gettempdir``.
249+
250+
Please see the documentation of ``tempfile.gettempdir`` for more details:
251+
https://docs.python.org/3/library/tempfile.html#tempfile.gettempdir
252+
"""
253+
return pathlib.Path(tempfile.gettempdir())

tests/test_temppathlib.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,5 +135,13 @@ def test_with_dir(self) -> None:
135135
self.assertTrue(tmp.path.exists())
136136

137137

138+
class TestGettempdir(unittest.TestCase):
139+
def test_that_it_works(self) -> None:
140+
tmpdir = temppathlib.gettempdir()
141+
142+
original_tmpdir = tempfile.gettempdir()
143+
self.assertEqual(original_tmpdir, str(tmpdir))
144+
145+
138146
if __name__ == '__main__':
139147
unittest.main()

0 commit comments

Comments
 (0)