Skip to content

Commit

Permalink
fixup unit test for 681a0bc
Browse files Browse the repository at this point in the history
  • Loading branch information
totaam committed Jan 13, 2024
1 parent 681a0bc commit 30d1084
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions tests/unittests/unit/net/common_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,28 @@

from xpra.util.env import OSEnvContext
from xpra.net import common
from xpra.log import set_global_logging_handler

class TestLogPackets(unittest.TestCase):

def mlp(sending, packet_type, *args) -> None:
packet = [packet_type] + list(args)
common.may_log_packet(sending, packet_type, packet)


class TestLogPackets(unittest.TestCase):

def info(self, *args):
self.log_messages.append(args)

def setup_log_intercept(self):
#get_log_packets, may_log_packet, log
# get_log_packets, may_log_packet, log
self.log_messages = []
common.log = self
set_global_logging_handler(self.info)

def lm(self, n=0):
assert len(self.log_messages)==n, "expected %i log messages, got %i" % (n, len(self.log_messages))
assert len(self.log_messages) == n, "expected %i log messages, got %i" % (n, len(self.log_messages))
self.log_messages = []

def t(self, sending, packet_type, *args):
packet = [packet_type] + list(args)
return common.may_log_packet(sending, packet_type, packet)


def test_env_log(self):
with OSEnvContext():
os.environ["XPRA_LOG_PACKETS"] = "info,ping,-bell"
Expand All @@ -40,12 +41,14 @@ def test_env_log(self):
logged = 1+inc
for sending in (True, False):
self.setup_log_intercept()
def t(packet_type, *args):
return self.t(sending, packet_type, *args) # pylint: disable=cell-var-from-loop

def t(packet_type, *args) -> None:
mlp(sending, packet_type, *args) # pylint: disable=cell-var-from-loop

self.lm()
t("hello", {})
self.lm(inc)
t("info", {"foo" : "bar"})
t("info", {"foo": "bar"})
self.lm(logged)
t("ping", 1, 2, 3)
self.lm(logged)
Expand All @@ -54,21 +57,22 @@ def t(packet_type, *args):
t("bell", 100)
self.lm(inc)
t("info", "0"*common.PACKET_LOG_MAX_SIZE*2)
assert len(self.log_messages[-1])<=common.PACKET_LOG_MAX_SIZE
assert len(self.log_messages[-1]) <= common.PACKET_LOG_MAX_SIZE
self.lm(logged)

def test_default_nolog(self):
with OSEnvContext():
os.environ.pop("XPRA_LOG_PACKETS", None)
self.setup_log_intercept()
for pt in common.PACKET_TYPES:
self.t(True, pt, (1, 2))
self.t(False, pt, (1, 2))
mlp(True, pt, (1, 2))
mlp(False, pt, (1, 2))
self.lm(0)


def main():
unittest.main()


if __name__ == '__main__':
main()

0 comments on commit 30d1084

Please sign in to comment.