Use proper tempfile isolation of GnuPG homedirs in unittests.

testing/mmn/mktime_takes_localtime_not_gmtime
Isis Lovecruft 2013-05-11 18:17:22 +00:00
parent 14ffe14569
commit d38efaffbc
No known key found for this signature in database
GPG Key ID: A3ADB67A2CDB8B35
1 changed files with 16 additions and 6 deletions

View File

@ -35,13 +35,12 @@ __version__ = gnupg.__version__
logger = logging.getLogger('gnupg')
_here = os.path.join(os.path.join(util._repo, 'gnupg'), 'tests')
_files = os.path.join(_here, 'files')
_tempd = os.path.join(_here, 'tmp')
tempfile.tempdir = os.path.join(_here, 'tmp_test')
tempfile.tempdir = _tempd
if not os.path.isdir(tempfile.gettempdir()):
os.mkdir(tempfile.gettempdir())
HOME_DIR = tempfile.tempdir
@wraps(tempfile.TemporaryFile)
def _make_tempfile(*args, **kwargs):
return tempfile.TemporaryFile(dir=tempfile.gettempdir(),
@ -137,7 +136,7 @@ class GPGTestCase(unittest.TestCase):
def setUp(self):
"""This method is called once per self.test_* method."""
hd = HOME_DIR
hd = tempfile.mkdtemp()
if os.path.exists(hd):
self.assertTrue(os.path.isdir(hd), "Not a directory: %s" % hd)
shutil.rmtree(hd)
@ -146,6 +145,17 @@ class GPGTestCase(unittest.TestCase):
self.keyring = os.path.join(self.homedir, 'keyring.gpg')
self.secring = os.path.join(self.homedir, 'secring.gpg')
def tearDown(self):
"""This is called once per self.test_* method after the test run."""
if os.path.exists(self.homedir) and os.path.isdir(self.homedir):
try:
shutil.rmtree(self.homedir)
except OSError as ose:
logger.error(ose)
else:
logger.warn("Can't delete homedir: '%s' not a directory"
% self.homedir)
def test_parsers_fix_unsafe(self):
"""Test that unsafe inputs are quoted out and then ignored."""
shell_input = "\"&coproc /bin/sh\""
@ -826,8 +836,8 @@ def main(args):
catchbreak=True)
## Finally, remove our testing directory:
if os.path.isdir(tempfile.gettempdir()):
os.removedirs(tempfile.gettempdir())
if os.path.isdir(_tempd):
os.unlink(_tempd)
if __name__ == "__main__":