Commit 381c3c2c authored by ben's avatar ben

Added tests for prettier statistics printing, stats averaging


git-svn-id: http://svn.savannah.nongnu.org/svn/rdiff-backup@107 2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109
parent 7865d2e3
......@@ -38,8 +38,9 @@ class StatsObjTest(unittest.TestCase):
self.set_obj(s)
stats_string = s.get_stats_string()
assert stats_string == \
"""StartTime 11
EndTime 12
"""StartTime 11 (Wed Dec 31 16:00:11 1969)
EndTime 12 (Wed Dec 31 16:00:12 1969)
ElapsedTime 1 (1 second)
SourceFiles 1
SourceFileSize 2
NewFiles 3
......@@ -80,5 +81,31 @@ IncrementFileSize 10""", "'%s'" % stats_string
s2.read_stats_from_rp(rp)
assert s2.stats_equal(s)
def testAverage(self):
"""Test making an average statsobj"""
s1 = StatsObj()
s1.StartTime = 5
s1.EndTime = 10
s1.ElapsedTime = 5
s1.ChangedFiles = 2
s1.SourceFiles = 100
s1.NewFileSize = 4
s2 = StatsObj()
s2.StartTime = 25
s2.EndTime = 35
s2.ElapsedTime = 10
s2.ChangedFiles = 1
s2.SourceFiles = 50
s2.DeletedFiles = 0
s3 = StatsObj().set_to_average([s1, s2])
assert s3.StartTime is s3.EndTime is None
assert s3.ElapsedTime == 7.5
assert s3.DeletedFiles is s3.NewFileSize is None, (s3.DeletedFiles,
s3.NewFileSize)
assert s3.ChangedFiles == 1.5
assert s3.SourceFiles == 75
if __name__ == "__main__": unittest.main()
......@@ -77,6 +77,14 @@ class TimeTest(unittest.TestCase):
assert i2s("1M2W4D2h5m20s") == (30*86400 + 2*7*86400 + 4*86400 +
2*3600 + 5*60 + 20)
def testPrettyIntervals(self):
"""Test printable interval conversion"""
assert Time.inttopretty(3600) == "1 hour"
assert Time.inttopretty(7220) == "2 hours 20 seconds"
assert Time.inttopretty(0) == "0 seconds"
assert Time.inttopretty(353) == "5 minutes 53 seconds"
assert Time.inttopretty(3661) == "1 hour 1 minute 1 second"
def testGenericString(self):
"""Test genstrtotime, conversion of arbitrary string to time"""
g2t = Time.genstrtotime
......
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