diff options
author | Thomas Koch <thomas@koch.ro> | 2013-01-21 15:50:39 +0100 |
---|---|---|
committer | Guido Günther <agx@sigxcpu.org> | 2013-04-08 07:43:02 +0200 |
commit | 3d6b68ae541d6020ff747628b3e44196999e0a50 (patch) | |
tree | bb3f94d4f9c0af6eb3a9779dbf6bbee20a512ef0 /tests/04_test_submodules.py | |
parent | 92edb4eda14cf4b5fd1514feb7b81aa50456285c (diff) |
tests: Use tempfile.mkdtemp to create temp dirs for tests
This puts test dirs below /tmp which often is a tmpfs.
All tests include the context module which consolidates tmpdir creation
and cleanup, undoes a chdir in teardown and silences log messages.
Diffstat (limited to 'tests/04_test_submodules.py')
-rw-r--r-- | tests/04_test_submodules.py | 29 |
1 files changed, 12 insertions, 17 deletions
diff --git a/tests/04_test_submodules.py b/tests/04_test_submodules.py index efcc9aaa..d96d67ab 100644 --- a/tests/04_test_submodules.py +++ b/tests/04_test_submodules.py @@ -2,9 +2,12 @@ """Test submodule L{GitRepository} submodule methods""" +from . import context + import os import shutil import tarfile +import tempfile import gbp.log import gbp.git @@ -12,7 +15,6 @@ import gbp.command_wrappers from gbp.scripts import buildpackage -top = None repo = None repodir = None @@ -29,27 +31,20 @@ class Submodule(object): def setup(): - global repo, repodir, submodules, top, tmpdir - - gbp.log.setup(False, False) - top = os.path.abspath(os.curdir) - tmpdir =os.path.join(top,'gbp_%s_repo' % __name__) - os.mkdir(tmpdir) + global repo, repodir, submodules, tmpdir - repodir = os.path.join(tmpdir, 'test_repo') + tmpdir = context.new_tmpdir(__name__) + repodir = tmpdir.join('test_repo') repo = gbp.git.GitRepository.create(repodir) for name in submodule_names: - submodules.append(Submodule(name, tmpdir)) + submodules.append(Submodule(name, str(tmpdir))) - os.chdir(repodir) + context.chdir(repodir) def teardown(): - os.chdir(top) - if not os.getenv("GBP_TESTS_NOCLEAN") and tmpdir: - shutil.rmtree(tmpdir) - + context.teardown() def test_empty_has_submodules(): """Test empty repo for submodules""" @@ -96,7 +91,7 @@ def test_get_submodules(): def test_dump_tree(): """Dump the repository and check if files exist""" - dumpdir = os.path.join(tmpdir, "dump") + dumpdir = tmpdir.join("dump") os.mkdir(dumpdir) assert buildpackage.dump_tree(repo, dumpdir, "master", True) assert os.path.exists(os.path.join(dumpdir, testfile_name)) @@ -108,7 +103,7 @@ def test_create_tarball(): cp = { "Source": "test", "Upstream-Version": "0.1" } assert buildpackage.git_archive(repo, cp, - tmpdir, + str(tmpdir), "HEAD", "bzip2", "9", @@ -116,7 +111,7 @@ def test_create_tarball(): def test_check_tarfile(): """Check the contents of the created tarfile""" - t = tarfile.open(os.path.join(tmpdir,"test_0.1.orig.tar.bz2"), 'r:*') + t = tarfile.open(tmpdir.join("test_0.1.orig.tar.bz2"), 'r:*') files = t.getmembers() assert "test-0.1/.gitmodules" in [ f.name for f in files ] assert len(files) == 6 |