forked from etingof/pysnmp
-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added more test cases and cleaned up.
- Loading branch information
Showing
4 changed files
with
59 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
|
||
```bash | ||
poetry env use 3.12 | ||
poetry env info --path | ||
``` | ||
|
||
## Bump Version Number | ||
|
11 changes: 11 additions & 0 deletions
11
tests/smi/manager/test_convert-between-pdu-varbinds-and-mib-objects.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 == () |