Commit 35fae838 authored by ben's avatar ben

Reexamined robust writing and statistics, passes test


git-svn-id: http://svn.savannah.nongnu.org/svn/rdiff-backup@111 2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109
parent 8c88d03d
...@@ -149,8 +149,9 @@ class PathSetter(unittest.TestCase): ...@@ -149,8 +149,9 @@ class PathSetter(unittest.TestCase):
# Make sure too many increment files not created # Make sure too many increment files not created
assert len(self.getinc_paths("nochange.", assert len(self.getinc_paths("nochange.",
"testfiles/output/rdiff-backup-data/increments")) == 0 "testfiles/output/rdiff-backup-data/increments")) == 0
assert len(self.getinc_paths("", nochange_incs = len(self.getinc_paths("",
"testfiles/output/rdiff-backup-data/increments/nochange")) == 1 "testfiles/output/rdiff-backup-data/increments/nochange"))
assert nochange_incs == 1 or nochange_incs == 0, nochange_incs
def getinc_paths(self, basename, directory): def getinc_paths(self, basename, directory):
"""Return increment.______.dir paths""" """Return increment.______.dir paths"""
......
...@@ -8,7 +8,7 @@ class RemoteMirrorTest(unittest.TestCase): ...@@ -8,7 +8,7 @@ class RemoteMirrorTest(unittest.TestCase):
"""Test mirroring""" """Test mirroring"""
def setUp(self): def setUp(self):
"""Start server""" """Start server"""
Log.setverbosity(7) Log.setverbosity(5)
Globals.change_source_perms = 1 Globals.change_source_perms = 1
SetConnections.UpdateGlobal('checkpoint_interval', 3) SetConnections.UpdateGlobal('checkpoint_interval', 3)
......
...@@ -6,7 +6,7 @@ rbexec("main.py") ...@@ -6,7 +6,7 @@ rbexec("main.py")
lc = Globals.local_connection lc = Globals.local_connection
Globals.change_source_perms = 1 Globals.change_source_perms = 1
Log.setverbosity(4) Log.setverbosity(5)
def getrp(ending): def getrp(ending):
return RPath(lc, "testfiles/various_file_types/" + ending) return RPath(lc, "testfiles/various_file_types/" + ending)
...@@ -191,32 +191,33 @@ class inctest2(unittest.TestCase): ...@@ -191,32 +191,33 @@ class inctest2(unittest.TestCase):
Globals.compression = 1 Globals.compression = 1
Myrm("testfiles/output") Myrm("testfiles/output")
InternalBackup(1, 1, "testfiles/stattest1", "testfiles/output") InternalBackup(1, 1, "testfiles/stattest1", "testfiles/output")
InternalBackup(1, 1, "testfiles/stattest2", "testfiles/output") InternalBackup(1, 1, "testfiles/stattest2", "testfiles/output",
time.time()+1)
inc_base = RPath(Globals.local_connection,
"testfiles/output/rdiff-backup-data/increments") rbdir = RPath(Globals.local_connection,
"testfiles/output/rdiff-backup-data")
incs = Restore.get_inclist(inc_base.append("subdir").
append("directory_statistics")) #incs = Restore.get_inclist(rbdir.append("subdir").
assert len(incs) == 2 # append("directory_statistics"))
s1 = StatsObj().read_stats_from_rp(incs[0]) # initial mirror stats #assert len(incs) == 2
assert s1.SourceFiles == 2 #s1 = StatsObj().read_stats_from_rp(incs[0]) # initial mirror stats
assert 400000 < s1.SourceFileSize < 420000 #assert s1.SourceFiles == 2
self.stats_check_initial(s1) #assert 400000 < s1.SourceFileSize < 420000
#self.stats_check_initial(s1)
subdir_stats = StatsObj().read_stats_from_rp(incs[1]) # increment stats
assert subdir_stats.SourceFiles == 2 #subdir_stats = StatsObj().read_stats_from_rp(incs[1]) # increment stats
assert 400000 < subdir_stats.SourceFileSize < 420000 #assert subdir_stats.SourceFiles == 2
assert subdir_stats.MirrorFiles == 2 #assert 400000 < subdir_stats.SourceFileSize < 420000
assert 400000 < subdir_stats.MirrorFileSize < 420000 #assert subdir_stats.MirrorFiles == 2
assert subdir_stats.NewFiles == subdir_stats.NewFileSize == 0 #assert 400000 < subdir_stats.MirrorFileSize < 420000
assert subdir_stats.DeletedFiles == subdir_stats.DeletedFileSize == 0 #assert subdir_stats.NewFiles == subdir_stats.NewFileSize == 0
assert subdir_stats.ChangedFiles == 2 #assert subdir_stats.DeletedFiles == subdir_stats.DeletedFileSize == 0
assert 400000 < subdir_stats.ChangedSourceSize < 420000 #assert subdir_stats.ChangedFiles == 2
assert 400000 < subdir_stats.ChangedMirrorSize < 420000 #assert 400000 < subdir_stats.ChangedSourceSize < 420000
assert 10 < subdir_stats.IncrementFileSize < 20000 #assert 400000 < subdir_stats.ChangedMirrorSize < 420000
#assert 10 < subdir_stats.IncrementFileSize < 20000
incs = Restore.get_inclist(inc_base.append("directory_statistics"))
incs = Restore.get_inclist(rbdir.append("session_statistics"))
assert len(incs) == 2 assert len(incs) == 2
s2 = StatsObj().read_stats_from_rp(incs[0]) s2 = StatsObj().read_stats_from_rp(incs[0])
assert s2.SourceFiles == 7 assert s2.SourceFiles == 7
...@@ -224,7 +225,7 @@ class inctest2(unittest.TestCase): ...@@ -224,7 +225,7 @@ class inctest2(unittest.TestCase):
self.stats_check_initial(s2) self.stats_check_initial(s2)
root_stats = StatsObj().read_stats_from_rp(incs[1]) root_stats = StatsObj().read_stats_from_rp(incs[1])
assert root_stats.SourceFiles == 7 assert root_stats.SourceFiles == 7, root_stats.SourceFiles
assert 550000 < root_stats.SourceFileSize < 570000 assert 550000 < root_stats.SourceFileSize < 570000
assert root_stats.MirrorFiles == 7 assert root_stats.MirrorFiles == 7
assert 700000 < root_stats.MirrorFileSize < 750000 assert 700000 < root_stats.MirrorFileSize < 750000
...@@ -235,6 +236,6 @@ class inctest2(unittest.TestCase): ...@@ -235,6 +236,6 @@ class inctest2(unittest.TestCase):
assert 3 <= root_stats.ChangedFiles <= 4, root_stats.ChangedFiles assert 3 <= root_stats.ChangedFiles <= 4, root_stats.ChangedFiles
assert 450000 < root_stats.ChangedSourceSize < 470000 assert 450000 < root_stats.ChangedSourceSize < 470000
assert 400000 < root_stats.ChangedMirrorSize < 420000 assert 400000 < root_stats.ChangedMirrorSize < 420000
assert 10 < subdir_stats.IncrementFileSize < 30000 assert 10 < root_stats.IncrementFileSize < 30000
if __name__ == '__main__': unittest.main() if __name__ == '__main__': unittest.main()
...@@ -13,7 +13,7 @@ testfiles ...@@ -13,7 +13,7 @@ testfiles
Globals.set('change_source_perms', 1) Globals.set('change_source_perms', 1)
Globals.counter = 0 Globals.counter = 0
Log.setverbosity(7) Log.setverbosity(3)
class Local: class Local:
"""This is just a place to put increments relative to the local """This is just a place to put increments relative to the local
......
...@@ -8,6 +8,8 @@ class StatsObjTest(unittest.TestCase): ...@@ -8,6 +8,8 @@ class StatsObjTest(unittest.TestCase):
"""Set values of s's statistics""" """Set values of s's statistics"""
s.SourceFiles = 1 s.SourceFiles = 1
s.SourceFileSize = 2 s.SourceFileSize = 2
s.MirrorFiles = 13
s.MirrorFileSize = 14
s.NewFiles = 3 s.NewFiles = 3
s.NewFileSize = 4 s.NewFileSize = 4
s.DeletedFiles = 5 s.DeletedFiles = 5
...@@ -15,6 +17,7 @@ class StatsObjTest(unittest.TestCase): ...@@ -15,6 +17,7 @@ class StatsObjTest(unittest.TestCase):
s.ChangedFiles = 7 s.ChangedFiles = 7
s.ChangedSourceSize = 8 s.ChangedSourceSize = 8
s.ChangedMirrorSize = 9 s.ChangedMirrorSize = 9
s.IncrementFiles = 15
s.IncrementFileSize = 10 s.IncrementFileSize = 10
s.StartTime = 11 s.StartTime = 11
s.EndTime = 12 s.EndTime = 12
...@@ -38,25 +41,51 @@ class StatsObjTest(unittest.TestCase): ...@@ -38,25 +41,51 @@ class StatsObjTest(unittest.TestCase):
self.set_obj(s) self.set_obj(s)
stats_string = s.get_stats_string() stats_string = s.get_stats_string()
assert stats_string == \ assert stats_string == \
"""StartTime 11 (Wed Dec 31 16:00:11 1969) """StartTime 11.00 (Wed Dec 31 16:00:11 1969)
EndTime 12 (Wed Dec 31 16:00:12 1969) EndTime 12.00 (Wed Dec 31 16:00:12 1969)
ElapsedTime 1 (1 second) ElapsedTime 1.00 (1 second)
SourceFiles 1 SourceFiles 1
SourceFileSize 2 SourceFileSize 2 (2 bytes)
MirrorFiles 13
MirrorFileSize 14 (14 bytes)
NewFiles 3 NewFiles 3
NewFileSize 4 NewFileSize 4 (4 bytes)
DeletedFiles 5 DeletedFiles 5
DeletedFileSize 6 DeletedFileSize 6 (6 bytes)
ChangedFiles 7 ChangedFiles 7
ChangedSourceSize 8 ChangedSourceSize 8 (8 bytes)
ChangedMirrorSize 9 ChangedMirrorSize 9 (9 bytes)
IncrementFileSize 10 IncrementFiles 15
IncrementFileSize 10 (10 bytes)
""", "'%s'" % stats_string """, "'%s'" % stats_string
def test_line_string(self):
"""Test conversion to a single line"""
s = StatsObj()
self.set_obj(s)
statline = s.get_stats_line(("sample", "index", "w", "new\nline"))
assert statline == "sample/index/w/new\\nline 1 2 13 14 " \
"3 4 5 6 7 8 9 15 10", repr(statline)
statline = s.get_stats_line(())
assert statline == ". 1 2 13 14 3 4 5 6 7 8 9 15 10"
def test_byte_summary(self):
"""Test conversion of bytes to strings like 7.23MB"""
s = StatsObj()
f = s.get_byte_summary_string
assert f(1) == "1 byte"
assert f(234.34) == "234 bytes"
assert f(2048) == "2.00 KB"
assert f(3502243) == "3.34 MB"
assert f(314992230) == "300 MB"
assert f(36874871216) == "34.3 GB", f(36874871216)
assert f(3775986812573450) == "3434 TB"
def test_init_stats(self): def test_init_stats(self):
"""Test setting stat object from string""" """Test setting stat object from string"""
s = StatsObj() s = StatsObj()
s.init_stats_from_string("NewFiles 3 hello there") s.set_stats_from_string("NewFiles 3 hello there")
for attr in s.stat_attrs: for attr in s.stat_attrs:
if attr == 'NewFiles': assert s.get_stat(attr) == 3 if attr == 'NewFiles': assert s.get_stat(attr) == 3
else: assert s.get_stat(attr) is None, (attr, s.__dict__[attr]) else: assert s.get_stat(attr) is None, (attr, s.__dict__[attr])
...@@ -66,7 +95,7 @@ IncrementFileSize 10 ...@@ -66,7 +95,7 @@ IncrementFileSize 10
assert not s1.stats_equal(s) assert not s1.stats_equal(s)
s2 = StatsObj() s2 = StatsObj()
s2.init_stats_from_string(s1.get_stats_string()) s2.set_stats_from_string(s1.get_stats_string())
assert s1.stats_equal(s2) assert s1.stats_equal(s2)
def test_write_rp(self): def test_write_rp(self):
......
...@@ -84,6 +84,7 @@ class TimeTest(unittest.TestCase): ...@@ -84,6 +84,7 @@ class TimeTest(unittest.TestCase):
assert Time.inttopretty(0) == "0 seconds" assert Time.inttopretty(0) == "0 seconds"
assert Time.inttopretty(353) == "5 minutes 53 seconds" assert Time.inttopretty(353) == "5 minutes 53 seconds"
assert Time.inttopretty(3661) == "1 hour 1 minute 1 second" assert Time.inttopretty(3661) == "1 hour 1 minute 1 second"
assert Time.inttopretty(353.234234) == "5 minutes 53.23 seconds"
def testGenericString(self): def testGenericString(self):
"""Test genstrtotime, conversion of arbitrary string to time""" """Test genstrtotime, conversion of arbitrary string to time"""
......
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