31
32
for i in range(total_lines):
32
33
text += line_prefix + str(i+1) + "\n"
34
open(path, 'w').write(text)
35
with open(path, 'w') as f:
36
38
self.run_bzr(['add', path])
37
39
self.run_bzr(['ci', '-m', '"' + path + '"'])
39
41
def _update_file(self, path, text, checkin=True):
40
42
"""append text to file 'path' and check it in"""
41
open(path, 'a').write(text)
43
with open(path, 'a') as f:
43
47
self.run_bzr(['ci', path, '-m', '"' + path + '"'])
46
50
"""pack command has no intrinsic output."""
47
51
self.make_branch('.')
48
52
out, err = self.run_bzr('pack')
49
self.assertEqual('', out)
50
self.assertEqual('', err)
53
self.assertEqual(b'', out)
54
self.assertEqual(b'', err)
52
56
def test_pack_accepts_branch_url(self):
53
57
"""pack command accepts the url to a branch."""
54
58
self.make_branch('branch')
55
59
out, err = self.run_bzr('pack branch')
56
self.assertEqual('', out)
57
self.assertEqual('', err)
60
self.assertEqual(b'', out)
61
self.assertEqual(b'', err)
59
63
def test_pack_accepts_repo_url(self):
60
64
"""pack command accepts the url to a branch."""
61
65
self.make_repository('repository')
62
66
out, err = self.run_bzr('pack repository')
63
self.assertEqual('', out)
64
self.assertEqual('', err)
67
self.assertEqual(b'', out)
68
self.assertEqual(b'', err)
66
70
def test_pack_clean_obsolete_packs(self):
67
71
"""Ensure --clean-obsolete-packs removes obsolete pack files
70
wt = self.make_branch_and_tree(wd)
71
transport = wt.branch.repository.bzrdir.transport
73
wt = self.make_branch_and_tree('.')
74
t = wt.branch.repository.controldir.transport
74
76
# do multiple commits to ensure that obsolete packs are created
76
78
self._make_versioned_file('file0.txt')
78
80
self._update_file('file0.txt', 'HELLO %d\n' % i)
80
82
out, err = self.run_bzr(['pack', '--clean-obsolete-packs'])
82
pack_names = transport.list_dir('repository/obsolete_packs')
84
pack_names = t.list_dir('repository/obsolete_packs')
83
85
self.assertTrue(len(pack_names) == 0)
88
class TestSmartServerPack(tests.TestCaseWithTransport):
90
def test_simple_pack(self):
91
self.setup_smart_server_with_call_log()
92
t = self.make_branch_and_tree('branch')
93
self.build_tree_contents([('branch/foo', b'thecontents')])
96
self.reset_smart_call_log()
97
out, err = self.run_bzr(['pack', self.get_url('branch')])
98
# This figure represent the amount of HPSS calls to perform this use
99
# case. It is entirely ok to reduce this number if a test fails due to
100
# rpc_count # being too low. If rpc_count increases, more network
101
# roundtrips have become necessary for this use case. Please do not
102
# adjust this number upwards without agreement from bzr's network
103
# support maintainers.
104
self.assertLength(6, self.hpss_calls)
105
self.assertLength(1, self.hpss_connections)
106
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)