From daba550c22a4e4d39ad9f3dbb003c3a4a7209bdd Mon Sep 17 00:00:00 2001 From: James Le Cuirot Date: Fri, 24 Dec 2021 12:49:12 +0000 Subject: [PATCH 01/21] Respect XDG_RUNTIME_DIR environment variable when running tests Gentoo sets XDG_RUNTIME_DIR to an isolated directory when building and testing packages, so we don't expect test files to be written to the fallback location of /tmp. --- tests/unittests/unit/process_test_util.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/unittests/unit/process_test_util.py b/tests/unittests/unit/process_test_util.py index e41535b2d..17d695fe5 100755 --- a/tests/unittests/unit/process_test_util.py +++ b/tests/unittests/unit/process_test_util.py @@ -167,6 +167,7 @@ class ProcessTestUtil(unittest.TestCase): "XAUTHORITY", "PWD", "PYTHONPATH", "SYSTEMROOT", "DBUS_SESSION_BUS_ADDRESS", + "XDG_RUNTIME_DIR", )) log("get_default_run_env() env(%s)=%s", repr_ellipsized(cls.default_env), env) env["NO_AT_BRIDGE"] = "1" -- 2.34.1 From 41111fbf1052fa7c9872504252f605a3bade4dd4 Mon Sep 17 00:00:00 2001 From: totaam Date: Tue, 21 Dec 2021 13:06:55 +0700 Subject: [PATCH 02/21] the ssh-port does not need special treatment --- xpra/client/gtk_base/client_launcher.py | 2 +- xpra/net/ssh.py | 6 +++--- xpra/scripts/parsing.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/xpra/client/gtk_base/client_launcher.py b/xpra/client/gtk_base/client_launcher.py index 691ab6b2d..cd64fa257 100755 --- a/xpra/client/gtk_base/client_launcher.py +++ b/xpra/client/gtk_base/client_launcher.py @@ -720,7 +720,7 @@ class ApplicationWindow: password = username[ppos+1:] username = username[:ppos] if self.config.ssh_port and self.config.ssh_port!=22: - params["ssh-port"] = self.config.ssh_port + params["port"] = self.config.ssh_port ssh_cmd = parse_ssh_string(self.config.ssh) ssh_cmd_0 = ssh_cmd[0].strip().lower() self.is_putty = ssh_cmd_0.endswith("plink") or ssh_cmd_0.endswith("plink.exe") diff --git a/xpra/net/ssh.py b/xpra/net/ssh.py index 899d162b0..f9445c0dc 100644 --- a/xpra/net/ssh.py +++ b/xpra/net/ssh.py @@ -156,7 +156,7 @@ class SSHProxyCommandConnection(SSHSocketConnection): def ssh_paramiko_connect_to(display_desc): #plain socket attributes: host = display_desc["host"] - port = display_desc.get("ssh-port", 22) + port = display_desc.get("port", 22) #ssh and command attributes: username = display_desc.get("username") or get_username() if "proxy_host" in display_desc: @@ -204,7 +204,7 @@ def ssh_paramiko_connect_to(display_desc): host = host_config.get("hostname", host) if "username" not in display_desc: username = host_config.get("user", username) - if "ssh-port" not in display_desc: + if "port" not in display_desc: port = host_config.get("port", port) try: port = int(port) @@ -944,7 +944,7 @@ def ssh_exec_connect_to(display_desc, opts=None, debug_cb=None, ssh_fail_cb=ssh_ except Exception as e: print("error trying to stop ssh tunnel process: %s" % e) host = display_desc["host"] - port = display_desc.get("ssh-port", 22) + port = display_desc.get("port", 22) username = display_desc.get("username") display = display_desc.get("display") info = { diff --git a/xpra/scripts/parsing.py b/xpra/scripts/parsing.py index c91b0cf5f..421ff29d7 100755 --- a/xpra/scripts/parsing.py +++ b/xpra/scripts/parsing.py @@ -543,7 +543,7 @@ def parse_display_name(error_cb, opts, display_name, find_session_by_name=False) _parse_host_string(host, 22) ssh_port = desc.pop("port", 22) if ssh_port!=22: - desc["ssh-port"] = ssh_port + desc["port"] = ssh_port username = desc.get("username") password = desc.get("password") host = desc.get("host") -- 2.34.1 From e57dede8ca73b12a1e4d17231651ca7005240c58 Mon Sep 17 00:00:00 2001 From: totaam Date: Mon, 20 Dec 2021 11:44:50 +0700 Subject: [PATCH 03/21] silence works at module level --- tests/unittests/unit/server/mixins/audio_test.py | 14 +++++++------- .../unit/server/mixins/child_command_test.py | 8 +++++--- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/tests/unittests/unit/server/mixins/audio_test.py b/tests/unittests/unit/server/mixins/audio_test.py index 72e7ba47d..f4f1b93bb 100755 --- a/tests/unittests/unit/server/mixins/audio_test.py +++ b/tests/unittests/unit/server/mixins/audio_test.py @@ -16,23 +16,23 @@ from unit.server.mixins.servermixintest_util import ServerMixinTest class AudioMixinTest(ServerMixinTest): def test_audio(self): - from xpra.server.mixins.audio_server import AudioServer, soundlog + from xpra.server.mixins import audio_server from xpra.server.source.audio_mixin import AudioMixin - from xpra.sound.gstreamer_util import CODEC_ORDER, log + from xpra.sound import gstreamer_util opts = AdHocStruct() opts.sound_source = "" opts.speaker = "on" - opts.speaker_codec = CODEC_ORDER + opts.speaker_codec = gstreamer_util.CODEC_ORDER opts.microphone = "on" opts.microphone_codec = ["mp3"] opts.pulseaudio = False opts.pulseaudio_command = "/bin/true" opts.pulseaudio_configure_commands = [] opts.av_sync = True - with silence_info(soundlog): - self._test_mixin_class(AudioServer, opts, { + with silence_info(audio_server, "soundlog"): + self._test_mixin_class(audio_server.AudioServer, opts, { "sound.receive" : True, - "sound.decoders" : CODEC_ORDER, + "sound.decoders" : gstreamer_util.CODEC_ORDER, }, AudioMixin) #init runs in a thread, give it time: time.sleep(2) @@ -40,7 +40,7 @@ class AudioMixinTest(ServerMixinTest): print("no speaker codecs available, test skipped") return codec = self.mixin.speaker_codecs[0] - with silence_info(log): + with silence_info(gstreamer_util): self.handle_packet(("sound-control", "start", codec)) time.sleep(1) self.handle_packet(("sound-control", "fadeout")) diff --git a/tests/unittests/unit/server/mixins/child_command_test.py b/tests/unittests/unit/server/mixins/child_command_test.py index 68cbb797b..86e9ebe35 100755 --- a/tests/unittests/unit/server/mixins/child_command_test.py +++ b/tests/unittests/unit/server/mixins/child_command_test.py @@ -26,13 +26,15 @@ class ChildCommandMixinTest(ServerMixinTest): self.do_test_command_server() def do_test_command_server(self): - from xpra.server.mixins.child_command_server import ChildCommandServer, log + from xpra.server.mixins import child_command_server opts = AdHocStruct() opts.exit_with_children = True opts.terminate_children = True opts.start_new_commands = True opts.start = [] opts.start_child = [] + opts.start_late = [] + opts.start_child_late = [] opts.start_after_connect = [] opts.start_child_after_connect = [] opts.start_on_connect = [] @@ -47,7 +49,7 @@ class ChildCommandMixinTest(ServerMixinTest): def noop(): pass def _ChildCommandServer(): - ccs = ChildCommandServer() + ccs = child_command_server.ChildCommandServer() ccs.setup_menu_watcher = noop return ccs self._test_mixin_class(_ChildCommandServer, opts) @@ -82,7 +84,7 @@ class ChildCommandMixinTest(ServerMixinTest): assert proc_info.get("name")=="sleep" assert proc_info.get("dead") is False #send it a SIGINT: - with silence_info(log): + with silence_info(child_command_server): self.handle_packet(("command-signal", pid, "SIGINT")) time.sleep(1) self.mixin.child_reaper.poll() -- 2.34.1 From 683724fdda8243767a6b14907f54475fe842b446 Mon Sep 17 00:00:00 2001 From: totaam Date: Mon, 20 Dec 2021 11:44:13 +0700 Subject: [PATCH 04/21] changes needed to run the unit tests --- xpra/server/mixins/child_command_server.py | 4 +++- xpra/server/mixins/display_manager.py | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/xpra/server/mixins/child_command_server.py b/xpra/server/mixins/child_command_server.py index a770487a4..db2a41aeb 100644 --- a/xpra/server/mixins/child_command_server.py +++ b/xpra/server/mixins/child_command_server.py @@ -9,6 +9,8 @@ import shlex import os.path from time import monotonic +from gi.repository import GLib + from xpra.platform.features import COMMAND_SIGNALS from xpra.child_reaper import getChildReaper, reaper_cleanup from xpra.os_util import ( @@ -66,7 +68,7 @@ class ChildCommandServer(StubServerMixin): self.session_name = "" self.menu_provider = None #wait for main loop to run: - self.idle_add(self.late_start) + GLib.idle_add(self.late_start) def late_start(self): def do_late_start(): diff --git a/xpra/server/mixins/display_manager.py b/xpra/server/mixins/display_manager.py index 038fcf62a..7d845d3e2 100644 --- a/xpra/server/mixins/display_manager.py +++ b/xpra/server/mixins/display_manager.py @@ -41,6 +41,9 @@ class DisplayManager(StubServerMixin): self.default_dpi = int(opts.dpi) self.bit_depth = self.get_display_bit_depth() + def get_display_bit_depth(self): + return 0 + def parse_hello(self, ss, caps, send_ui): if send_ui: -- 2.34.1 From 61f76ceca5dc659da9e275b415155fcbb2ad973b Mon Sep 17 00:00:00 2001 From: totaam Date: Mon, 20 Dec 2021 11:26:48 +0700 Subject: [PATCH 05/21] this function returns env values as bytes --- tests/unittests/unit/server/mixins/notification_test.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/unittests/unit/server/mixins/notification_test.py b/tests/unittests/unit/server/mixins/notification_test.py index c8047ef8e..ac9e8871d 100755 --- a/tests/unittests/unit/server/mixins/notification_test.py +++ b/tests/unittests/unit/server/mixins/notification_test.py @@ -29,13 +29,13 @@ class NotificationForwarderMixinTest(ServerMixinTest): dbus_pid, dbus_env = start_dbus("dbus-launch --sh-syntax --close-stderr") try: if dbus_env: - os.environ.update(dbus_env) + os.environb.update(dbus_env) - from xpra.server.mixins.notification_forwarder import NotificationForwarder, log + from xpra.server.mixins import notification_forwarder opts = AdHocStruct() opts.notifications = "yes" - with silence_info(log): - self._test_mixin_class(NotificationForwarder, opts) + with silence_info(notification_forwarder): + self._test_mixin_class(notification_forwarder.NotificationForwarder, opts) self.verify_packet_error(("notification-close", 1, "test", "hello")) self.verify_packet_error(("notification-action", 1)) self.handle_packet(("set-notify", False)) -- 2.34.1 From 4773624dda4b97046ea0860ad867942b72f528d3 Mon Sep 17 00:00:00 2001 From: totaam Date: Mon, 20 Dec 2021 11:18:15 +0700 Subject: [PATCH 06/21] silence loggers as module attributes --- .../unit/server/mixins/fileprint_test.py | 6 +++--- .../unit/server/mixins/logging_test.py | 8 +++---- .../unit/server/mixins/networkstate_test.py | 14 ++++++------- tests/unittests/unit/test_util.py | 21 ++++++++++--------- 4 files changed, 25 insertions(+), 24 deletions(-) diff --git a/tests/unittests/unit/server/mixins/fileprint_test.py b/tests/unittests/unit/server/mixins/fileprint_test.py index e10c96935..c91fc3ea5 100755 --- a/tests/unittests/unit/server/mixins/fileprint_test.py +++ b/tests/unittests/unit/server/mixins/fileprint_test.py @@ -23,7 +23,7 @@ class FilePrintMixinTest(ServerMixinTest): ] def test_fileprint(self): - from xpra.server.mixins.fileprint_server import FilePrintServer, printlog + from xpra.server.mixins import fileprint_server opts = AdHocStruct() opts.file_transfer = "yes" opts.file_size_limit = 10 @@ -36,8 +36,8 @@ class FilePrintMixinTest(ServerMixinTest): opts.add_printer_options = "" opts.postscript_printer = "" opts.pdf_printer = "" - with silence_info(printlog): - self._test_mixin_class(FilePrintServer, opts) + with silence_info(fileprint_server, "printlog"): + self._test_mixin_class(fileprint_server.FilePrintServer, opts) def main(): unittest.main() diff --git a/tests/unittests/unit/server/mixins/logging_test.py b/tests/unittests/unit/server/mixins/logging_test.py index 55007368f..c60019b0d 100755 --- a/tests/unittests/unit/server/mixins/logging_test.py +++ b/tests/unittests/unit/server/mixins/logging_test.py @@ -10,7 +10,7 @@ import unittest from unit.test_util import silence_error from xpra.util import AdHocStruct from xpra.server.source.stub_source_mixin import StubSourceMixin -from xpra.server.mixins.logging_server import LoggingServer, log +from xpra.server.mixins import logging_server from unit.server.mixins.servermixintest_util import ServerMixinTest @@ -31,7 +31,7 @@ class InputMixinTest(ServerMixinTest): def do_log(level, line): log_messages.append((level, line)) def _LoggingServer(): - ls = LoggingServer() + ls = logging_server.LoggingServer() ls.do_log = do_log return ls self._test_mixin_class(_LoggingServer, opts, {}, FakeSource) @@ -42,12 +42,12 @@ class InputMixinTest(ServerMixinTest): #multi-part: self.handle_packet(("logging", 20, ["multi", "messages"], time.time())) #invalid: - with silence_error(log): + with silence_error(logging_server): self.handle_packet(("logging", 20, nostr(), time.time())) def test_invalid(self): - l = LoggingServer() + l = logging_server.LoggingServer() opts = AdHocStruct() opts.remote_logging = "on" l.init(opts) diff --git a/tests/unittests/unit/server/mixins/networkstate_test.py b/tests/unittests/unit/server/mixins/networkstate_test.py index d48d1fa9f..81df3b2ca 100755 --- a/tests/unittests/unit/server/mixins/networkstate_test.py +++ b/tests/unittests/unit/server/mixins/networkstate_test.py @@ -18,7 +18,7 @@ class NetworkStateMixinTest(ServerMixinTest): def test_networkstate(self): with OSEnvContext(): os.environ["XPRA_PING_TIMEOUT"] = "1" - from xpra.server.mixins.networkstate_server import NetworkStateServer, MAX_BANDWIDTH_LIMIT, log, bandwidthlog + from xpra.server.mixins import networkstate_server from xpra.server.source.networkstate_mixin import NetworkStateMixin assert NetworkStateMixin.is_needed(typedict()) opts = AdHocStruct() @@ -26,8 +26,8 @@ class NetworkStateMixinTest(ServerMixinTest): opts.bandwidth_limit = "1Gbps" #the limit for all clients: capped_at = 1*1000*1000*1000 #=="1Gbps" - with silence_info(log): - self._test_mixin_class(NetworkStateServer, opts, {}, NetworkStateMixin) + with silence_info(networkstate_server): + self._test_mixin_class(networkstate_server.NetworkStateServer, opts, {}, NetworkStateMixin) self.assertEqual(capped_at, self.mixin.get_info().get("bandwidth-limit")) self.handle_packet(("ping", 10)) self.handle_packet(("ping", -1000)) @@ -47,14 +47,14 @@ class NetworkStateMixinTest(ServerMixinTest): pass else: raise Exception("should not allow %s (%s) as connection-data" % (v, type(v))) - with silence_info(bandwidthlog): + with silence_info(networkstate_server, "bandwidthlog"): self.handle_packet(("bandwidth-limit", 10*1024*1024)) def get_limit(): return self.source.get_info().get("bandwidth-limit", {}).get("setting", 0) self.assertEqual(10*1024*1024, get_limit()) - with silence_info(bandwidthlog): - self.handle_packet(("bandwidth-limit", MAX_BANDWIDTH_LIMIT+1)) - self.assertEqual(min(capped_at, MAX_BANDWIDTH_LIMIT), get_limit()) + with silence_info(networkstate_server, "bandwidthlog"): + self.handle_packet(("bandwidth-limit", networkstate_server.MAX_BANDWIDTH_LIMIT+1)) + self.assertEqual(min(capped_at, networkstate_server.MAX_BANDWIDTH_LIMIT), get_limit()) #test source: timeouts = [] def timeout(*args): diff --git a/tests/unittests/unit/test_util.py b/tests/unittests/unit/test_util.py index 9d1b8eeb7..c5289b7b5 100755 --- a/tests/unittests/unit/test_util.py +++ b/tests/unittests/unit/test_util.py @@ -5,14 +5,14 @@ # later version. See the file COPYING for details. -def silence_info(module): - return LoggerSilencer(module, ("info", )) +def silence_info(module, logger="log"): + return LoggerSilencer(module, ("info", ), logger) -def silence_warn(module): - return LoggerSilencer(module, ("warn", )) +def silence_warn(module, logger="log"): + return LoggerSilencer(module, ("warn", ), logger) -def silence_error(module): - return LoggerSilencer(module, ("error", )) +def silence_error(module, logger="log"): + return LoggerSilencer(module, ("error", ), logger) #to silence warnings triggered by the tests: from xpra.log import Logger @@ -27,14 +27,15 @@ class SilencedLogger(Logger): class LoggerSilencer: - def __init__(self, module, silence=("error", "warn", "info")): + def __init__(self, module, silence=("error", "warn", "info"), logger="log"): self.module = module + self.logger = logger self.silence = silence self.saved = None def __enter__(self): - self.saved = self.module.log - self.module.log = SilencedLogger(self.silence) + self.saved = getattr(self.module, self.logger) + setattr(self.module, self.logger, SilencedLogger(self.silence)) def __exit__(self, *_args): - self.module.log = self.saved + setattr(self.module, self.logger, self.saved) def __repr__(self): return "LoggerSilencer" -- 2.34.1 From 19540a6255124e4223fff9945d97e31c489b44ae Mon Sep 17 00:00:00 2001 From: totaam Date: Mon, 20 Dec 2021 10:41:05 +0700 Subject: [PATCH 07/21] log silencing works on modules now, not instances --- tests/unittests/unit/server/mixins/webcam_test.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/unittests/unit/server/mixins/webcam_test.py b/tests/unittests/unit/server/mixins/webcam_test.py index 873c08055..cf4d1107b 100755 --- a/tests/unittests/unit/server/mixins/webcam_test.py +++ b/tests/unittests/unit/server/mixins/webcam_test.py @@ -16,11 +16,12 @@ from unit.server.mixins.servermixintest_util import ServerMixinTest class WebcamMixinTest(ServerMixinTest): def test_webcam(self): - from xpra.server.mixins.webcam_server import WebcamServer, log as serverlog + from xpra.server.mixins import webcam_server + from xpra.server.mixins.webcam_server import WebcamServer from xpra.server.source.webcam_mixin import WebcamMixin, log as sourcelog opts = AdHocStruct() opts.webcam = "yes" - with silence_info(serverlog): + with silence_info(webcam_server): self._test_mixin_class(WebcamServer, opts, {}, WebcamMixin) if self.mixin.get_info(self.protocol).get("webcam", {}).get("virtual-video-devices", 0)>0: with silence_info(sourcelog): -- 2.34.1 From e474535363be981d98eb90c0341d5f9f647a05a0 Mon Sep 17 00:00:00 2001 From: totaam Date: Mon, 20 Dec 2021 10:34:10 +0700 Subject: [PATCH 08/21] use dummy stub function for tests --- xpra/server/mixins/encoding_server.py | 2 +- xpra/server/mixins/stub_server_mixin.py | 6 ++++++ xpra/server/mixins/window_server.py | 2 +- xpra/server/server_core.py | 5 ++++- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/xpra/server/mixins/encoding_server.py b/xpra/server/mixins/encoding_server.py index 1d3268e46..85450be86 100644 --- a/xpra/server/mixins/encoding_server.py +++ b/xpra/server/mixins/encoding_server.py @@ -60,7 +60,7 @@ class EncodingServer(StubServerMixin): #try to load the fast jpeg encoders: load_codec("enc_jpeg") self.init_encodings() - self.init_thread_callbacks.append(self.reinit_encodings) + self.add_init_thread_callback(self.reinit_encodings) def reinit_encodings(self): self.init_encodings() diff --git a/xpra/server/mixins/stub_server_mixin.py b/xpra/server/mixins/stub_server_mixin.py index 3792c4405..44e40f8b9 100644 --- a/xpra/server/mixins/stub_server_mixin.py +++ b/xpra/server/mixins/stub_server_mixin.py @@ -28,6 +28,12 @@ class StubServerMixin: Initialize state attributes. """ + def add_init_thread_callback(self, callback): + """ + Adds a callback that will be executed + after the init thread has completed. + """ + def reset_focus(self): """ diff --git a/xpra/server/mixins/window_server.py b/xpra/server/mixins/window_server.py index beff70aec..112ea921d 100644 --- a/xpra/server/mixins/window_server.py +++ b/xpra/server/mixins/window_server.py @@ -50,7 +50,7 @@ class WindowServer(StubServerMixin): def setup(self): self.load_existing_windows() - self.init_thread_callbacks.append(self.reinit_window_encoders) + self.add_init_thread_callback(self.reinit_window_encoders) def cleanup(self): for window in tuple(self._window_to_id.keys()): diff --git a/xpra/server/server_core.py b/xpra/server/server_core.py index 5a80093fa..67f18fe6d 100644 --- a/xpra/server/server_core.py +++ b/xpra/server/server_core.py @@ -405,10 +405,13 @@ class ServerCore: log.error("Error in initialization thread callback %s", cb) log.error(" %s", e) + def add_init_thread_callback(self, callback): + self.init_thread_callbacks.append(callback) + def after_threaded_init(self, callback): with self.init_thread_lock: if self.init_thread is None or self.init_thread.is_alive(): - self.init_thread_callbacks.append(callback) + self.add_init_thread_callback(callback) else: callback() -- 2.34.1 From c31402d7dbc3db14c2f2740baf6684c02ff35702 Mon Sep 17 00:00:00 2001 From: totaam Date: Mon, 20 Dec 2021 09:02:45 +0700 Subject: [PATCH 09/21] remove unused function, 'dbus-launch' is a valid option --- tests/unittests/unit/server/dbus_test.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/unittests/unit/server/dbus_test.py b/tests/unittests/unit/server/dbus_test.py index c4f5762ba..10e5431b1 100755 --- a/tests/unittests/unit/server/dbus_test.py +++ b/tests/unittests/unit/server/dbus_test.py @@ -26,8 +26,6 @@ class DBUSTest(unittest.TestCase): def test_exception_wrap(self): from xpra.server.dbus import dbus_common dbus_common.log = FakeLogger() - def r1(): - return 1 def rimporterror(): raise ImportError() def rfail(): @@ -57,7 +55,7 @@ class DBUSTest(unittest.TestCase): f("no") f("0") os.environ["DBUS_SESSION_BUS_ADDRESS"] = "whatever" - f("dbus-launch") + w("dbus-launch") rm() f("this-is-not-a-valid-command") f("shlex-parsing-error '") -- 2.34.1 From 213597ec7741d09229c2162be7054154f98ab5b9 Mon Sep 17 00:00:00 2001 From: totaam Date: Mon, 20 Dec 2021 22:15:36 +0700 Subject: [PATCH 10/21] fixup use of log silencer --- .../unit/notifications/common_test.py | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/unittests/unit/notifications/common_test.py b/tests/unittests/unit/notifications/common_test.py index 6500e28c6..f5af8f795 100755 --- a/tests/unittests/unit/notifications/common_test.py +++ b/tests/unittests/unit/notifications/common_test.py @@ -8,34 +8,34 @@ import os import tempfile import unittest -from xpra.notifications.common import parse_image_data, parse_image_path, log - +from xpra.notifications import common from unit.test_util import silence_error class TestCommon(unittest.TestCase): def test_parse_image_data(self): - with silence_error(log): - assert parse_image_data(None) is None - assert parse_image_data((1, 2, 3)) is None - assert parse_image_data((1, 2, 3, 4, 5, 6, 7)) is None - assert parse_image_data((10, 10, 40, True, 32, 4, b"0"*40*10)) is not None - assert parse_image_data((10, 10, 40, False, 24, 4, b"0"*40*10)) is not None - assert parse_image_data((10, 10, 30, False, 24, 3, b"0"*30*10)) is not None + p = common.parse_image_data + with silence_error(common): + assert p(None) is None + assert p((1, 2, 3)) is None + assert p((1, 2, 3, 4, 5, 6, 7)) is None + assert p((10, 10, 40, True, 32, 4, b"0"*40*10)) is not None + assert p((10, 10, 40, False, 24, 4, b"0"*40*10)) is not None + assert p((10, 10, 30, False, 24, 3, b"0"*30*10)) is not None def test_parse_image_path(self): from xpra.platform.paths import get_icon_filename filename = get_icon_filename("xpra") - assert parse_image_path(filename) is not None + assert common.parse_image_path(filename) is not None f = tempfile.NamedTemporaryFile(prefix="test-invalid-file", delete=False) try: f.file.write(b"0000000000000001111111111111111111111") f.file.flush() f.close() for x in ("", None, "/invalid-path", f.name): - with silence_error(log): - assert parse_image_path(x) is None + with silence_error(common): + assert common.parse_image_path(x) is None finally: os.unlink(f.name) -- 2.34.1 From f6823582e858f6e4dc92677fe9f37af83f77537c Mon Sep 17 00:00:00 2001 From: totaam Date: Mon, 20 Dec 2021 22:46:27 +0700 Subject: [PATCH 11/21] match refactoring --- tests/unittests/unit/net/rfb/rfb_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unittests/unit/net/rfb/rfb_test.py b/tests/unittests/unit/net/rfb/rfb_test.py index 815006aac..60f5c73a4 100755 --- a/tests/unittests/unit/net/rfb/rfb_test.py +++ b/tests/unittests/unit/net/rfb/rfb_test.py @@ -9,7 +9,7 @@ import unittest from xpra.util import AdHocStruct from xpra.codecs.image_wrapper import ImageWrapper -from xpra.net.rfb.rfb_source import RFBSource +from xpra.server.rfb.rfb_source import RFBSource def noop(*_args): pass -- 2.34.1 From 21927912e4fa4cbc67abbdddaa6841736e15f197 Mon Sep 17 00:00:00 2001 From: totaam Date: Tue, 21 Dec 2021 20:15:42 +0700 Subject: [PATCH 12/21] match refactoring: we have to initialize encoders and compressors --- tests/unittests/unit/net/subprocess_wrapper_test.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/unittests/unit/net/subprocess_wrapper_test.py b/tests/unittests/unit/net/subprocess_wrapper_test.py index fd266722e..9c9d3dd76 100755 --- a/tests/unittests/unit/net/subprocess_wrapper_test.py +++ b/tests/unittests/unit/net/subprocess_wrapper_test.py @@ -83,6 +83,13 @@ GObject.type_register(TestCallee) class SubprocessWrapperTest(unittest.TestCase): + @classmethod + def setUpClass(cls): + from xpra.net import packet_encoding + packet_encoding.init_all() + from xpra.net import compression + compression.init_compressors("none") + def test_loopback_caller(self): mainloop = GLib.MainLoop() lp = loopback_process() -- 2.34.1 From 1bc91c605f1f7808ce759d375b27d40db59da7d1 Mon Sep 17 00:00:00 2001 From: totaam Date: Tue, 21 Dec 2021 19:43:35 +0700 Subject: [PATCH 13/21] match protocol, compressors and encoders refactoring --- tests/unittests/unit/net/protocol_test.py | 57 ++++++++++++++--------- 1 file changed, 34 insertions(+), 23 deletions(-) diff --git a/tests/unittests/unit/net/protocol_test.py b/tests/unittests/unit/net/protocol_test.py index 923e586c2..220207df7 100755 --- a/tests/unittests/unit/net/protocol_test.py +++ b/tests/unittests/unit/net/protocol_test.py @@ -10,13 +10,16 @@ import unittest from gi.repository import GLib from xpra.util import csv, envint, envbool -from xpra.net.protocol import Protocol, verify_packet, log +from xpra.net import protocol +from xpra.net.protocol import Protocol, verify_packet from xpra.net.bytestreams import Connection from xpra.net.compression import Compressed from xpra.log import Logger from unit.test_util import silence_error +log = protocol.log + TIMEOUT = envint("XPRA_PROTOCOL_TEST_TIMEOUT", 20) PROFILING = envbool("XPRA_PROTOCOL_PROFILING", False) SHOW_PERF = envbool("XPRA_SHOW_PERF", False) @@ -83,7 +86,15 @@ def make_profiling_protocol_class(protocol_class): class ProtocolTest(unittest.TestCase): protocol_class = Protocol - def make_memory_protocol(self, data=(b""), read_buffer_size=1, hangup_delay=0, process_packet_cb=noop, get_packet_cb=nodata): + @classmethod + def setUpClass(cls): + from xpra.net import packet_encoding + packet_encoding.init_all() + from xpra.net import compression + compression.init_all() + + def make_memory_protocol(self, data=(b""), read_buffer_size=1, hangup_delay=0, + process_packet_cb=noop, get_packet_cb=nodata): conn = FastMemoryConnection(data) if PROFILING: pc = make_profiling_protocol_class(self.protocol_class) @@ -104,7 +115,7 @@ class ProtocolTest(unittest.TestCase): assert verify_packet(x) is False assert verify_packet(["foo", 1]) is True assert verify_packet(["foo", [1,2,3], {1:2}]) is True - with silence_error(log): + with silence_error(protocol): assert verify_packet(["no-floats test", 1.1]) is False, "floats are not allowed" assert verify_packet(["foo", [None], {1:2}]) is False, "no None values" assert verify_packet(["foo", [1,2,3], {object() : 2}]) is False @@ -116,19 +127,19 @@ class ProtocolTest(unittest.TestCase): def do_test_invalid_data(self, data): errs = [] - protocol = self.make_memory_protocol(data) + proto = self.make_memory_protocol(data) def check_failed(): - if not protocol.is_closed(): + if not proto.is_closed(): errs.append("protocol not closed") - if protocol.input_packetcount>0: - errs.append("processed %i packets" % protocol.input_packetcount) - if protocol.input_raw_packetcount==0: + if proto.input_packetcount>0: + errs.append("processed %i packets" % proto.input_packetcount) + if proto.input_raw_packetcount==0: errs.append("not read any raw packets") loop.quit() loop = GLib.MainLoop() GLib.timeout_add(500, check_failed) GLib.timeout_add(TIMEOUT*1000, loop.quit) - protocol.start() + proto.start() loop.run() assert not errs, "%s" % csv(errs) @@ -180,16 +191,16 @@ class ProtocolTest(unittest.TestCase): parsed_packets = [] def process_packet_cb(proto, packet): #log.info("process_packet_cb%s", packet[0]) - if packet[0]==Protocol.CONNECTION_LOST: + if packet[0]==protocol.CONNECTION_LOST: loop.quit() else: parsed_packets.append(packet[0]) #run the protocol on this data: loop = GLib.MainLoop() GLib.timeout_add(TIMEOUT*1000, loop.quit) - protocol = self.make_memory_protocol(ldata, read_buffer_size=65536, process_packet_cb=process_packet_cb) + proto = self.make_memory_protocol(ldata, read_buffer_size=65536, process_packet_cb=process_packet_cb) start = time.monotonic() - protocol.start() + proto.start() loop.run() end = time.monotonic() assert len(parsed_packets)==N*3, "expected to parse %i packets but got %i" % (N*3, len(parsed_packets)) @@ -224,23 +235,23 @@ class ProtocolTest(unittest.TestCase): packet = many.pop(0) return (packet, None, None, None, False, True, False) except IndexError: - protocol.close() + proto.close() return (None, ) def process_packet_cb(proto, packet): - if packet[0]==Protocol.CONNECTION_LOST: + if packet[0]==protocol.CONNECTION_LOST: GLib.timeout_add(1000, loop.quit) - protocol = self.make_memory_protocol(None, process_packet_cb=process_packet_cb, get_packet_cb=get_packet_cb) - conn = protocol._conn + proto = self.make_memory_protocol(None, process_packet_cb=process_packet_cb, get_packet_cb=get_packet_cb) + conn = proto._conn loop = GLib.MainLoop() GLib.timeout_add(TIMEOUT*1000, loop.quit) - protocol.enable_compressor("lz4") - protocol.enable_encoder("rencode") - protocol.start() - protocol.source_has_more() + proto.enable_compressor("lz4") + proto.enable_encoder("rencode") + proto.start() + proto.source_has_more() start = time.monotonic() loop.run() end = time.monotonic() - assert protocol.is_closed() + assert proto.is_closed() log("protocol: %s", protocol) log("%s write-data=%s", conn, len(conn.write_data)) total_size = sum(len(packet) for packet in conn.write_data) @@ -248,9 +259,9 @@ class ProtocolTest(unittest.TestCase): log("bytes=%s, elapsed=%s", total_size, elapsed) if SHOW_PERF: print("\n") - print("%-9s format thread:\t\t\t%iMB/s" % (protocol.TYPE, int(total_size/elapsed//1024//1024))) + print("%-9s format thread:\t\t\t%iMB/s" % (proto.TYPE, int(total_size/elapsed//1024//1024))) n_packets = len(packets)*N - print("%-9s packets formatted per second:\t\t%i" % (protocol.TYPE, int(n_packets/elapsed))) + print("%-9s packets formatted per second:\t\t%i" % (proto.TYPE, int(n_packets/elapsed))) assert conn.write_data -- 2.34.1 From 0f434c5fb045922f615eb5a10a2d4cbdf5a47de5 Mon Sep 17 00:00:00 2001 From: totaam Date: Mon, 20 Dec 2021 21:23:09 +0700 Subject: [PATCH 14/21] logging silencer fixes --- .../unittests/unit/client/mixins/display_test.py | 6 +++--- .../unit/client/mixins/encodings_test.py | 6 +++--- tests/unittests/unit/client/mixins/mmap_test.py | 16 ++++++++-------- .../unit/client/mixins/remotelogging_test.py | 12 +++++++----- 4 files changed, 21 insertions(+), 19 deletions(-) diff --git a/tests/unittests/unit/client/mixins/display_test.py b/tests/unittests/unit/client/mixins/display_test.py index 00f445c28..cecce1904 100755 --- a/tests/unittests/unit/client/mixins/display_test.py +++ b/tests/unittests/unit/client/mixins/display_test.py @@ -16,9 +16,9 @@ class DisplayClientTest(ClientMixinTest): def test_display(self): with DisplayContext(): - from xpra.client.mixins.display import DisplayClient, log + from xpra.client.mixins import display def _DisplayClient(): - dc = DisplayClient() + dc = display.DisplayClient() def get_root_size(): return 1024, 768 dc.get_root_size = get_root_size @@ -30,7 +30,7 @@ class DisplayClientTest(ClientMixinTest): opts.desktop_fullscreen = False opts.desktop_scaling = False opts.dpi = 144 - with silence_info(log): + with silence_info(display): self._test_mixin_class(_DisplayClient, opts, { "display" : ":999", "desktop_size" : (1024, 768), diff --git a/tests/unittests/unit/client/mixins/encodings_test.py b/tests/unittests/unit/client/mixins/encodings_test.py index 3d6051510..18c91818d 100755 --- a/tests/unittests/unit/client/mixins/encodings_test.py +++ b/tests/unittests/unit/client/mixins/encodings_test.py @@ -7,7 +7,7 @@ import unittest from xpra.util import AdHocStruct -from xpra.client.mixins.encodings import Encodings, log +from xpra.client.mixins import encodings from unit.test_util import silence_error from unit.client.mixins.clientmixintest_util import ClientMixinTest @@ -26,7 +26,7 @@ class EncodingClientTest(ClientMixinTest): opts.video_decoders = [] opts.csc_modules = [] opts.video_encoders = [] - m = self._test_mixin_class(Encodings, opts, { + m = self._test_mixin_class(encodings.Encodings, opts, { "encodings" : ["rgb"], "encodings.core" : ["rgb32", "rgb24", "png"], "encodings.problematic" : [], @@ -44,7 +44,7 @@ class EncodingClientTest(ClientMixinTest): m.set_encoding("invalid") f(set_invalid_encoding, "should not be able to set encoding 'invalid'") #this will trigger a warning: - with silence_error(log): + with silence_error(encodings): m.set_encoding("jpeg") #quality: for q in (-1, 0, 1, 99, 100): diff --git a/tests/unittests/unit/client/mixins/mmap_test.py b/tests/unittests/unit/client/mixins/mmap_test.py index 9704f59be..7e16797bd 100755 --- a/tests/unittests/unit/client/mixins/mmap_test.py +++ b/tests/unittests/unit/client/mixins/mmap_test.py @@ -9,7 +9,7 @@ import unittest from xpra.os_util import DummyContextManager from xpra.util import AdHocStruct -from xpra.client.mixins.mmap import MmapClient, log +from xpra.client.mixins import mmap from unit.test_util import silence_info, silence_error from unit.client.mixins.clientmixintest_util import ClientMixinTest @@ -23,21 +23,21 @@ class MixinsTest(ClientMixinTest): raise Exception("test close failure handling") import tempfile tmp_dir = tempfile.gettempdir() - for mmap, ctx in { + for mmap_option, ctx in { "off" : DummyContextManager(), - "on" : silence_info(log), - tmp_dir+"/xpra-mmap-test-file-%i" % os.getpid() : silence_info(log), - tmp_dir+"/xpra-fail-mmap-test-file-%i" % os.getpid() : silence_error(log), + "on" : silence_info(mmap), + tmp_dir+"/xpra-mmap-test-file-%i" % os.getpid() : silence_info(mmap), + tmp_dir+"/xpra-fail-mmap-test-file-%i" % os.getpid() : silence_error(mmap), }.items(): opts = AdHocStruct() - opts.mmap = mmap + opts.mmap = mmap_option opts.mmap_group = False with ctx: - m = self._test_mixin_class(MmapClient, opts, { + m = self._test_mixin_class(mmap.MmapClient, opts, { "mmap.enabled" : True, }) fail = bool(m.mmap_filename) and m.mmap_filename.find("fail")>=0 - assert m.mmap_enabled == (mmap!="off" and not fail) + assert m.mmap_enabled == (mmap_option!="off" and not fail) assert len(self.exit_codes)==int(fail) m.cleanup() #no-op: diff --git a/tests/unittests/unit/client/mixins/remotelogging_test.py b/tests/unittests/unit/client/mixins/remotelogging_test.py index 767691633..845c27c0e 100755 --- a/tests/unittests/unit/client/mixins/remotelogging_test.py +++ b/tests/unittests/unit/client/mixins/remotelogging_test.py @@ -7,7 +7,7 @@ import unittest from xpra.util import AdHocStruct -from xpra.client.mixins.remote_logging import RemoteLogging, log +from xpra.client.mixins import remote_logging from unit.test_util import silence_info from unit.client.mixins.clientmixintest_util import ClientMixinTest @@ -23,8 +23,8 @@ class MixinsTest(ClientMixinTest): return opts = AdHocStruct() opts.remote_logging = "yes" - with silence_info(log): - self._test_mixin_class(RemoteLogging, opts, { + with silence_info(remote_logging): + self._test_mixin_class(remote_logging.RemoteLogging, opts, { "remote-logging" : True, }) assert len(self.packets)==0 @@ -35,11 +35,13 @@ class MixinsTest(ClientMixinTest): packet = self.packets[0] assert packet[0]=="logging", "expected logging packet but got '%s'" % (packet[0],) assert packet[1]==20, "expected INFO level (20) but got %s" % (packet[1],) - assert packet[2].data==message, "expected message '%s' but got '%s'" % (message, packet[2].data) + #data might be using a compressed wrapper: + data = getattr(packet[2], "data", packet[2]) + assert data==message, "expected message '%s' but got '%s'" % (message, data) #after cleanup, log messages should not be intercepted: self.packets = [] self.mixin.cleanup() - with silence_info(log): + with silence_info(remote_logging): logger.info("foo") assert len(self.packets)==0 -- 2.34.1 From 7024950d86e176a13cce72a40b9330bda982ce4a Mon Sep 17 00:00:00 2001 From: totaam Date: Mon, 20 Dec 2021 21:23:38 +0700 Subject: [PATCH 15/21] some code checks for 'TYPE' so we must define it --- tests/unittests/unit/client/mixins/clientmixintest_util.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/unittests/unit/client/mixins/clientmixintest_util.py b/tests/unittests/unit/client/mixins/clientmixintest_util.py index 0260d970d..9b96f7723 100755 --- a/tests/unittests/unit/client/mixins/clientmixintest_util.py +++ b/tests/unittests/unit/client/mixins/clientmixintest_util.py @@ -79,12 +79,13 @@ class ClientMixinTest(unittest.TestCase): def fake_quit(self, code): self.exit_codes.append(code) - def _test_mixin_class(self, mclass, opts, caps=None): + def _test_mixin_class(self, mclass, opts, caps=None, protocol_type="xpra"): x = self.mixin = mclass() x.quit = self.fake_quit fake_protocol = AdHocStruct() fake_protocol.get_info = lambda : {} fake_protocol.set_compression_level = lambda _x : None + fake_protocol.TYPE = protocol_type x._protocol = fake_protocol #pylint: disable=protected-access x.add_packet_handlers = self.add_packet_handlers x.add_packet_handler = self.add_packet_handler -- 2.34.1 From 7f1523f9d2b1d24b14b32f9fce91e7f82c03e673 Mon Sep 17 00:00:00 2001 From: totaam Date: Mon, 20 Dec 2021 22:14:55 +0700 Subject: [PATCH 16/21] the tray_icon option is now required in thewwindow mixin --- tests/unittests/unit/client/mixins/window_test.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/unittests/unit/client/mixins/window_test.py b/tests/unittests/unit/client/mixins/window_test.py index 08ef398eb..5759c640e 100755 --- a/tests/unittests/unit/client/mixins/window_test.py +++ b/tests/unittests/unit/client/mixins/window_test.py @@ -36,6 +36,7 @@ class WindowManagerTest(ClientMixinTest): opts.modal_windows = True opts.border = "red" opts.mousewheel = "yes" + opts.tray_icon = "yes" self._test_mixin_class(_WindowClient, opts) def main(): -- 2.34.1 From 1797dee3ed23da8f9c0082abbd0e9763e5ea6aaa Mon Sep 17 00:00:00 2001 From: totaam Date: Mon, 20 Dec 2021 22:44:48 +0700 Subject: [PATCH 17/21] match refactoring #3247 --- tests/unittests/unit/net/crypto_test.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/unittests/unit/net/crypto_test.py b/tests/unittests/unit/net/crypto_test.py index 33b6d5651..dec443205 100755 --- a/tests/unittests/unit/net/crypto_test.py +++ b/tests/unittests/unit/net/crypto_test.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # This file is part of Xpra. -# Copyright (C) 2011-2020 Antoine Martin +# Copyright (C) 2011-2021 Antoine Martin # Copyright (C) 2008, 2009, 2010 Nathaniel Smith # Xpra is released under the terms of the GNU GPL v2, or, at your option, any # later version. See the file COPYING for details. @@ -11,7 +11,7 @@ from xpra.os_util import hexstr from xpra.util import envbool from xpra.net.crypto import ( - DEFAULT_SALT, DEFAULT_ITERATIONS, DEFAULT_BLOCKSIZE, DEFAULT_IV, + DEFAULT_SALT, DEFAULT_ITERATIONS, DEFAULT_KEYSIZE, DEFAULT_KEY_HASH, DEFAULT_IV, validate_backend, ) @@ -41,10 +41,11 @@ class TestCrypto(unittest.TestCase): password = "this is our secret" key_salt = DEFAULT_SALT + key_hash = DEFAULT_KEY_HASH iterations = DEFAULT_ITERATIONS - block_size = DEFAULT_BLOCKSIZE + block_size = DEFAULT_KEYSIZE #test key stretching: - args = password, key_salt, block_size, iterations + args = password, key_salt, key_hash, block_size, iterations secret = self.backend.get_key(*args) log("%s%s=%s" % (self.backend.get_key, args, hexstr(secret))) assert secret is not None -- 2.34.1 From 08b229904c9d3e22c1f099e08196dc494ab5a87d Mon Sep 17 00:00:00 2001 From: totaam Date: Mon, 20 Dec 2021 22:45:10 +0700 Subject: [PATCH 18/21] lzo is no more --- tests/unittests/unit/net/packet_header_test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unittests/unit/net/packet_header_test.py b/tests/unittests/unit/net/packet_header_test.py index 1c56e736a..bdb50e027 100755 --- a/tests/unittests/unit/net/packet_header_test.py +++ b/tests/unittests/unit/net/packet_header_test.py @@ -12,7 +12,7 @@ import unittest from xpra.net.header import ( unpack_header, pack_header, FLAGS_BENCODE, FLAGS_RENCODE, FLAGS_CIPHER, FLAGS_YAML, - ZLIB_FLAG, LZ4_FLAG, LZO_FLAG, BROTLI_FLAG, + ZLIB_FLAG, LZ4_FLAG, BROTLI_FLAG, ) class TestPacketHeader(unittest.TestCase): @@ -20,7 +20,7 @@ class TestPacketHeader(unittest.TestCase): def test_roundtrip(self): print("hello") for encode_flag in (FLAGS_BENCODE, FLAGS_RENCODE, FLAGS_YAML): - for comp_flag in (ZLIB_FLAG, LZ4_FLAG, LZO_FLAG, BROTLI_FLAG): + for comp_flag in (ZLIB_FLAG, LZ4_FLAG, BROTLI_FLAG): for cipher in (0, FLAGS_CIPHER): for level in (0, 1, 10): for index in (0, 1, 255): -- 2.34.1 From 9106e02104f071a05f106c1f581256c09d587be7 Mon Sep 17 00:00:00 2001 From: totaam Date: Mon, 20 Dec 2021 22:47:13 +0700 Subject: [PATCH 19/21] ip_ifaces is a dict also update the log silencer --- tests/unittests/unit/net/net_util_test.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/unittests/unit/net/net_util_test.py b/tests/unittests/unit/net/net_util_test.py index 870801666..a56551eed 100755 --- a/tests/unittests/unit/net/net_util_test.py +++ b/tests/unittests/unit/net/net_util_test.py @@ -7,13 +7,13 @@ import unittest from collections import defaultdict +from xpra.net import net_util from xpra.net.net_util import ( get_info, get_interfaces, get_interfaces_addresses, #get_interface, get_gateways, get_bind_IPs, do_get_bind_ifacemask, get_ssl_info, get_interface, if_nametoindex, if_indextoname, get_iface, get_free_tcp_port, - log ) from unit.test_util import silence_error @@ -41,7 +41,7 @@ class TestVersionUtilModule(unittest.TestCase): ipmasks = do_get_bind_ifacemask(iface) for ip, _ in ipmasks: ip_ifaces[ip].append(iface) - for ip, ifaces in ip_ifaces: + for ip, ifaces in ip_ifaces.items(): assert get_iface(ip) in ifaces, "expected interface for ip %s to be one of %s but got %s" % ( ip, ifaces, get_iface(ip)) ia = get_interfaces_addresses() @@ -65,7 +65,7 @@ class TestVersionUtilModule(unittest.TestCase): invalid_iface("") invalid_iface("%") invalid_iface(":") - with silence_error(log): + with silence_error(net_util): invalid_iface("INVALIDHOSTNAME") invalid_iface("10.0.0") get_iface("localhost") -- 2.34.1 From d6a4ab2c3c709895deaf89a377f69357f8546742 Mon Sep 17 00:00:00 2001 From: totaam Date: Tue, 21 Dec 2021 13:46:39 +0700 Subject: [PATCH 20/21] silencer must point to module --- tests/unittests/unit/net/bencode_test.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/unittests/unit/net/bencode_test.py b/tests/unittests/unit/net/bencode_test.py index 06b900e38..12c945040 100755 --- a/tests/unittests/unit/net/bencode_test.py +++ b/tests/unittests/unit/net/bencode_test.py @@ -312,7 +312,8 @@ class TestFailCython(unittest.TestCase): try: #backup = sys.modules.copy() sys.modules["xpra.net.bencode.cython_bencode"] = None - with silence_warn(get_util_logger()): + from xpra import os_util + with silence_warn(os_util, "util_logger"): bencode.init() finally: del sys.modules["xpra.net.bencode.cython_bencode"] -- 2.34.1 From a6bfa406864fbf32d1a6f0f7df3b2331d74b7d14 Mon Sep 17 00:00:00 2001 From: totaam Date: Tue, 21 Dec 2021 19:50:01 +0700 Subject: [PATCH 21/21] match refactoring: the function now returns a 'raw' uncompressed wrapper --- tests/unittests/unit/net/compression_test.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/tests/unittests/unit/net/compression_test.py b/tests/unittests/unit/net/compression_test.py index 36f2242a1..7aed3e9f4 100755 --- a/tests/unittests/unit/net/compression_test.py +++ b/tests/unittests/unit/net/compression_test.py @@ -53,12 +53,9 @@ class TestCompression(unittest.TestCase): raise Exception("%s is not a valid compression" % x) def test_compressed_wrapper(self): - try: - compression.compressed_wrapper("test", b"abc") - except compression.InvalidCompressionException: - pass - else: - raise Exception("should not be able to use the wrapper without enabling a compressor") + r = compression.compressed_wrapper("test", b"a"*(compression.MIN_COMPRESS_SIZE+1)) + if not r.datatype.startswith("raw"): + raise Exception("should not be able to use the wrapper without enabling a compressor, but got %s" % r) for x in ("lz4", "brotli", "zlib", "none"): if not compression.use(x): continue -- 2.34.1