Skip to content

Commit

Permalink
#1761 add unit tests for remotelogging mixin, stub mixin now contains…
Browse files Browse the repository at this point in the history
… more default behaviour: exit_code, start_time and compressed_wrapper method

git-svn-id: https://xpra.org/svn/Xpra/trunk@18535 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Feb 22, 2018
1 parent b70990b commit 9d5dd07
Show file tree
Hide file tree
Showing 14 changed files with 58 additions and 2 deletions.
29 changes: 29 additions & 0 deletions src/unittests/unit/client/mixins_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from xpra.os_util import monotonic_time
from xpra.client.mixins.network_state import NetworkState
from xpra.client.mixins.mmap_client import MmapClient
from xpra.client.mixins.remote_logging import RemoteLogging


class MixinsTest(unittest.TestCase):
Expand Down Expand Up @@ -46,6 +47,34 @@ def test_mmap(self):
})
x.parse_server_capabilities()

def test_remotelogging(self):
x = RemoteLogging()
opts = AdHocStruct()
opts.remote_logging = "yes"
x.init(opts)
assert x.get_caps() is not None
x.server_capabilities = typedict({
"remote-logging" : True,
})
x.parse_server_capabilities()
packets = []
def send(*args):
packets.append(args)
x.send = send
from xpra.log import Logger
log = Logger("util")
message = "hello"
log.info(message)
assert len(packets)==1
packet = packets[0]
assert packet[0]=="logging"
assert packet[1]==20 #info
assert packet[2].data==message
#after cleanup, log messages should not be intercepted:
x.cleanup()
log.info("foo")
assert len(packets)==1


def main():
unittest.main()
Expand Down
1 change: 1 addition & 0 deletions src/xpra/client/mixins/audio_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class AudioClient(StubClientMixin):
__signals__ = ["speaker-changed", "microphone-changed"]

def __init__(self):
StubClientMixin.__init__(self)
self.sound_source_plugin = None
self.speaker_allowed = False
self.speaker_enabled = False
Expand Down
1 change: 1 addition & 0 deletions src/xpra/client/mixins/clipboard_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class ClipboardClient(StubClientMixin):
__signals__ = ["clipboard-toggled"]

def __init__(self):
StubClientMixin.__init__(self)
self.client_clipboard_type = ""
self.client_clipboard_direction = "both"
self.client_supports_clipboard = False
Expand Down
1 change: 1 addition & 0 deletions src/xpra/client/mixins/display_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class DisplayClient(StubClientMixin):
__signals__ = ["scaling-changed"]

def __init__(self):
StubClientMixin.__init__(self)
self.dpi = 0
self.initial_scaling = 1, 1
self.xscale, self.yscale = self.initial_scaling
Expand Down
2 changes: 2 additions & 0 deletions src/xpra/client/mixins/encodings.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
Mixin for adding encodings to a client
"""
class Encodings(StubClientMixin):

def __init__(self):
StubClientMixin.__init__(self)
self.allowed_encodings = []
self.core_encodings = None
self.encoding = None
Expand Down
2 changes: 2 additions & 0 deletions src/xpra/client/mixins/mmap_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
Mixin for adding mmap support to a client
"""
class MmapClient(StubClientMixin):

def __init__(self):
StubClientMixin.__init__(self)
self.mmap_enabled = False
self.mmap = None
self.mmap_token = None
Expand Down
2 changes: 1 addition & 1 deletion src/xpra/client/mixins/network_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
class NetworkState(StubClientMixin):

def __init__(self):
self.start_time = int(monotonic_time())
StubClientMixin.__init__(self)
self.uuid = get_user_uuid()

self.server_start_time = -1
Expand Down
1 change: 1 addition & 0 deletions src/xpra/client/mixins/notification_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
class NotificationClient(StubClientMixin):

def __init__(self):
StubClientMixin.__init__(self)
self.client_supports_notifications = False
self.notifications_enabled = False
self.notifier = None
Expand Down
1 change: 1 addition & 0 deletions src/xpra/client/mixins/remote_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
class RemoteLogging(StubClientMixin):

def __init__(self):
StubClientMixin.__init__(self)
self.client_supports_remote_logging = False
self.in_remote_logging = False
self.local_logging = None
Expand Down
1 change: 1 addition & 0 deletions src/xpra/client/mixins/rpc_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
class RPCClient(StubClientMixin):

def __init__(self):
StubClientMixin.__init__(self)
#rpc / dbus:
self.rpc_counter = AtomicInteger()
self.rpc_pending_requests = {}
Expand Down
15 changes: 14 additions & 1 deletion src/xpra/client/mixins/stub_client_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,24 @@

import sys

from xpra.os_util import monotonic_time


class StubClientMixin(object):

__signals__ = {}
def __init__(self):
self.exit_code = None
self.start_time = int(monotonic_time())

def init(self, opts):
def init(self, _opts):
pass

def run(self):
pass

def quit(self, exit_code):
self.exit_code = exit_code
sys.exit(exit_code)

def cleanup(self):
Expand All @@ -39,6 +46,12 @@ def parse_server_capabilities(self):
def process_ui_capabilities(self):
pass

def compressed_wrapper(self, datatype, data, level=5):
#sub-classes should override this
assert level>=0
from xpra.net.compression import Compressed
return Compressed("raw %s" % datatype, data, can_inline=True)


def init_authenticated_packet_handlers(self):
pass
2 changes: 2 additions & 0 deletions src/xpra/client/mixins/tray_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
(not forwarding other application's trays - that's handled in WindowClient)
"""
class TrayClient(StubClientMixin):

def __init__(self):
StubClientMixin.__init__(self)
#settings:
self.tray_enabled = False
self.delay_tray = False
Expand Down
1 change: 1 addition & 0 deletions src/xpra/client/mixins/webcam_forwarder.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class WebcamForwarder(StubClientMixin):
__signals__ = ["webcam-changed"]

def __init__(self):
StubClientMixin.__init__(self)
#webcam:
self.webcam_option = ""
self.webcam_forwarding = False
Expand Down
1 change: 1 addition & 0 deletions src/xpra/client/mixins/window_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
class WindowClient(StubClientMixin):

def __init__(self):
StubClientMixin.__init__(self)
self._window_to_id = {}
self._id_to_window = {}

Expand Down

0 comments on commit 9d5dd07

Please sign in to comment.