예제 #1
0
 def test_start_end(self):
     assert DOT(G(N('start', {N('end'): None}))).encode() == \
         lstrip('''
             | digraph {
             |   start -> end
             | }
         ''')
예제 #2
0
 def test_multilevel_suite(self):
     assert parse('''
                  | if q:
                  |   if q2:
                  |     first
                  |     second
                  ''') == G(
         N('q', {N('q2', {N('first', {N('second'): None}): True}): True}))
예제 #3
0
 def test_if_else(self):
     assert DOT(G(N('q', {N('y'): True, N('n'): False}))).encode() == \
         lstrip('''
                | digraph {
                |   q -> y [label=True]
                |   q -> n [label=False]
                | }
         ''')
예제 #4
0
 def test_if_else(self):
     assert parse('''
                  | if q:
                  |   y
                  | else:
                  |   n
                  ''') == G(N('q', {
         N('y'): True,
         N('n'): False
     }))
예제 #5
0
 def test_if_elif_elif_else(self):
     assert parse('''
                  | if q:
                  |   y
                  | elif q2:
                  |   y2
                  | elif q3:
                  |   y3
                  | else:
                  |   n
                  ''') == \
                 G(N('q', {
                     N('y'): True,
                     N('q2', {
                         N('y2'): True,
                         N('q3', {
                             N('y3'): True,
                             N('n'): False
                         }): False
                     }): False
                 }))
예제 #6
0
 def test_if_is(self):
     assert parse('''
                  | if s is o1:
                  |   y10
                  |   y11
                  | elif s is o2:
                  |   y2
                  | elif s is o3:
                  |   y3
                  | else:
                  |   n
                  ''') == \
                 G(N('s', {
                     N('y10', {N('y11'): None}): 'o1',
                     N('y2'): 'o2',
                     N('y3'): 'o3',
                     N('n'): False
                 }))
예제 #7
0
 def test__iter__(self, start_end):
     assert list(Graph(start_end)) == [N('start'), N('end')]
예제 #8
0
 def test__setitem__(self, start_end):
     g = N('start')
     g[N('end')] = None
     assert list(g.children) == list(start_end.children)
예제 #9
0
 def test__delitem__(self, start_end):
     del start_end[N('end')]
     assert not start_end.children
예제 #10
0
 def test__getitem__(self, start_end):
     assert start_end[N('end')] == None
예제 #11
0
 def test__iter__(self, start_end):
     assert tuple(iter(start_end)) == tuple({N('end'): None})
예제 #12
0
 def test__lt__(self, start_end):
     assert start_end < N('z')
예제 #13
0
 def test__eq__(self, start_end):
     assert start_end == N('start')
     assert start_end != N('end')
예제 #14
0
    def test__eq__(self, start_end):
        assert Graph(start_end) == Graph(N('start', {N('end'): None}))
        assert Graph(start_end) != Graph(N('start'))
        assert Graph(start_end) != Graph(
            N('start', {N('end', {N('extra'): None}): None}))
        assert Graph(start_end) != Graph(N('start', {N('end'): True}))

        assert Graph(N('q', {N('y'): True, N('n'): False})) == \
            Graph(N('q', {N('n'): False, N('y'): True}))
예제 #15
0
def start_end():
    return 'start; end', G(N('start', {N('end'): None}))
예제 #16
0
 def test_if(self):
     assert parse('''
                  | if q:
                  |   y
                  ''') == G(N('q', {N('y'): True}))
예제 #17
0
 def test_if_not(self):
     assert parse('''
                  | if not q:
                  |   y
                  ''') == G(N('q', {N('y'): False}))
예제 #18
0
 def test_multistatemnt_suite(self):
     assert parse('''
                  | if q:
                  |   first
                  |   second
                  ''') == G(N('q', {N('first', {N('second'): None}): True}))
예제 #19
0
def start_end():
    return N('start', {N('end'): None})
예제 #20
0
 def test_children(self, start_end):
     assert start_end.children == {N('end'): None}