-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathtest.py
213 lines (172 loc) · 8.58 KB
/
test.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#!/usr/bin/env python
#
# Let's try and integrate some unittest tests
#
import glob
import os
import unittest
from xym import xym
class TestCase_base(unittest.TestCase):
def setUp(self):
for y in glob.glob('*.yang'):
os.remove(y)
def tearDown(self):
for y in glob.glob('*.yang'):
os.remove(y)
class TestCase_default(TestCase_base):
def runTest(self):
"""Run a test that is the equivalent of:
xym.py test-file.txt
"""
extracted_modules = xym.xym('resources/test-file.txt', './', './', strict=False, strict_examples=False,
debug_level=0)
self.assertTrue(len(extracted_modules) == 5)
module_check = ['example-no-error.yang', 'ex-error.yang', 'ex-no-error.yang', 'example-error.yang',
'test-valid.yang']
for y in module_check:
self.assertTrue(y in extracted_modules)
class TestCase_strict(TestCase_base):
def runTest(self):
"""Run a test that is the equivalent of:
xym.py --strict test-file.txt
"""
extracted_modules = xym.xym('resources/test-file.txt', './', './', strict=True, strict_examples=False,
debug_level=0)
self.assertTrue(len(extracted_modules) == 3)
module_check = ['ex-no-error.yang', 'example-error.yang', 'test-valid.yang']
for y in module_check:
self.assertTrue(y in extracted_modules)
class TestCase_strict_examples(TestCase_base):
def runTest(self):
"""Run a test that is the equivalent of:
xym.py --strict --strict-examples test-file.txt
"""
extracted_modules = xym.xym('resources/test-file.txt', './', './', strict=True, strict_examples=True,
debug_level=0)
self.assertTrue(len(extracted_modules) == 1)
module_check = ['example-no-error.yang']
for y in module_check:
self.assertTrue(y in extracted_modules)
class TestCase_codeBegins_noFile(TestCase_base):
def runTest(self):
"""Run a test that is the equivalent of:
xym.py --strict --strict-examples test-file.txt
"""
print('startig test')
extracted_modules = xym.xym('resources/test-file-no-file-after-code-begins', './', './', strict=True,
strict_examples=False, debug_level=0, force_revision_regexp=True)
print(extracted_modules)
self.assertTrue(len(extracted_modules) == 1)
module_check = ['[email protected]']
for y in module_check:
self.assertTrue(y in extracted_modules)
class TestCase_codeBegins_fileWithSymbol(TestCase_base):
def runTest(self):
"""Run a test that is the equivalent of:
xym.py --strict --strict-examples test-file.txt
"""
extracted_modules = xym.xym('resources/test-file-with-symbol', './', './', strict=True, strict_examples=False,
debug_level=0, force_revision_regexp=True)
self.assertTrue(len(extracted_modules) == 1)
module_check = ['[email protected]']
for y in module_check:
self.assertTrue(y in extracted_modules)
class TestCase_forceRevisionPyang(TestCase_base):
def runTest(self):
"""Run a test that is the equivalent of:
xym.py --force-revision-pyang https://tools.ietf.org/rfc/rfc7223.txt
"""
print('start force_revision_pyang')
extracted_modules = xym.xym("https://tools.ietf.org/rfc/rfc7223.txt", './', './',
debug_level=0, force_revision_pyang=True)
self.assertTrue(len(extracted_modules) == 4)
module_check = ['[email protected]', 'ex-ethernet.yang', 'ex-ethernet-bonding.yang',
'ex-vlan.yang']
for y in module_check:
self.assertTrue(y in extracted_modules)
class TestCase_forceRevisionRegexp(TestCase_base):
def runTest(self):
"""Run a test that is the equivalent of:
xym.py --force_revision_regexp https://tools.ietf.org/rfc/rfc7223.txt
"""
print('start force_revision_regexp')
extracted_modules = xym.xym("https://tools.ietf.org/rfc/rfc7223.txt", './', './',
debug_level=0, force_revision_regexp=True)
self.assertTrue(len(extracted_modules) == 4)
module_check = ['[email protected]', 'ex-ethernet.yang', 'ex-ethernet-bonding.yang',
'ex-vlan.yang']
for y in module_check:
self.assertTrue(y in extracted_modules)
class TestCase_parseonlymodules(TestCase_base):
def runTest(self):
"""Run a test that is the equivalent of:
xym.py --parse-only-modules test-valid example-error.yang source test-file.txt
"""
extracted_modules = xym.xym('resources/test-file.txt', './', './',
strict=False,
strict_examples=False,
debug_level=0,
parse_only_modules=['test-valid', 'example-error.yang'])
self.assertTrue(len(extracted_modules) == 2)
module_check = ['test-valid.yang', 'example-error.yang']
for y in module_check:
self.assertTrue(y in extracted_modules)
class TestCase_skipmodules(TestCase_base):
def runTest(self):
"""Run a test that is the equivalent of:
xym.py --skip-modules test-valid ex-no-error.yang source test-file.txt
"""
extracted_modules = xym.xym('resources/test-file.txt', './', './',
strict=False,
strict_examples=False,
debug_level=0,
skip_modules=['test-valid', 'ex-no-error.yang'])
self.assertTrue(len(extracted_modules) == 3)
module_check = ['example-no-error.yang', 'ex-error.yang', 'example-error.yang']
for y in module_check:
self.assertTrue(y in extracted_modules)
class TestCase_strict_parseonlymodules(TestCase_base):
def runTest(self):
"""Run a test that is the equivalent of:
xym.py --strict --parse-only-modules example-no-error source test-file.txt
"""
extracted_modules = xym.xym('resources/test-file.txt', './', './',
strict=True,
strict_examples=False,
debug_level=0,
parse_only_modules=['example-no-error'])
self.assertTrue(len(extracted_modules) == 0)
class TestCase_strict_skipmodules(TestCase_base):
def runTest(self):
"""Run a test that is the equivalent of:
xym.py --strict --skip-modules ex-error ex-no-error example-error test-valid source test-file.txt
"""
extracted_modules = xym.xym('resources/test-file.txt', './', './',
strict=True,
strict_examples=False,
debug_level=0,
skip_modules=['ex-error', 'ex-no-error', 'example-error', 'test-valid'])
self.assertTrue(len(extracted_modules) == 0)
class TestCase_strict_examples_parseonlymodules(TestCase_base):
def runTest(self):
"""Run a test that is the equivalent of:
xym.py --strict --strict-examples --parse-only-modules ex-error ex-no-error example-error test-valid \
source test-file.txt
"""
extracted_modules = xym.xym('resources/test-file.txt', './', './',
strict=True,
strict_examples=True,
debug_level=0,
parse_only_modules=['ex-error', 'test-valid', 'ex-no-error', 'example-error'])
self.assertTrue(len(extracted_modules) == 0)
class TestCase_strict_examples_skipmodules(TestCase_base):
def runTest(self):
"""Run a test that is the equivalent of:
xym.py --strict --strict-examples --skip-modules example-no-error source test-file.txt
"""
extracted_modules = xym.xym('resources/test-file.txt', './', './',
strict=True,
strict_examples=True,
debug_level=0,
skip_modules=['example-no-error'])
self.assertTrue(len(extracted_modules) == 0)