-
Notifications
You must be signed in to change notification settings - Fork 9
/
test_util.py
68 lines (48 loc) · 1.42 KB
/
test_util.py
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
import unittest
from os import path
import gcl
from gcl import util
class TestJSONLoader(unittest.TestCase):
"""Test our JSON compatibility routines."""
def set_json(self, json):
self.loader = util.JSONLoader(gcl.InMemoryFiles({
'/test.json': json
}), filter_fn=util.interpolate_json)
def parse(self, gcl_contents):
return gcl.loads(gcl_contents, filename='/root.gcl', loader=self.loader)
def testJSONSimple(self):
self.set_json('{"test" : "it works"}')
x = self.parse("""
included = include "test.json";
""")
self.assertEquals('it works', x['included']['test'])
def testJSONWithSubstitutions(self):
self.set_json('{"test" : "it {verb}"}')
x = self.parse("""
included = include "test.json" {
verb = 'works'
}
""")
self.assertEquals('it works', x['included']['test'])
def testJSONList(self):
self.set_json('["{foo}", "{foo}"]')
x = self.parse("""
included = include "test.json" {
foo = 'boo'
}
""")
self.assertEquals(['boo', 'boo'], list(x['included']))
def testJSONString(self):
self.set_json('"{foo}{foo}"')
x = self.parse("""
included = include "test.json" {
foo = 'boo'
}
""")
self.assertEquals('booboo', str(x['included']))
def testJSONNumber(self):
self.set_json('3')
x = self.parse("""
included = include "test.json";
""")
self.assertEquals(3, x['included'])