/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_pack.py

(jelmer) Convert bzrlib.smtp_connection to use config stacks. (Jelmer
 Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2007, 2009, 2010 Canonical Ltd
 
2
#
 
3
# This program is free software; you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation; either version 2 of the License, or
 
6
# (at your option) any later version.
 
7
#
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program; if not, write to the Free Software
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
16
#
 
17
 
 
18
"""Tests of the 'bzr pack' command."""
 
19
import os
 
20
 
 
21
from bzrlib import tests
 
22
from bzrlib.tests.matchers import ContainsNoVfsCalls
 
23
 
 
24
 
 
25
class TestPack(tests.TestCaseWithTransport):
 
26
 
 
27
    def _make_versioned_file(self, path, line_prefix='line', total_lines=10):
 
28
        self._make_file(path, line_prefix, total_lines, versioned=True)
 
29
 
 
30
    def _make_file(self, path, line_prefix, total_lines, versioned):
 
31
        text=''
 
32
        for i in range(total_lines):
 
33
            text += line_prefix + str(i+1) + "\n"
 
34
 
 
35
        open(path, 'w').write(text)
 
36
        if versioned:
 
37
            self.run_bzr(['add', path])
 
38
            self.run_bzr(['ci', '-m', '"' + path + '"'])
 
39
 
 
40
    def _update_file(self, path, text, checkin=True):
 
41
        """append text to file 'path' and check it in"""
 
42
        with open(path, 'a') as f:
 
43
            f.write(text)
 
44
 
 
45
        if checkin:
 
46
            self.run_bzr(['ci', path, '-m', '"' + path + '"'])
 
47
 
 
48
    def test_pack_silent(self):
 
49
        """pack command has no intrinsic output."""
 
50
        self.make_branch('.')
 
51
        out, err = self.run_bzr('pack')
 
52
        self.assertEqual('', out)
 
53
        self.assertEqual('', err)
 
54
 
 
55
    def test_pack_accepts_branch_url(self):
 
56
        """pack command accepts the url to a branch."""
 
57
        self.make_branch('branch')
 
58
        out, err = self.run_bzr('pack branch')
 
59
        self.assertEqual('', out)
 
60
        self.assertEqual('', err)
 
61
 
 
62
    def test_pack_accepts_repo_url(self):
 
63
        """pack command accepts the url to a branch."""
 
64
        self.make_repository('repository')
 
65
        out, err = self.run_bzr('pack repository')
 
66
        self.assertEqual('', out)
 
67
        self.assertEqual('', err)
 
68
 
 
69
    def test_pack_clean_obsolete_packs(self):
 
70
        """Ensure --clean-obsolete-packs removes obsolete pack files
 
71
        """
 
72
        wd = 'foobar0'
 
73
        wt = self.make_branch_and_tree(wd)
 
74
        transport = wt.branch.repository.bzrdir.transport
 
75
        os.chdir(wd)
 
76
 
 
77
        # do multiple commits to ensure that obsolete packs are created
 
78
        # by 'bzr pack'
 
79
        self._make_versioned_file('file0.txt')
 
80
        for i in range(5):
 
81
            self._update_file('file0.txt', 'HELLO %d\n' % i)
 
82
 
 
83
        out, err = self.run_bzr(['pack', '--clean-obsolete-packs'])
 
84
 
 
85
        pack_names = transport.list_dir('repository/obsolete_packs')
 
86
        self.assertTrue(len(pack_names) == 0)
 
87
 
 
88
 
 
89
class TestSmartServerPack(tests.TestCaseWithTransport):
 
90
 
 
91
    def test_simple_pack(self):
 
92
        self.setup_smart_server_with_call_log()
 
93
        t = self.make_branch_and_tree('branch')
 
94
        self.build_tree_contents([('branch/foo', 'thecontents')])
 
95
        t.add("foo")
 
96
        t.commit("message")
 
97
        self.reset_smart_call_log()
 
98
        out, err = self.run_bzr(['pack', self.get_url('branch')])
 
99
        # This figure represent the amount of HPSS calls to perform this use
 
100
        # case. It is entirely ok to reduce this number if a test fails due to
 
101
        # rpc_count # being too low. If rpc_count increases, more network
 
102
        # roundtrips have become necessary for this use case. Please do not
 
103
        # adjust this number upwards without agreement from bzr's network
 
104
        # support maintainers.
 
105
        self.assertLength(6, self.hpss_calls)
 
106
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)