1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
# vim: set fileencoding=utf-8 :
"""Test submodule L{GitRepository} submodule methods"""
import os
import shutil
import tarfile
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_tarballs():
"""Create an upstream tarball"""
# Tarball with submodules
cp = { "Source": "test", "Upstream-Version": "0.1" }
assert buildpackage.git_archive(repo, cp, tmpdir, "/tmp/", "HEAD", "bzip2",
"9", True)
# Tarball without submodules
cp["Upstream-Version"] = "0.2"
assert buildpackage.git_archive(repo, cp, tmpdir, "/tmp/", "HEAD", "bzip2",
"9", False)
def test_check_tarfiles():
"""Check the contents of the created tarfile"""
# Check tarball with submodules
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
# Check tarball without submodules
t = tarfile.open(os.path.join(tmpdir,"test_0.2.orig.tar.bz2"), 'r:*')
files = t.getmembers()
assert ("test-0.2/%s" % testfile_name) in [ f.name for f in files ]
assert len(files) == 4
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\:·:
|