Skip to content

Commit

Permalink
Added more test cases and cleaned up.
Browse files Browse the repository at this point in the history
  • Loading branch information
lextm committed Jan 13, 2024
1 parent 6a841e0 commit 6521c80
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 1 deletion.
6 changes: 5 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{
"restructuredtext.syntaxHighlighting.disabled": true
"python.testing.pytestArgs": [
"tests"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
}
1 change: 1 addition & 0 deletions Development.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

```bash
poetry env use 3.12
poetry env info --path
```

## Bump Version Number
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import pytest
from unittest.mock import patch
from pysnmp.smi import builder, view, rfc1902, error

def test_addAsn1MibSource():
mibBuilder = builder.MibBuilder()
mibView = view.MibViewController(mibBuilder)
mibVar = rfc1902.ObjectIdentity("IF-MIB", "ifInOctets", 1)
mibVar.addAsn1MibSource('https://mibs.pysnmp.com/asn1/@mib@')
mibVar.resolveWithMib(mibView)
assert mibVar.prettyPrint() == 'IF-MIB::ifInOctets.1'
42 changes: 42 additions & 0 deletions tests/smi/manager/test_mib-tree-inspection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import pytest
from pysnmp.smi import builder, view

mibBuilder = builder.MibBuilder()
mibBuilder.addMibSources(builder.DirMibSource("/opt/pysnmp_mibs"))
mibBuilder.loadModules(
"SNMPv2-MIB", "SNMP-FRAMEWORK-MIB", "SNMP-COMMUNITY-MIB", "IP-MIB"
)
mibView = view.MibViewController(mibBuilder)

def test_getNodeName_by_OID():
oid, label, suffix = mibView.getNodeName((1, 3, 6, 1, 2, 1, 1, 1))
assert oid == (1, 3, 6, 1, 2, 1, 1, 1)
assert label == ('iso', 'org', 'dod', 'internet', 'mgmt', 'mib-2', 'system', 'sysDescr')
assert suffix == ()

def test_getNodeName_by_label():
oid, label, suffix = mibView.getNodeName((1, 3, 6, 1, 2, "mib-2", 1, "sysDescr"))
assert oid == (1, 3, 6, 1, 2, 1, 1, 1)
assert label == ('iso', 'org', 'dod', 'internet', 'mgmt', 'mib-2', 'system', 'sysDescr')
assert suffix == ()

def test_getNodeName_by_symbol_description():
oid, label, suffix = mibView.getNodeName(("sysDescr",))
assert oid == (1, 3, 6, 1, 2, 1, 1, 1)
assert label == ('iso', 'org', 'dod', 'internet', 'mgmt', 'mib-2', 'system', 'sysDescr')
assert suffix == ()

def test_getNodeName_by_symbol_description_with_module_name():
oid, label, suffix = mibView.getNodeName(("snmpEngineID",), "SNMP-FRAMEWORK-MIB")
assert oid == (1, 3, 6, 1, 6, 3, 10, 2, 1, 1)
assert label == ('iso', 'org', 'dod', 'internet', 'snmpV2', 'snmpModules', 'snmpFrameworkMIB', 'snmpFrameworkMIBObjects', 'snmpEngine', 'snmpEngineID')
assert suffix == ()

(mibNode,) = mibBuilder.importSymbols("SNMP-FRAMEWORK-MIB", "snmpEngineID")
assert mibNode.syntax.prettyPrint() != ''

def test_getNodeName_by_symbol_location_lookup_by_name():
modName, symName, suffix = mibView.getNodeLocation(("snmpCommunityEntry",))
assert modName == "SNMP-COMMUNITY-MIB"
assert symName == "snmpCommunityEntry"
assert suffix == ()

0 comments on commit 6521c80

Please sign in to comment.