def p_step(p): ''' step : '-' edge '-' '>' vertex | '<' '-' edge '-' vertex | '-' '-' '>' vertex | '<' '-' '-' vertex ''' step = Step() if p[1] == '-': step.type = 1 else: step.type = -1 if len(p) == 5: v = p[4].get_vVal() e = None elif p[1] == '-': v = p[5].get_vVal() e = p[2].get_eVal() else: v = p[5].get_vVal() e = p[3].get_eVal() if e is not None: step.name = e.name step.ranking = e.ranking step.props = e.props step.dst = v p[0] = step
def p_steps(p): ''' steps : edge vertex | steps edge vertex ''' step = Step() if len(p) == 3: step.dst = p[2].get_vVal() edge = p[1].get_eVal() step.name = edge.name step.type = edge.type step.ranking = edge.ranking step.props = edge.props p[0] = [step] else: step.dst = p[3].get_vVal() edge = p[2].get_eVal() step.name = edge.name step.type = edge.type step.ranking = edge.ranking step.props = edge.props p[1].append(step) p[0] = p[1]
expected['<-[@-1]-'] = Value(eVal=Edge(type=-1, ranking=-1)) expected['-["1"->"2"]->'] = Value(eVal=Edge(src='1', dst='2', type=1)) expected['<-["1"->"2"]-'] = Value(eVal=Edge(src='1', dst='2', type=-1)) expected['-[{}]->'] = Value(eVal=Edge(type=1, props={})) expected['<-[{}]-'] = Value(eVal=Edge(type=-1, props={})) expected['-[:e{}]->'] = Value(eVal=Edge(name='e', type=1, props={})) expected['<-[:e{}]-'] = Value(eVal=Edge(name='e', type=-1, props={})) expected['-[:e@123{}]->'] = Value( eVal=Edge(name='e', type=1, ranking=123, props={})) expected['<-[:e@123{}]-'] = Value( eVal=Edge(name='e', type=-1, ranking=123, props={})) expected['-[:e"1"->"2"@123{}]->'] = Value( eVal=Edge(name='e', type=1, ranking=123, src='1', dst='2', props={})) expected['<()>'] = Value(pVal=Path(src=Vertex())) expected['<("vid")>'] = Value(pVal=Path(src=Vertex(vid='vid'))) expected['<()-->()>'] = Value( pVal=Path(src=Vertex(), steps=[Step(type=1, dst=Vertex())])) expected['<()<--()>'] = Value( pVal=Path(src=Vertex(), steps=[Step(type=-1, dst=Vertex())])) expected['<()-->()-->()>'] = Value(pVal=Path(src=Vertex(),\ steps=[Step(type=1, dst=Vertex()),Step(type=1, dst=Vertex())])) expected['<()-->()<--()>'] = Value(pVal=Path(src=Vertex(),\ steps=[Step(type=1, dst=Vertex()),Step(type=-1, dst=Vertex())])) expected['<("v1")-[:e1]->()<-[:e2]-("v2")>'] = Value(pVal=Path(src=Vertex(vid='v1'),\ steps=[Step(name='e1',type=1,dst=Vertex()),Step(name='e2',type=-1, dst=Vertex(vid='v2'))])) for item in expected.items(): v = parse(item[0]) assert v is not None, "Failed to parse %s" % item[0] assert v == item[1], \ "Parsed value not as expected, str: %s, expected: %s actual: %s" % (item[0], item[1], v)
expected['[hash("1")->hash("2")]'] = Value( eVal=Edge(src=murmurhash2('1'), dst=murmurhash2('2'))) expected['[:e{}]'] = Value(eVal=Edge(name='e', props={})) expected['[:e@123{}]'] = Value(eVal=Edge(name='e', ranking=123, props={})) expected['[:e"1"->"2"@123{}]'] = Value(eVal=Edge( name='e', ranking=123, src='1', dst='2', props={}, )) expected['<()>'] = Value(pVal=Path(src=Vertex())) expected['<("vid")>'] = Value(pVal=Path(src=Vertex(vid='vid'))) expected['<()-->()>'] = Value(pVal=Path( src=Vertex(), steps=[Step(type=1, dst=Vertex())], )) expected['<()<--()>'] = Value(pVal=Path( src=Vertex(), steps=[Step(type=-1, dst=Vertex())], )) expected['<()-->()-->()>'] = Value(pVal=Path( src=Vertex(), steps=[ Step(type=1, dst=Vertex()), Step(type=1, dst=Vertex()), ], )) expected['<()-->()<--()>'] = Value(pVal=Path( src=Vertex(), steps=[
for cell in row: v = nbv.parse(cell) if v is None: raise Exception('Unable to parse %s' % cell) list.append(v) return Row(list) if __name__ == '__main__': headings = ['m', 'r', 'n'] rows = [ ['1', '2', '3'], ['()', '-->', '()'], ['("vid")', '<-[:e "1" -> "2" @-1 {p1: 0, p2: [1, 2, 3]}]-', '()'], ['<()-->()<--()>', '()', '"prop"'], ['EMPTY', 'NULL', 'BAD_TYPE'], ] expected = DataSet(column_names = headings,\ rows = [ Row([Value(iVal=1), Value(iVal=2), Value(iVal=3)]), Row([Value(vVal=Vertex()), Value(eVal=Edge(type=1)), Value(vVal=Vertex())]), Row([Value(vVal=Vertex('vid')), Value(eVal=Edge(name='e',type=-1,src='1',dst='2',ranking=-1,props={'p1': Value(iVal=0), 'p2': Value(lVal=List([Value(iVal=1),Value(iVal=2),Value(iVal=3)]))})), Value(vVal=Vertex())]), Row([Value(pVal=Path(src=Vertex(),steps=[Step(type=1,dst=Vertex()),Step(type=-1,dst=Vertex())])), Value(vVal=Vertex()), Value(sVal='prop')]), Row([Value(), Value(nVal=NullType.__NULL__), Value(nVal=NullType.BAD_TYPE)]) ]) table = bh.Table(headings=headings, rows=rows) dataset = parse(table) assert dataset == expected,\ "Parsed DataSet doesn't match, \nexpected: %s, \nactual: %s" % (expected, dataset)