From 2a873e1a4d6babf37e417c9da3e4e1b3640bc347 Mon Sep 17 00:00:00 2001 From: Guido Günther Date: Wed, 28 Dec 2011 22:04:03 +0100 Subject: Rename and comment tests Git-Dch: Ignore --- tests/01_test_help.py | 4 +- tests/02_test_import.py | 80 ---------------- tests/02_test_upstream_source_tar_unpack.py | 82 ++++++++++++++++ tests/03_test_dch_guess_version.py | 6 +- tests/04_test_gbp_submodules.py | 137 --------------------------- tests/04_test_submodules.py | 139 ++++++++++++++++++++++++++++ tests/05_test_detection.py | 4 + tests/06_test_upstream_source.py | 6 +- tests/07_test_fastimport.py | 2 + tests/08_test_patch.py | 4 + 10 files changed, 243 insertions(+), 221 deletions(-) delete mode 100644 tests/02_test_import.py create mode 100644 tests/02_test_upstream_source_tar_unpack.py delete mode 100644 tests/04_test_gbp_submodules.py create mode 100644 tests/04_test_submodules.py (limited to 'tests') diff --git a/tests/01_test_help.py b/tests/01_test_help.py index 02b19c8a..cee79118 100644 --- a/tests/01_test_help.py +++ b/tests/01_test_help.py @@ -1,6 +1,6 @@ # vim: set fileencoding=utf-8 : -# -# check if --help works + +"""Check if --help works""" import os import unittest diff --git a/tests/02_test_import.py b/tests/02_test_import.py deleted file mode 100644 index 6ded95af..00000000 --- a/tests/02_test_import.py +++ /dev/null @@ -1,80 +0,0 @@ -# vim: set fileencoding=utf-8 : - -import glob -import os -import shutil -import tarfile -import tempfile - -import gbp.deb - -class TestUnpack: - """Make sure we unpack gzip and bzip2 archives correctly""" - archive_prefix = "archive" - - def _unpack_dir(self, compression): - return "%s-%s" % (self.archive_prefix, compression) - - def _check_files(self, files, comp): - """Check if files exist in the unpacked dir""" - for f in files: - target = os.path.join(self._unpack_dir(comp), f) - assert os.path.exists(target), "%s does not exist" % target - - def _create_archive(self, comp): - filelist = [ 'README', 'setup.py' ] - - name = "%s_0.1.tar.%s" % (self.archive_prefix, comp) - t = tarfile.open(name= name, mode='w:%s' % comp) - for f in filelist: - t.add(os.path.join(self.top, f), - os.path.join(self._unpack_dir(comp), f)) - t.close() - return name, filelist - - def setUp(self): - self.dir = tempfile.mkdtemp(prefix='gbp_%s_' % __name__, dir='.') - self.top = os.path.abspath(os.curdir) - os.chdir(self.dir) - self.archives = {} - for ext in [ "gz", "bz2" ]: - self.archives[ext] = self._create_archive(ext) - - def tearDown(self): - os.chdir(self.top) - if not os.getenv("GBP_TESTS_NOCLEAN"): - shutil.rmtree(self.dir) - - def test_upstream_source_type(self): - for (comp, archive) in self.archives.iteritems(): - source = gbp.deb.UpstreamSource(archive[0]) - assert source.is_orig == True - assert source.is_dir == False - assert source.unpacked == None - source.unpack(".") - assert source.is_orig == True - assert source.is_dir == False - assert type(source.unpacked) == str - - def test_upstream_source_unpack(self): - for (comp, archive) in self.archives.iteritems(): - source = gbp.deb.UpstreamSource(archive[0]) - source.unpack(".") - self._check_files(archive[1], comp) - - def test_upstream_source_unpack_no_filter(self): - for (comp, archive) in self.archives.iteritems(): - source = gbp.deb.UpstreamSource(archive[0]) - source.unpack(".", []) - self._check_files(archive[1], comp) - - def test_upstream_source_unpack_filtered(self): - exclude = "README" - - for (comp, archive) in self.archives.iteritems(): - source = gbp.deb.UpstreamSource(archive[0]) - source.unpack(".", [exclude]) - archive[1].remove(exclude) - self._check_files(archive[1], comp) - -# vim:et:ts=4:sw=4:et:sts=4:ai:set list listchars=tab\:»·,trail\:·: diff --git a/tests/02_test_upstream_source_tar_unpack.py b/tests/02_test_upstream_source_tar_unpack.py new file mode 100644 index 00000000..9366dd95 --- /dev/null +++ b/tests/02_test_upstream_source_tar_unpack.py @@ -0,0 +1,82 @@ +# vim: set fileencoding=utf-8 : + +"""Test L{UpstreamSource}'s tarball unpack""" + +import glob +import os +import shutil +import tarfile +import tempfile + +import gbp.deb + +class TestUnpack: + """Make sure we unpack gzip and bzip2 archives correctly""" + archive_prefix = "archive" + + def _unpack_dir(self, compression): + return "%s-%s" % (self.archive_prefix, compression) + + def _check_files(self, files, comp): + """Check if files exist in the unpacked dir""" + for f in files: + target = os.path.join(self._unpack_dir(comp), f) + assert os.path.exists(target), "%s does not exist" % target + + def _create_archive(self, comp): + filelist = [ 'README', 'setup.py' ] + + name = "%s_0.1.tar.%s" % (self.archive_prefix, comp) + t = tarfile.open(name= name, mode='w:%s' % comp) + for f in filelist: + t.add(os.path.join(self.top, f), + os.path.join(self._unpack_dir(comp), f)) + t.close() + return name, filelist + + def setUp(self): + self.dir = tempfile.mkdtemp(prefix='gbp_%s_' % __name__, dir='.') + self.top = os.path.abspath(os.curdir) + os.chdir(self.dir) + self.archives = {} + for ext in [ "gz", "bz2" ]: + self.archives[ext] = self._create_archive(ext) + + def tearDown(self): + os.chdir(self.top) + if not os.getenv("GBP_TESTS_NOCLEAN"): + shutil.rmtree(self.dir) + + def test_upstream_source_type(self): + for (comp, archive) in self.archives.iteritems(): + source = gbp.deb.UpstreamSource(archive[0]) + assert source.is_orig == True + assert source.is_dir == False + assert source.unpacked == None + source.unpack(".") + assert source.is_orig == True + assert source.is_dir == False + assert type(source.unpacked) == str + + def test_upstream_source_unpack(self): + for (comp, archive) in self.archives.iteritems(): + source = gbp.deb.UpstreamSource(archive[0]) + source.unpack(".") + self._check_files(archive[1], comp) + + def test_upstream_source_unpack_no_filter(self): + for (comp, archive) in self.archives.iteritems(): + source = gbp.deb.UpstreamSource(archive[0]) + source.unpack(".", []) + self._check_files(archive[1], comp) + + def test_upstream_source_unpack_filtered(self): + exclude = "README" + + for (comp, archive) in self.archives.iteritems(): + source = gbp.deb.UpstreamSource(archive[0]) + source.unpack(".", [exclude]) + archive[1].remove(exclude) + self._check_files(archive[1], comp) + +# vim:et:ts=4:sw=4:et:sts=4:ai:set list listchars=tab\:»·,trail\:·: diff --git a/tests/03_test_dch_guess_version.py b/tests/03_test_dch_guess_version.py index 10343074..d954459d 100644 --- a/tests/03_test_dch_guess_version.py +++ b/tests/03_test_dch_guess_version.py @@ -1,3 +1,7 @@ +# vim: set fileencoding=utf-8 : + +"""Test L{Changelog}'s guess_version_from_upstream""" + import unittest from gbp.scripts import dch @@ -28,7 +32,7 @@ class MockedChangeLog(ChangeLog): class TestGuessVersionFromUpstream(unittest.TestCase): - """Dest guess_version_from_upstream""" + """Test guess_version_from_upstream""" def test_guess_no_epoch(self): """Guess the new version from the upstream tag""" repo = MockGitRepository(upstream_tag='upstream/1.1') diff --git a/tests/04_test_gbp_submodules.py b/tests/04_test_gbp_submodules.py deleted file mode 100644 index a20f668d..00000000 --- a/tests/04_test_gbp_submodules.py +++ /dev/null @@ -1,137 +0,0 @@ -# vim: set fileencoding=utf-8 : - -import os -import shutil -import tarfile -import tempfile - -import gbp.log -import gbp.git -import gbp.command_wrappers - -from gbp.scripts import buildpackage - -top = None -repo = None -repodir = None - -submodules = [] -submodule_names = ["test_submodule", "sub module"] -tmpdir = None -testfile_name = "testfile" - -class Submodule(object): - def __init__(self, name, tmpdir): - self.name = name - self.dir = os.path.join(tmpdir, name) - self.repo = gbp.git.GitRepository.create(self.dir) - - -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) - - repodir = os.path.join(tmpdir, 'test_repo') - repo = gbp.git.GitRepository.create(repodir) - - for name in submodule_names: - submodules.append(Submodule(name, tmpdir)) - - os.chdir(repodir) - - -def teardown(): - os.chdir(top) - if not os.getenv("GBP_TESTS_NOCLEAN") and tmpdir: - shutil.rmtree(tmpdir) - - -def test_empty_has_submodules(): - """Test empty repo for submodules""" - assert not repo.has_submodules() - - -def _add_dummy_data(repo, msg): - shutil.copy(".git/HEAD", testfile_name) - repo.add_files('.', force=True) - repo.commit_all(msg) - - -def test_add_files(): - """Add some dummy data""" - _add_dummy_data(repo, "initial commit") - assert True - - -def test_add_submodule_files(): - """Add some dummy data""" - for submodule in submodules: - os.chdir(submodule.dir) - _add_dummy_data(submodule.repo, "initial commit in submodule") - os.chdir(repodir) - assert True - - -def test_add_submodule(): - """Add a submodule""" - repo.add_submodule(submodules[0].dir) - repo.commit_all(msg='Added submodule %s' % submodules[0].dir) - -def test_has_submodules(): - """Check for submodules""" - assert repo.has_submodules() - - -def test_get_submodules(): - """Check for submodules list of (name, hash)""" - modules = repo.get_submodules("master")[0] - assert modules[0] == './test_submodule' - assert len(modules[1]) == 40 - - -def test_dump_tree(): - """Dump the repository and check if files exist""" - dumpdir = os.path.join(tmpdir, "dump") - os.mkdir(dumpdir) - assert buildpackage.dump_tree(repo, dumpdir, "master", True) - assert os.path.exists(os.path.join(dumpdir, testfile_name)) - assert os.path.exists(os.path.join(dumpdir, submodules[0].name, testfile_name)) - - -def test_create_tarball(): - """Create an upstream tarball""" - cp = { "Source": "test", "Upstream-Version": "0.1" } - assert buildpackage.git_archive(repo, - cp, - tmpdir, - "HEAD", - "bzip2", - "9", - True) - -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:*') - files = t.getmembers() - assert "test-0.1/.gitmodules" in [ f.name for f in files ] - assert len(files) == 6 - -def test_add_whitespace_submodule(): - """Add a second submodule with name containing whitespace""" - repo.add_submodule(submodules[1].dir) - repo.commit_all(msg='Added submodule %s' % submodules[0].dir) - -def test_get_more_submodules(): - """Check for submodules list of (name, hash)""" - module = repo.get_submodules("master") - assert(len(module) == len(submodule_names)) - for module in repo.get_submodules("master"): - assert len(module[1]) == 40 - assert os.path.basename(module[0]) in submodule_names - - -# vim:et:ts=4:sw=4:et:sts=4:ai:set list listchars=tab\:»·,trail\:·: diff --git a/tests/04_test_submodules.py b/tests/04_test_submodules.py new file mode 100644 index 00000000..5ae1f5fa --- /dev/null +++ b/tests/04_test_submodules.py @@ -0,0 +1,139 @@ +# vim: set fileencoding=utf-8 : + +"""Test submodule L{GitRepository} submodule methods""" + +import os +import shutil +import tarfile +import tempfile + +import gbp.log +import gbp.git +import gbp.command_wrappers + +from gbp.scripts import buildpackage + +top = None +repo = None +repodir = None + +submodules = [] +submodule_names = ["test_submodule", "sub module"] +tmpdir = None +testfile_name = "testfile" + +class Submodule(object): + def __init__(self, name, tmpdir): + self.name = name + self.dir = os.path.join(tmpdir, name) + self.repo = gbp.git.GitRepository.create(self.dir) + + +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) + + repodir = os.path.join(tmpdir, 'test_repo') + repo = gbp.git.GitRepository.create(repodir) + + for name in submodule_names: + submodules.append(Submodule(name, tmpdir)) + + os.chdir(repodir) + + +def teardown(): + os.chdir(top) + if not os.getenv("GBP_TESTS_NOCLEAN") and tmpdir: + shutil.rmtree(tmpdir) + + +def test_empty_has_submodules(): + """Test empty repo for submodules""" + assert not repo.has_submodules() + + +def _add_dummy_data(repo, msg): + shutil.copy(".git/HEAD", testfile_name) + repo.add_files('.', force=True) + repo.commit_all(msg) + + +def test_add_files(): + """Add some dummy data""" + _add_dummy_data(repo, "initial commit") + assert True + + +def test_add_submodule_files(): + """Add some dummy data""" + for submodule in submodules: + os.chdir(submodule.dir) + _add_dummy_data(submodule.repo, "initial commit in submodule") + os.chdir(repodir) + assert True + + +def test_add_submodule(): + """Add a submodule""" + repo.add_submodule(submodules[0].dir) + repo.commit_all(msg='Added submodule %s' % submodules[0].dir) + +def test_has_submodules(): + """Check for submodules""" + assert repo.has_submodules() + + +def test_get_submodules(): + """Check for submodules list of (name, hash)""" + modules = repo.get_submodules("master")[0] + assert modules[0] == './test_submodule' + assert len(modules[1]) == 40 + + +def test_dump_tree(): + """Dump the repository and check if files exist""" + dumpdir = os.path.join(tmpdir, "dump") + os.mkdir(dumpdir) + assert buildpackage.dump_tree(repo, dumpdir, "master", True) + assert os.path.exists(os.path.join(dumpdir, testfile_name)) + assert os.path.exists(os.path.join(dumpdir, submodules[0].name, testfile_name)) + + +def test_create_tarball(): + """Create an upstream tarball""" + cp = { "Source": "test", "Upstream-Version": "0.1" } + assert buildpackage.git_archive(repo, + cp, + tmpdir, + "HEAD", + "bzip2", + "9", + True) + +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:*') + files = t.getmembers() + assert "test-0.1/.gitmodules" in [ f.name for f in files ] + assert len(files) == 6 + +def test_add_whitespace_submodule(): + """Add a second submodule with name containing whitespace""" + repo.add_submodule(submodules[1].dir) + repo.commit_all(msg='Added submodule %s' % submodules[0].dir) + +def test_get_more_submodules(): + """Check for submodules list of (name, hash)""" + module = repo.get_submodules("master") + assert(len(module) == len(submodule_names)) + for module in repo.get_submodules("master"): + assert len(module[1]) == 40 + assert os.path.basename(module[0]) in submodule_names + + +# vim:et:ts=4:sw=4:et:sts=4:ai:set list listchars=tab\:»·,trail\:·: diff --git a/tests/05_test_detection.py b/tests/05_test_detection.py index 2f58265c..d866d7d2 100644 --- a/tests/05_test_detection.py +++ b/tests/05_test_detection.py @@ -1,3 +1,7 @@ +# vim: set fileencoding=utf-8 : + +"""Test tarball compression type detection""" + import os import shutil import tempfile diff --git a/tests/06_test_upstream_source.py b/tests/06_test_upstream_source.py index e414fa43..96402f4e 100644 --- a/tests/06_test_upstream_source.py +++ b/tests/06_test_upstream_source.py @@ -1,4 +1,6 @@ -# Test the UpstreamSource class +# vim: set fileencoding=utf-8 : + +"""Test the L{UpstreamSource} class""" import glob import os @@ -20,6 +22,7 @@ class TestDir(unittest.TestCase): class TestTar(unittest.TestCase): + """Test if packing tar archives works""" def _check_tar(self, us, positive=[], negative=[]): t = tarfile.open(name=us.path, mode="r:bz2") for f in positive: @@ -64,6 +67,7 @@ class TestTar(unittest.TestCase): class TestZip(unittest.TestCase): + """Test if unpacking zip archives works""" def setUp(self): self.tmpdir = tempfile.mkdtemp(prefix='gbp_%s_' % __name__, dir='.') self.zipfile = os.path.join(self.tmpdir, "gbp-0.1.zip") diff --git a/tests/07_test_fastimport.py b/tests/07_test_fastimport.py index cfb560f8..7e38bf25 100644 --- a/tests/07_test_fastimport.py +++ b/tests/07_test_fastimport.py @@ -1,5 +1,7 @@ # vim: set fileencoding=utf-8 : +"""Test L{FastImport} class""" + import os import shutil import tarfile diff --git a/tests/08_test_patch.py b/tests/08_test_patch.py index 8735b16c..92a6739f 100644 --- a/tests/08_test_patch.py +++ b/tests/08_test_patch.py @@ -1,3 +1,7 @@ +# vim: set fileencoding=utf-8 : + +"""Test L{Patch} class""" + import os import unittest -- cgit v1.2.3