Skip to content

Commit

Permalink
Improved some test cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
lextm committed Sep 6, 2024
1 parent 9e64aad commit ce8faf0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
4 changes: 2 additions & 2 deletions tests/hlapi/asyncio/manager/cmdgen/test_v1_next.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ async def test_v1_next():
with Slim(1) as slim:
errorIndication, errorStatus, errorIndex, varBinds = await slim.next(
"public",
"localhost",
AGENT_PORT,
"localhost", # "demo.pysnmp.com",
AGENT_PORT, # 161,
ObjectType(
ObjectIdentity("SNMPv2-MIB", "sysDescr", 0).loadMibs("PYSNMP-MIB")
),
Expand Down
4 changes: 2 additions & 2 deletions tests/hlapi/asyncio/manager/cmdgen/test_v2c_next.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ async def test_v2_next():
with Slim() as slim:
errorIndication, errorStatus, errorIndex, varBinds = await slim.next(
"public",
"localhost",
AGENT_PORT,
"localhost", # "demo.pysnmp.com",
AGENT_PORT, # 161,
ObjectType(ObjectIdentity("SNMPv2-MIB", "sysDescr", 0)),
)

Expand Down
16 changes: 12 additions & 4 deletions tests/manager_context.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# manager_context.py
from typing import Tuple


from pysnmp.entity.rfc3413 import ntfrcv
from pysnmp.hlapi.v3arch.asyncio import *
from pysnmp.carrier.asyncio.dgram import udp
Expand All @@ -12,7 +15,7 @@
MANAGER_PORT = 1622


async def start_manager() -> SnmpEngine:
async def start_manager() -> Tuple[SnmpEngine, ntfrcv.NotificationReceiver]:
# Create SNMP engine
snmpEngine = engine.SnmpEngine()

Expand Down Expand Up @@ -68,7 +71,7 @@ def cbFun(
print(f"{name.prettyPrint()} = {val.prettyPrint()}")

# Register SNMP Application at the SNMP engine
ntfrcv.NotificationReceiver(snmpEngine, cbFun)
receiver = ntfrcv.NotificationReceiver(snmpEngine, cbFun)

# Run I/O dispatcher which would receive queries and send confirmations
snmpEngine.transportDispatcher.jobStarted(1) # this job would never finish
Expand All @@ -79,7 +82,7 @@ def cbFun(
await asyncio.sleep(1)

# return the engine
return snmpEngine
return snmpEngine, receiver


class ManagerContextManager:
Expand All @@ -96,10 +99,15 @@ class ManagerContextManager:
Note: The `start_manager()` function and the `transportDispatcher` attribute are not defined in this code snippet.
"""

manager: SnmpEngine
receiver: ntfrcv.NotificationReceiver

async def __aenter__(self):
self.manager = await start_manager()
self.manager, self.receiver = await start_manager()
return self.manager

async def __aexit__(self, exc_type, exc_val, exc_tb):
self.receiver.close(self.manager)

self.manager.transportDispatcher.jobFinished(1)
self.manager.closeDispatcher()

0 comments on commit ce8faf0

Please sign in to comment.