forked from etingof/pysmi
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_moduleidentity_smiv2_pysnmp.py
117 lines (96 loc) · 3.26 KB
/
test_moduleidentity_smiv2_pysnmp.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
#
# This file is part of pysmi software.
#
# Copyright (c) 2015-2020, Ilya Etingof <[email protected]>
# License: http://snmplabs.com/pysmi/license.html
#
import sys
try:
import unittest2 as unittest
except ImportError:
import unittest
from pysmi.parser.smi import parserFactory
from pysmi.codegen.pysnmp import PySnmpCodeGen
from pysmi.codegen.symtable import SymtableCodeGen
from pysnmp.smi.builder import MibBuilder
class ModuleIdentityTestCase(unittest.TestCase):
"""
TEST-MIB DEFINITIONS ::= BEGIN
IMPORTS
MODULE-IDENTITY
FROM SNMPv2-SMI;
testModule MODULE-IDENTITY
LAST-UPDATED "200001100000Z" -- Midnight 10 January 2000
ORGANIZATION "AgentX Working Group"
CONTACT-INFO "WG-email: [email protected]"
DESCRIPTION "This is the MIB module for the SNMP"
REVISION "200001100000Z" -- Midnight 10 January 2000
DESCRIPTION "Initial version published as RFC 2742."
::= { 1 3 }
END
"""
def setUp(self):
ast = parserFactory()().parse(self.__class__.__doc__)[0]
mibInfo, symtable = SymtableCodeGen().genCode(ast, {}, genTexts=True)
self.mibInfo, pycode = PySnmpCodeGen().genCode(ast, {mibInfo.name: symtable}, genTexts=True)
codeobj = compile(pycode, 'test', 'exec')
mibBuilder = MibBuilder()
mibBuilder.loadTexts = True
self.ctx = {'mibBuilder': mibBuilder}
exec(codeobj, self.ctx, self.ctx)
def testModuleIdentitySymbol(self):
self.assertTrue(
'testModule' in self.ctx,
'symbol not present'
)
def testModuleIdentityName(self):
self.assertEqual(
self.ctx['testModule'].getName(),
(1, 3),
'bad name'
)
def testModuleIdentityLastUpdated(self):
self.assertEqual(
self.ctx['testModule'].getLastUpdated(),
'200001100000Z',
'bad LAST-UPDATED'
)
def testModuleIdentityOrganization(self):
self.assertEqual(
self.ctx['testModule'].getOrganization(),
'AgentX Working Group\n',
'bad ORGANIZATION'
)
def testModuleIdentityRevisions(self):
self.assertEqual(
self.ctx['testModule'].getRevisions(),
('2000-01-10 00:00',),
'bad REVISIONS'
)
# TODO: pysnmp does not implement .getRevisionsDescriptions()
# self.assertEqual(
# self.ctx['testModule'].getRevisionsDescriptions(),
# ('Initial version published as RFC 2742.',),
# 'bad REVISIONS'
# )
def testModuleIdentityContactInfo(self):
self.assertEqual(
self.ctx['testModule'].getContactInfo(),
'WG-email: [email protected]\n',
'bad CONTACT-INFO'
)
def testModuleIdentityDescription(self):
self.assertEqual(
self.ctx['testModule'].getDescription(),
'This is the MIB module for the SNMP\n',
'bad DESCRIPTION'
)
def testModuleIdentityClass(self):
self.assertEqual(
self.ctx['testModule'].__class__.__name__,
'ModuleIdentity',
'bad SYNTAX class'
)
suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__])
if __name__ == '__main__':
unittest.TextTestRunner(verbosity=2).run(suite)