This repository was archived by the owner on Jun 23, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_namespaces.py
More file actions
61 lines (56 loc) · 1.99 KB
/
test_namespaces.py
File metadata and controls
61 lines (56 loc) · 1.99 KB
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
from __future__ import unicode_literals
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import
from future import standard_library
standard_library.install_aliases()
from builtins import *
import json
import pytest
from nstack import build
from helper_defs import *
testdata1 = json.loads("""
{
"config": {
"runCmd": "/usr/bin/true",
"stack": "Python"
},
"api": {
"types": [
[ [ "nstack/Hello:0.0.1-SNAPSHOT", "MyText" ], { "type": [ "text", null ] } ],
[ [ "nstack/Hello2:0.0.1-SNAPSHOT", "MyInt" ], { "type": [ "int", null ] } ]
],
"imports": [ [ "One", "nstack/Hello:0.0.1-SNAPSHOT" ] ],
"signatures": {
"numChars": [
{ "type": [ "ref", ["nstack/Hello:0.0.1-SNAPSHOT", "MyText"] ] },
{ "type": [ "ref", ["nstack/Hello2:0.0.1-SNAPSHOT", "MyInt"] ] }
]
},
"unqualified": [
"nstack/Hello2:0.0.1-SNAPSHOT"
]
}
}""")
testdata2 = {
"types": [[["nstack/Ex1:0.0.1", "Foo"], t_tuple(t_int, t_int)],
[["nstack/Ex2:0.0.1", "Foo"], t_tuple(t_ref(["nstack/Ex1:0.0.1", "Foo"]),
t_ref(["nstack/Ex1:0.0.1", "Foo"]))]],
"signatures": {"method1": [t_ref(["nstack/Ex1:0.0.1", "Foo"]),
t_ref(["nstack/Ex2:0.0.1", "Foo"])]},
"imports": [["Ex1", "nstack/Ex1:0.0.1"], ["Ex2", "nstack/Ex2:0.0.1"]],
"unqualified": ["nstack/Ex3:0.0.1"],
}
def test_namespace1():
a, b, c = build.process_schema(testdata1["api"])
assert issubclass(c.MyInt, int)
assert issubclass(c.One.MyText, str)
with pytest.raises(AttributeError):
c.MyText
assert b(type('ex', (object, ), {'numChars': lambda i: len(i)})).numChars("foo") == 3
def test_namespace2():
a, b, c = build.process_schema(testdata2)
assert c.Ex1.Foo is not c.Ex2.Foo
with pytest.raises(AttributeError):
c.Foo
assert b(type('ex', (object, ), {'method1': lambda i: (i, i)})).method1((1,2)) == ((1,2), (1,2))