13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
17
"""Tests for repository statistic-gathering apis."""
19
from bzrlib.tests.repository_implementations.test_repository import TestCaseWithRepository
19
from bzrlib.tests.per_repository import TestCaseWithRepository
22
22
class TestGatherStats(TestCaseWithRepository):
24
def check_stats_has_size(self, stats):
25
"""Check that stats has a reasonable size entry."""
26
# actual disk size varies from implementation to implementation,
27
# but they should all provide it on their native transport.
28
self.assertTrue('size' in stats)
29
# and it should be a number
30
self.assertIsInstance(stats['size'], (int, long))
31
# and now remove it to make other assertions work without variation.
34
24
def test_gather_stats(self):
35
25
"""First smoke test covering the refactoring into the Repository api."""
36
26
tree = self.make_branch_and_memory_tree('.')
39
# three commits: one to be included by reference, one to be
29
# three commits: one to be included by reference, one to be
40
30
# requested, and one to be in the repository but [mostly] ignored.
41
31
rev1 = tree.commit('first post', committer='person 1',
42
32
timestamp=1170491381, timezone=0)
45
35
rev3 = tree.commit('third post', committer='person 3',
46
36
timestamp=1172491381, timezone=0)
48
# now, in the same repository, asking for stats with/without the
38
# now, in the same repository, asking for stats with/without the
49
39
# committers flag generates the same date information.
50
40
stats = tree.branch.repository.gather_stats(rev2, committers=False)
51
self.check_stats_has_size(stats)
53
42
'firstrev': (1170491381.0, 0),
54
43
'latestrev': (1171491381.0, 0),
58
47
stats = tree.branch.repository.gather_stats(rev2, committers=True)
59
self.check_stats_has_size(stats)
62
50
'firstrev': (1170491381.0, 0),
68
def test_gather_stats_norevid_gets_size(self):
69
"""Without a revid, repository size is still gathered."""
70
tree = self.make_branch_and_memory_tree('.')
73
# put something in the repository, because zero-size is borink.
74
rev1 = tree.commit('first post')
76
# now ask for global repository stats.
77
stats = tree.branch.repository.gather_stats()
78
self.check_stats_has_size(stats)
84
56
def test_gather_stats_empty_repo(self):
85
"""An empty repository still has size and revisions."""
57
"""An empty repository still has revisions."""
86
58
tree = self.make_branch_and_memory_tree('.')
87
59
# now ask for global repository stats.
88
60
stats = tree.branch.repository.gather_stats()
89
self.check_stats_has_size(stats)