Commit ddc7e439 authored by ben's avatar ben

Updated test set for use with new more complicated statistics


git-svn-id: http://svn.savannah.nongnu.org/svn/rdiff-backup@105 2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109
parent 097e2c75
......@@ -182,54 +182,32 @@ class inctest2(unittest.TestCase):
incs = Restore.get_inclist(inc_base.append("subdir").
append("directory_statistics"))
assert len(incs) == 1
subdir_stats = self.parse_statistics(incs[0])
assert subdir_stats.total_files == 2, subdir_stats.total_files
assert 350000 < subdir_stats.total_file_size < 450000, \
subdir_stats.total_file_size
assert subdir_stats.changed_files == 2, subdir_stats.changed_files
assert 350000 < subdir_stats.changed_file_size < 450000, \
subdir_stats.changed_file_size
assert 10 < subdir_stats.increment_file_size < 20000, \
subdir_stats.increment_file_size
subdir_stats = StatsObj().read_stats_from_rp(incs[0])
assert subdir_stats.SourceFiles == 2
assert 400000 < subdir_stats.SourceFileSize < 420000
assert subdir_stats.MirrorFiles == 2
assert 400000 < subdir_stats.MirrorFileSize < 420000
assert subdir_stats.NewFiles == subdir_stats.NewFileSize == 0
assert subdir_stats.DeletedFiles == subdir_stats.DeletedFileSize == 0
assert subdir_stats.ChangedFiles == 2
assert 400000 < subdir_stats.ChangedSourceSize < 420000
assert 400000 < subdir_stats.ChangedMirrorSize < 420000
assert 10 < subdir_stats.IncrementFileSize < 20000
incs = Restore.get_inclist(inc_base.append("directory_statistics"))
assert len(incs) == 1
root_stats = self.parse_statistics(incs[0])
assert root_stats.total_files == 6, root_stats.total_files
assert 650000 < root_stats.total_file_size < 750000, \
root_stats.total_file_size
assert root_stats.changed_files == 4, root_stats.changed_files
assert 550000 < root_stats.changed_file_size < 650000, \
root_stats.changed_file_size
assert 10 < root_stats.increment_file_size < 20000, \
root_stats.increment_file_size
def parse_statistics(self, statrp):
"""Return StatObj from given statrp"""
assert statrp.isincfile() and statrp.getinctype() == "data"
s = StatObj()
fp = statrp.open("r")
for line in fp:
lsplit = line.split()
assert len(lsplit) == 2
field, num = lsplit[0], long(lsplit[1])
if field == "TotalFiles": s.total_files = num
elif field == "TotalFileSize": s.total_file_size = num
elif field == "ChangedFiles": s.changed_files = num
elif field == "ChangedFileSize": s.changed_file_size = num
elif field == "IncrementFileSize": s.increment_file_size = num
else: assert None, "Unrecognized field %s" % (field,)
assert not fp.close()
return s
class StatObj:
"""Just hold various statistics"""
total_files = 0
total_file_size = 0
changed_files = 0
changed_file_size = 0
increment_file_size = 0
root_stats = StatsObj().read_stats_from_rp(incs[0])
assert root_stats.SourceFiles == 7
assert 550000 < root_stats.SourceFileSize < 570000
assert root_stats.MirrorFiles == 7
assert 700000 < root_stats.MirrorFileSize < 750000
assert root_stats.NewFiles == 1
assert root_stats.NewFileSize == 0
assert root_stats.DeletedFiles == 1
assert root_stats.DeletedFileSize == 200000
assert 3 <= root_stats.ChangedFiles <= 4, root_stats.ChangedFiles
assert 450000 < root_stats.ChangedSourceSize < 470000
assert 400000 < root_stats.ChangedMirrorSize < 420000
assert 10 < subdir_stats.IncrementtFileSize < 30000
if __name__ == '__main__': unittest.main()
import unittest
execfile("commontest.py")
rbexec("statistics.py")
class StatsObjTest(unittest.TestCase):
"""Test StatsObj class"""
def set_obj(self, s):
"""Set values of s's statistics"""
s.SourceFiles = 1
s.SourceFileSize = 2
s.NewFiles = 3
s.NewFileSize = 4
s.DeletedFiles = 5
s.DeletedFileSize = 6
s.ChangedFiles = 7
s.ChangedSourceSize = 8
s.ChangedMirrorSize = 9
s.IncrementFileSize = 10
s.StartTime = 11
s.EndTime = 12
def test_get_stats(self):
"""Test reading and writing stat objects"""
s = StatsObj()
assert s.get_stat('SourceFiles') is None
self.set_obj(s)
assert s.get_stat('SourceFiles') == 1
s1 = StatsITR()
assert s1.get_stat('SourceFiles') == 0
def test_get_stats_string(self):
"""Test conversion of stat object into string"""
s = StatsObj()
stats_string = s.get_stats_string()
assert stats_string == "", stats_string
self.set_obj(s)
stats_string = s.get_stats_string()
assert stats_string == \
"""StartTime 11
EndTime 12
SourceFiles 1
SourceFileSize 2
NewFiles 3
NewFileSize 4
DeletedFiles 5
DeletedFileSize 6
ChangedFiles 7
ChangedSourceSize 8
ChangedMirrorSize 9
IncrementFileSize 10""", "'%s'" % stats_string
def test_init_stats(self):
"""Test setting stat object from string"""
s = StatsObj()
s.init_stats_from_string("NewFiles 3 hello there")
for attr in s.stat_attrs:
if attr == 'NewFiles': assert s.get_stat(attr) == 3
else: assert s.get_stat(attr) is None, (attr, s.__dict__[attr])
s1 = StatsObj()
self.set_obj(s1)
assert not s1.stats_equal(s)
s2 = StatsObj()
s2.init_stats_from_string(s1.get_stats_string())
assert s1.stats_equal(s2)
def test_write_rp(self):
"""Test reading and writing of statistics object"""
rp = RPath(Globals.local_connection, "testfiles/statstest")
if rp.lstat(): rp.delete()
s = StatsObj()
self.set_obj(s)
s.write_stats_to_rp(rp)
s2 = StatsObj()
assert not s2.stats_equal(s)
s2.read_stats_from_rp(rp)
assert s2.stats_equal(s)
if __name__ == "__main__": unittest.main()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment