~bzr-pqm/bzr/bzr.dev

6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
1
# Copyright (C) 2007, 2008, 2009, 2011, 2016 Canonical Ltd
2258.1.1 by Robert Collins
Move info branch statistics gathering into the repository to allow smart server optimisation (Robert Collins).
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
2258.1.1 by Robert Collins
Move info branch statistics gathering into the repository to allow smart server optimisation (Robert Collins).
16
17
"""Tests for repository statistic-gathering apis."""
18
3689.1.1 by John Arbash Meinel
Rename repository_implementations tests into per_repository tests
19
from bzrlib.tests.per_repository import TestCaseWithRepository
2258.1.1 by Robert Collins
Move info branch statistics gathering into the repository to allow smart server optimisation (Robert Collins).
20
21
22
class TestGatherStats(TestCaseWithRepository):
23
24
    def test_gather_stats(self):
25
        """First smoke test covering the refactoring into the Repository api."""
26
        tree = self.make_branch_and_memory_tree('.')
27
        tree.lock_write()
28
        tree.add('')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
29
        # three commits: one to be included by reference, one to be
2258.1.1 by Robert Collins
Move info branch statistics gathering into the repository to allow smart server optimisation (Robert Collins).
30
        # requested, and one to be in the repository but [mostly] ignored.
31
        rev1 = tree.commit('first post', committer='person 1',
32
            timestamp=1170491381, timezone=0)
33
        rev2 = tree.commit('second post', committer='person 2',
34
            timestamp=1171491381, timezone=0)
35
        rev3 = tree.commit('third post', committer='person 3',
36
            timestamp=1172491381, timezone=0)
37
        tree.unlock()
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
38
        # now, in the same repository, asking for stats with/without the
2258.1.2 by Robert Collins
New version of gather_stats which gathers aggregate data too.
39
        # committers flag generates the same date information.
2258.1.1 by Robert Collins
Move info branch statistics gathering into the repository to allow smart server optimisation (Robert Collins).
40
        stats = tree.branch.repository.gather_stats(rev2, committers=False)
6127.1.8 by Jelmer Vernooij
Allow extra data in gather_stats().
41
        # this test explicitly only checks for certain keys
42
        # in the dictionary, as implementations are allowed to
43
        # provide arbitrary data in other keys.
44
        self.assertEqual(stats['firstrev'], (1170491381.0, 0))
45
        self.assertEqual(stats['latestrev'], (1171491381.0, 0))
46
        self.assertEqual(stats['revisions'], 3)
2258.1.1 by Robert Collins
Move info branch statistics gathering into the repository to allow smart server optimisation (Robert Collins).
47
        stats = tree.branch.repository.gather_stats(rev2, committers=True)
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
48
        self.assertEqual(2, stats["committers"])
49
        self.assertEqual((1170491381.0, 0), stats["firstrev"])
50
        self.assertEqual((1171491381.0, 0), stats["latestrev"])
51
        self.assertEqual(3, stats["revisions"])
2258.1.2 by Robert Collins
New version of gather_stats which gathers aggregate data too.
52
53
    def test_gather_stats_empty_repo(self):
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
54
        """An empty repository still has revisions."""
2258.1.2 by Robert Collins
New version of gather_stats which gathers aggregate data too.
55
        tree = self.make_branch_and_memory_tree('.')
56
        # now ask for global repository stats.
57
        stats = tree.branch.repository.gather_stats()
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
58
        self.assertEqual(0, stats['revisions'])
5751.1.1 by Jelmer Vernooij
Allow for extra statistics returned by Repository.gather_stats().
59
        self.assertFalse("committers" in stats)
60
        self.assertFalse("firstrev" in stats)
61
        self.assertFalse("latestrev" in stats)