summaryrefslogtreecommitdiff
path: root/test/test-specparser.py
blob: 806d7fc8b95dba9ac8db4ff24ce99186ffeb9fba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env python

import sys
import os.path

test_dir = os.path.dirname (sys.argv[0])
sys.path.insert (0, os.path.join (test_dir, '../tools/'))

import specparser

spec_path = os.path.join (test_dir, 'input/all.xml')

def test_specparser ():
    """
>>> spec = specparser.parse (spec_path, 'im.telepathy1.SpecAutoGenTest')
>>> spec
Spec(telepathy-spec tools test case)

>>> spec.interfaces
[Interface(im.telepathy1.SpecAutoGenTest)]

>>> sorted(spec.errors.items())
[(u'im.telepathy1.SpecAutoGenTest.MiscError', Error(im.telepathy1.SpecAutoGenTest.MiscError)), (u'im.telepathy1.SpecAutoGenTest.OtherError', Error(im.telepathy1.SpecAutoGenTest.OtherError))]

>>> spec.generic_types
[]
>>> spec.types
{u'Adjective': Enum(Adjective), u'Test_Flags': Flags(Test_Flags), u'UV': Struct(UV)}

>>> i = spec.interfaces[0]
>>> i
Interface(im.telepathy1.SpecAutoGenTest)

>>> print i.causes_havoc
None

>>> i.methods
[Method(im.telepathy1.SpecAutoGenTest.DoStuff)]

>>> i.methods[0].args
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'Method' object has no attribute 'args'
>>> i.methods[0].in_args
[Arg(im.telepathy1.SpecAutoGenTest.DoStuff.badger:b), Arg(im.telepathy1.SpecAutoGenTest.DoStuff.mushroom:a{sv}), Arg(im.telepathy1.SpecAutoGenTest.DoStuff.snake:s)]
>>> i.methods[0].out_args
[Arg(im.telepathy1.SpecAutoGenTest.DoStuff.misc:a(uv))]

>>> i.methods[0].possible_errors
[PossibleError(im.telepathy1.SpecAutoGenTest.MiscError), PossibleError(im.telepathy1.SpecAutoGenTest.OtherError)]
>>> map (lambda e: e.get_error (), i.methods[0].possible_errors)
[Error(im.telepathy1.SpecAutoGenTest.MiscError), Error(im.telepathy1.SpecAutoGenTest.OtherError)]

>>> i.signals
[Signal(im.telepathy1.SpecAutoGenTest.StuffHappened)]

>>> i.signals[0].args
[Arg(im.telepathy1.SpecAutoGenTest.StuffHappened.stoat:ay), Arg(im.telepathy1.SpecAutoGenTest.StuffHappened.ferret:s), Arg(im.telepathy1.SpecAutoGenTest.StuffHappened.weasel:b)]

>>> i.properties
[Property(im.telepathy1.SpecAutoGenTest.Introspective:b)]

>>> i.properties[0].type
''
>>> i.properties[0].dbus_type
u'b'
>>> print i.properties[0].get_type ()
None

>>> i.types
[Enum(Adjective), Flags(Test_Flags), Struct(UV)]

>>> i.types[0].values
[EnumValue(Adjective.Leveraging), EnumValue(Adjective.Synergistic)]
>>> map (lambda v: (v.short_name, v.value), i.types[0].values)
[(u'Leveraging', u'0'), (u'Synergistic', u'1')]

>>> i.types[1].values
[EnumValue(Test_Flags.LowBit), EnumValue(Test_Flags.HighBit)]
>>> map (lambda v: (v.short_name, v.value), i.types[1].values)
[(u'LowBit', u'1'), (u'HighBit', u'128')]

>>> sorted(spec.everything.items())
[(u'im.telepathy1.SpecAutoGenTest', ClientInterest(im.telepathy1.SpecAutoGenTest)), (u'im.telepathy1.SpecAutoGenTest.DoStuff', Method(im.telepathy1.SpecAutoGenTest.DoStuff)), (u'im.telepathy1.SpecAutoGenTest.Introspective', Property(im.telepathy1.SpecAutoGenTest.Introspective:b)), (u'im.telepathy1.SpecAutoGenTest.StuffHappened', Signal(im.telepathy1.SpecAutoGenTest.StuffHappened)), (u'im.telepathy1.SpecAutoGenTest/badgers', ClientInterest(im.telepathy1.SpecAutoGenTest/badgers))]


>>> map (lambda o: i.added, spec.everything.values ())
[None, None, None, None, None]
>>> map (lambda o: i.deprecated, spec.everything.values ())
[None, None, None, None, None]
    """

if __name__ == '__main__':
    import doctest
    doctest.testmod ()