def test_spawn(self): class Child(VisitPassenger): def __init__(self): VisitPassenger.__init__(self) self.osaka= False def itinerary(self): yield vpath2regexp('//osaka') self.osaka= True raise StopIteration c = Child() class Parent(VisitPassenger): def __init__(self): VisitPassenger.__init__(self) self.tokyo = False def spawn(self): return [c] def itinerary(self): yield re.compile('^.*tokyo') self.tokyo = True raise StopIteration p = Parent() self.assert_(not p.tokyo) self.assert_(not c.osaka) bus = VisitBus((p,)) bus.visit(self.tree.getroot()) self.assert_(p.tokyo) self.assert_(c.osaka)
def test_japandu(self): class JapanPassenger(VisitPassenger): def __init__(self): VisitPassenger.__init__(self) self.down = False self.up= False self.tokyo = False self.osaka = False def itinerary(self): yield vpath2regexp('//japan>') self.down = True yield vpath2regexp('//tokyo') self.tokyo = True yield vpath2regexp('//osaka') self.osaka = True yield vpath2regexp('//japan<') self.up = True raise StopIteration p = JapanPassenger() self.assert_(not p.down) self.assert_(not p.up) self.assert_(not p.tokyo) self.assert_(not p.osaka) bus = VisitBus((p,)) bus.visit(self.tree.getroot()) self.assert_(p.down) self.assert_(p.tokyo) self.assert_(p.osaka) self.assert_(p.up)
def test_ManyPassengers(self): class TokyoPassenger(VisitPassenger): def __init__(self): VisitPassenger.__init__(self) self.tokyo = False def itinerary(self): yield vpath2regexp('//tokyo') self.tokyo = True raise StopIteration class OsakaPassenger(VisitPassenger): def __init__(self): VisitPassenger.__init__(self) self.osaka = False def itinerary(self): yield vpath2regexp('//osaka') self.osaka = True raise StopIteration tokyo1 = TokyoPassenger() tokyo2 = TokyoPassenger() osaka = OsakaPassenger() self.assert_(not tokyo1.tokyo) self.assert_(not tokyo2.tokyo) self.assert_(not osaka.osaka) bus = VisitBus((tokyo1, tokyo2, osaka)) bus.visit(self.tree.getroot()) self.assert_(tokyo1.tokyo) self.assert_(tokyo2.tokyo) self.assert_(osaka.osaka)
def test_tokyoup(self): class TokyoPassenger(VisitPassenger): def __init__(self): VisitPassenger.__init__(self) self.tokyo = False def itinerary(self): yield vpath2regexp('//tokyo<') self.tokyo = True raise StopIteration p = TokyoPassenger() self.assert_(not p.tokyo) bus = VisitBus((p,)) bus.visit(self.tree.getroot()) self.assert_(p.tokyo)
def test_visitRegexp(self): class TokyoPassenger(VisitPassenger): def __init__(self): VisitPassenger.__init__(self) self.tokyo = False self.osaka = False def itinerary(self): yield re.compile('^.*tokyo') self.tokyo = True yield re.compile('^.*osaka') self.osaka = True raise StopIteration p = TokyoPassenger() self.assert_(not p.tokyo) self.assert_(not p.osaka) bus = VisitBus((p,)) bus.visit(self.tree.getroot()) self.assert_(p.tokyo) self.assert_(p.osaka)