Skip to content

Commit

Permalink
test: Organise cvlib context tests better
Browse files Browse the repository at this point in the history
Move cvlib context tests to conform with general testing layout

Change-Id: Ia91c2b04c616d60d2297153502d63962eccfd2b6
  • Loading branch information
cianmcgrath committed Apr 15, 2024
1 parent 0f58b1d commit a723f10
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,48 +11,14 @@
ActionContext,
Context,
Device,
User,
Logger,
LoggingLevel
User
)

from cloudvision.cvlib.exceptions import (
DeviceCommandsFailed,
InvalidContextException
)

loggingTestCases = [
("critical_logging", LoggingLevel.Critical, 1),
("trace_logging", LoggingLevel.Trace, 6)
]


@pytest.mark.parametrize('name, logLevel, expectedLogCalls', loggingTestCases)
def test_logging(name, logLevel, expectedLogCalls):

def alog(a, b, c, d):
pass

logCalls = 0

def log(a, b):
nonlocal logCalls
logCalls += 1

logger = Logger(alog, log, log, log, log, log, log)
ctx = Context(
user=User("test_user", "123"),
logger=logger
)
ctx.setLoggingLevel(logLevel)
ctx.trace("logTrace")
ctx.debug("logDebug")
ctx.info("logInfo")
ctx.warning("logWarning")
ctx.error("logError")
ctx.critical("logCritical")
assert logCalls == expectedLogCalls


device_no_host = Device(ip="123.456.789", deviceId="JPE123456",
deviceMac="00-B0-D0-63-C2-26")
Expand Down
44 changes: 44 additions & 0 deletions test/cvlib/context/test_logging.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Copyright (c) 2024 Arista Networks, Inc.
# Use of this source code is governed by the Apache License 2.0
# that can be found in the COPYING file.

import pytest

from cloudvision.cvlib import (
Context,
User,
Logger,
LoggingLevel
)

loggingTestCases = [
("critical_logging", LoggingLevel.Critical, 1),
("trace_logging", LoggingLevel.Trace, 6)
]


@pytest.mark.parametrize('name, logLevel, expectedLogCalls', loggingTestCases)
def test_logging(name, logLevel, expectedLogCalls):

def alog(a, b, c, d):
pass

logCalls = 0

def log(a, b):
nonlocal logCalls
logCalls += 1

logger = Logger(alog, log, log, log, log, log, log)
ctx = Context(
user=User("test_user", "123"),
logger=logger
)
ctx.setLoggingLevel(logLevel)
ctx.trace("logTrace")
ctx.debug("logDebug")
ctx.info("logInfo")
ctx.warning("logWarning")
ctx.error("logError")
ctx.critical("logCritical")
assert logCalls == expectedLogCalls

0 comments on commit a723f10

Please sign in to comment.