~bzr-pqm/bzr/bzr.dev

6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
1
# Copyright (C) 2007, 2009-2012 Canonical Ltd
2604.2.1 by Robert Collins
(robertc) Introduce a pack command.
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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2604.2.1 by Robert Collins
(robertc) Introduce a pack command.
16
#
17
18
"""Tests of the 'bzr pack' command."""
5108.1.2 by Parth Malwankar
added test case for --create-obsolete-packs
19
import os
2604.2.1 by Robert Collins
(robertc) Introduce a pack command.
20
5184.1.1 by Vincent Ladeuil
Random cleanups to catch up with copyright updates in trunk.
21
from bzrlib import tests
6352.2.3 by Jelmer Vernooij
s/NoVfsCalls/ContainsNoVfsCalls/.
22
from bzrlib.tests.matchers import ContainsNoVfsCalls
5184.1.1 by Vincent Ladeuil
Random cleanups to catch up with copyright updates in trunk.
23
24
25
class TestPack(tests.TestCaseWithTransport):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
26
5108.1.2 by Parth Malwankar
added test case for --create-obsolete-packs
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
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
35
        with open(path, 'w') as f:
36
            f.write(text)
5108.1.2 by Parth Malwankar
added test case for --create-obsolete-packs
37
        if versioned:
38
            self.run_bzr(['add', path])
39
            self.run_bzr(['ci', '-m', '"' + path + '"'])
40
41
    def _update_file(self, path, text, checkin=True):
42
        """append text to file 'path' and check it in"""
5861.2.1 by Wouter van Heyst
Stop depending on CPython refcounting semantics to close files.
43
        with open(path, 'a') as f:
44
            f.write(text)
45
5108.1.2 by Parth Malwankar
added test case for --create-obsolete-packs
46
        if checkin:
47
            self.run_bzr(['ci', path, '-m', '"' + path + '"'])
48
2604.2.1 by Robert Collins
(robertc) Introduce a pack command.
49
    def test_pack_silent(self):
50
        """pack command has no intrinsic output."""
51
        self.make_branch('.')
52
        out, err = self.run_bzr('pack')
53
        self.assertEqual('', out)
54
        self.assertEqual('', err)
55
56
    def test_pack_accepts_branch_url(self):
57
        """pack command accepts the url to a branch."""
58
        self.make_branch('branch')
59
        out, err = self.run_bzr('pack branch')
60
        self.assertEqual('', out)
61
        self.assertEqual('', err)
62
63
    def test_pack_accepts_repo_url(self):
64
        """pack command accepts the url to a branch."""
65
        self.make_repository('repository')
66
        out, err = self.run_bzr('pack repository')
67
        self.assertEqual('', out)
68
        self.assertEqual('', err)
5108.1.2 by Parth Malwankar
added test case for --create-obsolete-packs
69
70
    def test_pack_clean_obsolete_packs(self):
71
        """Ensure --clean-obsolete-packs removes obsolete pack files
72
        """
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
73
        wt = self.make_branch_and_tree('.')
74
        t = wt.branch.repository.bzrdir.transport
5108.1.2 by Parth Malwankar
added test case for --create-obsolete-packs
75
76
        # do multiple commits to ensure that obsolete packs are created
77
        # by 'bzr pack'
78
        self._make_versioned_file('file0.txt')
79
        for i in range(5):
80
            self._update_file('file0.txt', 'HELLO %d\n' % i)
81
82
        out, err = self.run_bzr(['pack', '--clean-obsolete-packs'])
83
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
84
        pack_names = t.list_dir('repository/obsolete_packs')
5108.1.2 by Parth Malwankar
added test case for --create-obsolete-packs
85
        self.assertTrue(len(pack_names) == 0)
6305.2.5 by Jelmer Vernooij
Add hpss call count test.
86
87
88
class TestSmartServerPack(tests.TestCaseWithTransport):
89
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', 'thecontents')])
94
        t.add("foo")
95
        t.commit("message")
96
        self.reset_smart_call_log()
97
        out, err = self.run_bzr(['pack', self.get_url('branch')])
6305.2.6 by Jelmer Vernooij
Update comments, thanks mgz.
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.
6305.2.5 by Jelmer Vernooij
Add hpss call count test.
104
        self.assertLength(6, self.hpss_calls)
6366.1.4 by Jelmer Vernooij
Test connection count calls for most blackbox commands.
105
        self.assertLength(1, self.hpss_connections)
6352.2.3 by Jelmer Vernooij
s/NoVfsCalls/ContainsNoVfsCalls/.
106
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)