Commit 8069fb19 authored by ben's avatar ben

Added root selection test, and modified tests to jive with new

IterTreeReducer fast_process code.


git-svn-id: http://svn.savannah.nongnu.org/svn/rdiff-backup@146 2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109
parent a5904b19
......@@ -218,7 +218,7 @@ class MultiplexTest(Iterators):
assert Iter.equal(i2, self.one_to_100())
class ITRadder(IterTreeReducer):
class ITRBadder(ITRBranch):
def start_process(self, index):
self.total = 0
......@@ -232,7 +232,7 @@ class ITRadder(IterTreeReducer):
#print "Adding subinstance ", subinstance.total
self.total += subinstance.total
class ITRadder2(IterTreeReducer):
class ITRBadder2(ITRBranch):
def start_process(self, index):
self.total = 0
......@@ -240,6 +240,13 @@ class ITRadder2(IterTreeReducer):
#print "Adding ", self.base_index
self.total += reduce(lambda x,y: x+y, self.base_index, 0)
def can_fast_process(self, index):
if len(index) == 3: return 1
else: return None
def fast_process(self, index):
self.total += index[0] + index[1] + index[2]
def branch_process(self, subinstance):
#print "Adding branch ", subinstance.total
self.total += subinstance.total
......@@ -257,24 +264,24 @@ class TreeReducerTest(unittest.TestCase):
def testTreeReducer(self):
"""testing IterTreeReducer"""
itm = ITRadder()
itm = IterTreeReducer(ITRBadder, [])
for index in self.i1:
val = itm(index)
assert val, (val, index)
itm.Finish()
assert itm.total == 6, itm.total
assert itm.root_branch.total == 6, itm.root_branch.total
itm2 = ITRadder2()
itm2 = IterTreeReducer(ITRBadder2, [])
for index in self.i2:
val = itm2(index)
if index == (): assert not val
else: assert val
itm2.Finish()
assert itm2.total == 12, itm2.total
assert itm2.root_branch.total == 12, itm2.root_branch.total
def testTreeReducerState(self):
"""Test saving and recreation of an IterTreeReducer"""
itm1a = ITRadder()
itm1a = IterTreeReducer(ITRBadder, [])
for index in self.i1a:
val = itm1a(index)
assert val, index
......@@ -283,9 +290,9 @@ class TreeReducerTest(unittest.TestCase):
val = itm1b(index)
assert val, index
itm1b.Finish()
assert itm1b.total == 6, itm1b.total
assert itm1b.root_branch.total == 6, itm1b.root_branch.total
itm2a = ITRadder2()
itm2a = IterTreeReducer(ITRBadder2, [])
for index in self.i2a:
val = itm2a(index)
if index == (): assert not val
......@@ -301,7 +308,7 @@ class TreeReducerTest(unittest.TestCase):
if index == (): assert not val
else: assert val
itm2c.Finish()
assert itm2c.total == 12, itm2c.total
assert itm2c.root_branch.total == 12, itm2c.root_branch.total
if __name__ == "__main__": unittest.main()
......@@ -371,7 +371,16 @@ class FileAttributes(FileCopying):
self.assertRaises(RPathException, RPath.copy_attribs,
self.nothing, self.nowrite)
class CheckPath(unittest.TestCase):
"""Check to make sure paths generated properly"""
def testpath(self):
"""Test root paths"""
root = RPath(Globals.local_connection, "/")
assert root.path == "/", root.path
bin = root.append("bin")
assert bin.path == "/bin", bin.path
bin2 = RPath(Globals.local_connection, "/bin")
assert bin.path == "/bin", bin2.path
if __name__ == "__main__":
unittest.main()
......@@ -224,9 +224,12 @@ testfiles/select/1/1
class ParseArgsTest(unittest.TestCase):
"""Test argument parsing"""
root = None
def ParseTest(self, tuplelist, indicies, filelists = []):
"""No error if running select on tuple goes over indicies"""
self.root = DSRPath(1, Globals.local_connection, "testfiles/select")
if not self.root:
self.root = DSRPath(1, Globals.local_connection,
"testfiles/select")
self.Select = Select(self.root)
self.Select.ParseArgs(tuplelist, filelists)
self.Select.set_iter()
......@@ -278,6 +281,32 @@ class ParseArgsTest(unittest.TestCase):
('3', '3'),
('3', '3', '2')])
def testGlob2(self):
"""Test more globbing functions"""
self.ParseTest([("--include", "testfiles/select/*foo*/p*"),
("--exclude", "**")],
[(), ('efools',), ('efools', 'ping'),
('foobar',), ('foobar', 'pong')])
self.ParseTest([("--exclude", "testfiles/select/1/1/*"),
("--exclude", "testfiles/select/1/2/**"),
("--exclude", "testfiles/select/1/3**"),
("--include", "testfiles/select/1"),
("--exclude", "**")],
[(), ('1',), ('1', '1'), ('1', '2')])
def testAlternateRoot(self):
"""Test select with different root"""
self.root = DSRPath(1, Globals.local_connection,
"testfiles/select/1")
self.ParseTest([("--exclude", "testfiles/select/1/[23]")],
[(), ('1',), ('1', '1'), ('1', '2'), ('1', '3')])
self.root = DSRPath(1, Globals.local_connection, "/")
self.ParseTest([("--exclude", "/home/*"),
("--include", "/home"),
("--exclude", "/")],
[(), ("home",)])
def testParseStartingFrom(self):
"""Test parse, this time starting from inside"""
self.root = DSRPath(1, Globals.local_connection, "testfiles/select")
......
......@@ -29,7 +29,7 @@ class StatsObjTest(unittest.TestCase):
self.set_obj(s)
assert s.get_stat('SourceFiles') == 1
s1 = StatsITR()
s1 = StatsITRB()
assert s1.get_stat('SourceFiles') == 0
def test_get_stats_string(self):
......
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