-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_plugin.py
97 lines (82 loc) · 2.32 KB
/
test_plugin.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
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
96
97
import pytest
import mappyfile
from mappyfile_colors import ColorsTransformer, ConversionType
from mappyfile.parser import Parser
from mappyfile.transformer import MapfileToDict
from mappyfile.pprint import PrettyPrinter
def test_simple_api():
s = """
CLASS
STYLE
COLOR 184 134 11
OUTLINECOLOR 0 0 255
WIDTH 3
END
END
"""
d = mappyfile.loads(
s,
include_color_names=True,
include_comments=True,
transformer_class=ColorsTransformer,
conversion_type=ConversionType.TO_HEX,
)
output = mappyfile.dumps(d, indent=0, newlinechar=" ")
assert (
output
== 'CLASS STYLE COLOR "#b8860b" # darkgoldenrod OUTLINECOLOR "#0000ff" # blue WIDTH 3 END END'
)
def test_simple_api_rgb():
s = """
CLASS
STYLE
COLOR "#b8860b"
OUTLINECOLOR "#0000ff"
WIDTH 3
END
END
"""
d = mappyfile.loads(
s,
include_color_names=True,
include_comments=True,
transformer_class=ColorsTransformer,
conversion_type=ConversionType.TO_RGB,
)
output = mappyfile.dumps(d, indent=0, newlinechar=" ")
print(output)
assert (
output
== "CLASS STYLE COLOR 184 134 11 # darkgoldenrod OUTLINECOLOR 0 0 255 # blue WIDTH 3 END END"
)
def test_api():
s = """
CLASS
STYLE
COLOR 184 134 11
OUTLINECOLOR 0 0 255
WIDTH 3 # ignore this comment
END
END
"""
p = Parser(expand_includes=True, include_comments=False)
ast = p.parse(s)
m = MapfileToDict(
include_comments=True,
include_color_names=True, # if this is True then include_comments must also be true
transformer_class=ColorsTransformer,
conversion_type=ConversionType.TO_HEX,
)
d = m.transform(ast)
pp = PrettyPrinter(indent=0, newlinechar=" ")
output = pp.pprint(d)
assert (
output
== 'CLASS STYLE COLOR "#b8860b" # darkgoldenrod OUTLINECOLOR "#0000ff" # blue WIDTH 3 END END'
)
def run_tests():
pytest.main(["tests/test_plugin.py", "-vv"])
if __name__ == "__main__":
# test_api()
run_tests()
print("Done!")