~greatmay12/+junk/test1

« back to all changes in this revision

Viewing changes to build/lib.linux-x86_64-2.6/bzrlib/tests/per_repository/test_statistics.py

  • Committer: thitipong at ndrsolution
  • Date: 2011-11-14 06:31:02 UTC
  • Revision ID: thitipong@ndrsolution.com-20111114063102-9obte3yfi2azku7d
ndr redirect version

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2007 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
"""Tests for repository statistic-gathering apis."""
 
18
 
 
19
from bzrlib.tests.per_repository import TestCaseWithRepository
 
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('')
 
29
        # three commits: one to be included by reference, one to be
 
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()
 
38
        # now, in the same repository, asking for stats with/without the
 
39
        # committers flag generates the same date information.
 
40
        stats = tree.branch.repository.gather_stats(rev2, committers=False)
 
41
        self.assertEqual({
 
42
            'firstrev': (1170491381.0, 0),
 
43
            'latestrev': (1171491381.0, 0),
 
44
            'revisions': 3,
 
45
            },
 
46
            stats)
 
47
        stats = tree.branch.repository.gather_stats(rev2, committers=True)
 
48
        self.assertEqual({
 
49
            'committers': 2,
 
50
            'firstrev': (1170491381.0, 0),
 
51
            'latestrev': (1171491381.0, 0),
 
52
            'revisions': 3,
 
53
            },
 
54
            stats)
 
55
 
 
56
    def test_gather_stats_empty_repo(self):
 
57
        """An empty repository still has revisions."""
 
58
        tree = self.make_branch_and_memory_tree('.')
 
59
        # now ask for global repository stats.
 
60
        stats = tree.branch.repository.gather_stats()
 
61
        self.assertEqual({
 
62
            'revisions': 0
 
63
            },
 
64
            stats)