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 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
|
# test_config.py -- Tests for builddeb's config.py
# Copyright (C) 2007 James Westby <jw+debian@jameswestby.net>
#
# This file is part of bzr-builddeb.
#
# bzr-builddeb is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# bzr-builddeb is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with bzr-builddeb; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
from ....branch import Branch
from ..config import (
BUILD_TYPE_MERGE,
DebBuildConfig,
)
from . import TestCaseWithTransport
class DebBuildConfigTests(TestCaseWithTransport):
def setUp(self):
super().setUp()
self.tree = self.make_branch_and_tree(".")
self.branch = self.tree.branch
with open("default.conf", "w") as f:
f.write("[" + DebBuildConfig.section + "]\n")
# shouldn't be read as it needs to be trusted
f.write("builder = invalid builder\n")
f.write("build-dir = default build dir\n")
f.write("orig-dir = default orig dir\n")
f.write("result-dir = default result dir\n")
with open("user.conf", "w") as f:
f.write("[" + DebBuildConfig.section + "]\n")
f.write("builder = valid builder\n")
f.write("quick-builder = valid quick builder\n")
f.write("orig-dir = user orig dir\n")
f.write("result-dir = user result dir\n")
with open(".bzr/branch/branch.conf", "w") as f:
f.write("[" + DebBuildConfig.section + "]\n")
f.write("quick-builder = invalid quick builder\n")
f.write("result-dir = branch result dir\n")
self.tree.add(["default.conf", "user.conf"])
self.config = DebBuildConfig(
[("user.conf", True), ("default.conf", False)], branch=self.branch
)
def test_secure_not_from_untrusted(self):
self.assertEqual(self.config.builder, "valid builder")
def test_secure_not_from_branch(self):
self.assertEqual(self.config.quick_builder, "valid quick builder")
def test_branch_over_all(self):
self.assertEqual(self.config.result_dir, "branch result dir")
def test_hierarchy(self):
self.assertEqual(self.config.orig_dir, "user orig dir")
self.assertEqual(self.config.build_dir, "default build dir")
def test_no_entry(self):
self.assertEqual(self.config.merge, False)
self.assertEqual(self.config.build_type, None)
def test_parse_error(self):
with open("invalid.conf", "w") as f:
f.write("[" + DebBuildConfig.section + "\n")
DebBuildConfig([("invalid.conf", True, "invalid.conf")])
def test_upstream_metadata(self):
cfg = DebBuildConfig([], tree=self.branch.basis_tree())
self.assertIs(None, cfg.upstream_branch)
self.build_tree_contents(
[
("debian/",),
("debian/upstream/",),
(
"debian/upstream/metadata",
b"Name: example\n"
b"Repository: http://example.com/foo\n"
b"Repository-Tag-Prefix: exampl-\n",
),
]
)
self.tree.add(["debian", "debian/upstream", "debian/upstream/metadata"])
cfg = DebBuildConfig([], tree=self.tree)
self.assertEqual("http://example.com/foo", cfg.upstream_branch)
self.assertEqual("tag:exampl-$UPSTREAM_VERSION", cfg.export_upstream_revision)
def test_upstream_metadata_multidoc(self):
cfg = DebBuildConfig([], tree=self.branch.basis_tree())
self.assertIs(None, cfg.upstream_branch)
self.build_tree_contents(
[
("debian/",),
("debian/upstream/",),
(
"debian/upstream/metadata",
b"---\n"
b"---\n"
b"Name: example\n"
b"Repository: http://example.com/foo\n"
b"Repository-Tag-Prefix: exampl-\n",
),
]
)
self.tree.add(["debian", "debian/upstream", "debian/upstream/metadata"])
cfg = DebBuildConfig([], tree=self.tree)
self.assertEqual("http://example.com/foo", cfg.upstream_branch)
self.assertEqual("tag:exampl-$UPSTREAM_VERSION", cfg.export_upstream_revision)
def test_invalid_upstream_metadata(self):
cfg = DebBuildConfig([], tree=self.branch.basis_tree())
self.assertIs(None, cfg.upstream_branch)
self.build_tree_contents(
[
("debian/",),
("debian/upstream/",),
("debian/upstream/metadata", b"debian/changelog.blah"),
]
)
self.tree.add(["debian", "debian/upstream", "debian/upstream/metadata"])
# We just ignore the upstream metadata file in this case
config = DebBuildConfig([], tree=self.tree)
self.assertEqual([], config._config_files)
try:
from ...svn.config import SubversionBuildPackageConfig # noqa: F401
except ImportError:
pass
else:
from ...svn.tests import SubversionTestCase
class DebuildSvnBpTests(SubversionTestCase):
if not getattr(SubversionTestCase, "make_svn_branch", None):
def make_svn_branch(self, relpath):
repos_url = self.make_repository(relpath)
return Branch.open(repos_url)
def test_from_properties(self):
branch = self.make_svn_branch("d")
cfg = DebBuildConfig([], tree=branch.basis_tree())
self.assertEqual(False, cfg.merge)
dc = self.get_commit_editor(branch.base)
d = dc.add_dir("debian")
d.change_prop("mergeWithUpstream", "1")
d.change_prop("svn-bp:origDir", "someorigdir")
dc.close()
cfg = DebBuildConfig([], tree=branch.basis_tree())
self.assertEqual(True, cfg.merge)
self.assertEqual(BUILD_TYPE_MERGE, cfg.build_type)
self.assertEqual("someorigdir", cfg.orig_dir)
def test_from_svn_layout_file(self):
branch = self.make_svn_branch("d")
cfg = DebBuildConfig([], tree=branch.basis_tree())
self.assertEqual(False, cfg.merge)
with self.get_commit_editor(branch.base) as dc:
d = dc.add_dir("debian")
f = d.add_file("debian/svn-layout")
f.modify(b"origDir = someorigdir\n")
cfg = DebBuildConfig([], tree=branch.basis_tree())
self.assertEqual("someorigdir", cfg.orig_dir)
|