source: trunk/yaml/tests/TestYamlBasics.py @ 87

Revision 87, 4.3 KB checked in by tim, 9 years ago (diff)

moved tests into a module under yaml and added a testrunner script courtesy of matt goodall

  • Property svn:executable set to *
Line 
1import YamlTest
2from here import *
3from test import assertEquals
4from yaml.load import l
5from yaml.dump import d
6
7class Test(YamlTest.YamlTest):
8    def setUp(self):
9        # print '>>>>>>>>>>>>>>>'
10        pass
11
12    def testNoLineFeed(self):
13        from yaml.stream import noLineFeed
14        assertEquals("foo", noLineFeed("foo\n"))
15        assertEquals("bar", noLineFeed("bar\n"))
16        assertEquals("bar", noLineFeed("bar\r\n"))
17        assertEquals("", noLineFeed("\r\n"))
18
19    def XXXtest9(self):
20        # XXX - not sure how this gets handled now
21        self.verify(
22            """
23            - foo: 1
24                bar: 2
25            """,
26            [ {'foo': 1, '  bar': 2}])
27
28    def testOutlineSnippet(self):
29        self.verify(
30            """
31            - YAML ToDo:
32                - y2outline
33                - support generic transfers
34                - work on YAML.py:
35                    - work on Store
36            """,
37            [ {'YAML ToDo': [   
38                'y2outline',
39                'support generic transfers',
40                { 'work on YAML.py': ['work on Store'] }
41                ]
42              }
43            ])
44
45    def testQuotedString(self):
46        self.verify(
47            """
48            ---
49            foo: 'key: value'
50            """,
51            {'foo': "key: value"}
52            )
53
54    def testFloatRedHerring(self):
55        self.verify(
56            """
57            ---
58            - 'Version: 0.18.0'
59            """,
60            [ 'Version: 0.18.0' ]
61            )
62
63    def testDashInQuotes(self):
64        self.verify(
65            """
66            ---
67            title: 'Perspective Broker - twisted.spread'
68            """,
69            {'title': 'Perspective Broker - twisted.spread'}
70            )
71
72    def testQuestionMarks(self):
73        self.verify(
74            """
75            ---
76            hello: you there?
77            foo:
78                - ok?
79                - sure?
80            bar:
81                - for here or to go?
82                - more sugar?
83            """,
84            {   
85                'hello': 'you there?',
86                'foo': ['ok?', 'sure?'],
87                'bar': ['for here or to go?', 'more sugar?']
88            }
89            )
90
91    def testDoubleQuoteEscapedKeys(self):
92        self.verify(
93            """
94            ---
95            "I'm escaped!": simple
96            """,
97            { "I'm escaped!": 'simple' }
98            )
99
100    def testColonsInsideEscapedKeys(self):
101        self.verify(
102            """
103            ---
104            'aaa: bbbb': simple
105            """,
106            { 'aaa: bbbb': 'simple' }
107            )
108
109    def testControlChars(self):
110        self.verify(
111            r"""
112            control: "\b1998\t1999\t2000\n"
113            """,
114            { 'control': "\b1998\t1999\t2000\n" }
115        )
116
117    def testUnicode(self):
118        if YamlTest.hasUnicode:
119            self.verify(
120                r'''
121                unicode: "Sosa did fine.\u263A"
122                ''',
123                { 'unicode': u"Sosa did fine.\u263A"}
124            )
125
126    def testMultiLineScalar(self):
127        self.verify(
128            """
129            plain: This unquoted
130                   scalar spans
131                   many lines.
132            """,
133            { 'plain': 'This unquoted scalar spans many lines.' }
134        )
135
136    def testDomainType(self):
137        class MyYamlConfig:
138            def resolveType(self, data, url):
139                if url == '!!name':
140                    return 'Foo ' + data
141                elif url == '!!coords':
142                    return { 'x': data[0], 'y': data[1]}
143                else:
144                    raise 'url not passed in correctly'
145        data = YamlTest.loadFlushLeft("""
146            name: !!name Barson
147            coords: !!coords
148              - 10
149              - 20
150            """, 
151            MyYamlConfig())
152        self.assertEquals(data[0], 
153            {'name': 'Foo Barson',
154            'coords': { 'x': 10, 'y': 20 } }
155        )
156
157    def testQuickInterfaces(self):
158        assertEquals(l("--- foo"), "foo")
159        assertEquals(d({'foo': 'bar'}), "---\nfoo: bar\n")
160
161if __name__ == '__main__':
162    import unittest
163    unittest.main()
Note: See TracBrowser for help on using the repository browser.