-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refs #19 - Added tests for rst2rst.tests.test_fixtures.fixture_names(…
…) and refactored fixture_names().
- Loading branch information
1 parent
5548e89
commit cffa09d
Showing
3 changed files
with
69 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Temporary directory management.""" | ||
import shutil | ||
import tempfile | ||
|
||
|
||
class temporary_directory(object): | ||
"""Create, yield, and finally delete a temporary directory. | ||
>>> from rst2rst.utils.tempdir import temporary_directory | ||
>>> import os | ||
>>> with temporary_directory() as directory: | ||
... os.path.isdir(directory) | ||
True | ||
>>> os.path.exists(directory) | ||
False | ||
Deletion of temporary directory is recursive. | ||
>>> with temporary_directory() as directory: | ||
... filename = os.path.join(directory, 'sample.txt') | ||
... __ = open(filename, 'w').close() | ||
... os.path.isfile(filename) | ||
True | ||
>>> os.path.isfile(filename) | ||
False | ||
""" | ||
def __enter__(self): | ||
"""Create temporary directory and return its path.""" | ||
self.path = tempfile.mkdtemp() | ||
return self.path | ||
|
||
def __exit__(self, exc_type=None, exc_val=None, exc_tb=None): | ||
"""Remove temporary directory recursively.""" | ||
shutil.rmtree(self.path) |