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
|
# Copyright (C) 2007, 2009, 2010 Canonical Ltd
#
# This program 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.
#
# This program 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 this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
"""Tests of the 'bzr pack' command."""
import os
from bzrlib import tests
from bzrlib.tests.matchers import ContainsNoVfsCalls
class TestPack(tests.TestCaseWithTransport):
def _make_versioned_file(self, path, line_prefix='line', total_lines=10):
self._make_file(path, line_prefix, total_lines, versioned=True)
def _make_file(self, path, line_prefix, total_lines, versioned):
text=''
for i in range(total_lines):
text += line_prefix + str(i+1) + "\n"
open(path, 'w').write(text)
if versioned:
self.run_bzr(['add', path])
self.run_bzr(['ci', '-m', '"' + path + '"'])
def _update_file(self, path, text, checkin=True):
"""append text to file 'path' and check it in"""
with open(path, 'a') as f:
f.write(text)
if checkin:
self.run_bzr(['ci', path, '-m', '"' + path + '"'])
def test_pack_silent(self):
"""pack command has no intrinsic output."""
self.make_branch('.')
out, err = self.run_bzr('pack')
self.assertEqual('', out)
self.assertEqual('', err)
def test_pack_accepts_branch_url(self):
"""pack command accepts the url to a branch."""
self.make_branch('branch')
out, err = self.run_bzr('pack branch')
self.assertEqual('', out)
self.assertEqual('', err)
def test_pack_accepts_repo_url(self):
"""pack command accepts the url to a branch."""
self.make_repository('repository')
out, err = self.run_bzr('pack repository')
self.assertEqual('', out)
self.assertEqual('', err)
def test_pack_clean_obsolete_packs(self):
"""Ensure --clean-obsolete-packs removes obsolete pack files
"""
wd = 'foobar0'
wt = self.make_branch_and_tree(wd)
transport = wt.branch.repository.bzrdir.transport
os.chdir(wd)
# do multiple commits to ensure that obsolete packs are created
# by 'bzr pack'
self._make_versioned_file('file0.txt')
for i in range(5):
self._update_file('file0.txt', 'HELLO %d\n' % i)
out, err = self.run_bzr(['pack', '--clean-obsolete-packs'])
pack_names = transport.list_dir('repository/obsolete_packs')
self.assertTrue(len(pack_names) == 0)
class TestSmartServerPack(tests.TestCaseWithTransport):
def test_simple_pack(self):
self.setup_smart_server_with_call_log()
t = self.make_branch_and_tree('branch')
self.build_tree_contents([('branch/foo', 'thecontents')])
t.add("foo")
t.commit("message")
self.reset_smart_call_log()
out, err = self.run_bzr(['pack', self.get_url('branch')])
# This figure represent the amount of HPSS calls to perform this use
# case. It is entirely ok to reduce this number if a test fails due to
# rpc_count # being too low. If rpc_count increases, more network
# roundtrips have become necessary for this use case. Please do not
# adjust this number upwards without agreement from bzr's network
# support maintainers.
self.assertLength(6, self.hpss_calls)
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
|