Skip to content

Commit

Permalink
prefer newer unittest.mock when available
Browse files Browse the repository at this point in the history
  • Loading branch information
a-detiste committed Apr 14, 2024
1 parent b5a477e commit 646dbe9
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 7 deletions.
2 changes: 1 addition & 1 deletion docs/sources/basics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ necessarily need a connected socket, in fact, you don't even need a socket at al
>>> def data_source():
>>> yield TextMessage(u'hello world')
>>> from mock import MagicMock
>>> from unittest.mock import MagicMock
>>> source = MagicMock(side_effect=data_source)
>>> ws = EchoWebSocket(sock=source)
>>> ws.send(u'hello there')
5 changes: 4 additions & 1 deletion test/test_cherrypy.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
import time
import unittest

from mock import MagicMock, call
try:
from unittest.mock import MagicMock, call
except ImportError:
from mock import MagicMock, call

import cherrypy
from ws4py.server.cherrypyserver import WebSocketPlugin, WebSocketTool
Expand Down
5 changes: 4 additions & 1 deletion test/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
import time
import unittest

from mock import MagicMock, patch
try:
from unittest.mock import MagicMock, patch
except ImportError:
from mock import MagicMock, patch

from ws4py import WS_KEY
from ws4py.exc import HandshakeError
Expand Down
5 changes: 4 additions & 1 deletion test/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
except ImportError:
from itertools import zip_longest

from mock import MagicMock, call, patch
try:
from unittest.mock import MagicMock, call, patch
except ImportError:
from mock import MagicMock, call, patch

from ws4py.manager import WebSocketManager, SelectPoller,\
EPollPoller
Expand Down
9 changes: 7 additions & 2 deletions test/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
# -*- coding: utf-8 -*-
import unittest

try:
from unittest.mock import MagicMock
except ImportError:
from mock import MagicMock

from ws4py import format_addresses
from ws4py.websocket import WebSocket
from mock import MagicMock


class WSUtilities(unittest.TestCase):
def test_format_address(self):
Expand All @@ -14,7 +19,7 @@ def test_format_address(self):

log = format_addresses(ws)
self.assertEqual(log, "[Local => 127.0.0.1:52300 | Remote => 127.0.0.1:4800]")

if __name__ == '__main__':
suite = unittest.TestSuite()
loader = unittest.TestLoader()
Expand Down
5 changes: 4 additions & 1 deletion test/test_websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
import socket
import struct

from mock import MagicMock, call, patch
try:
from unittest.mock import MagicMock, call, patch
except ImportError:
from mock import MagicMock, call, patch

from ws4py.framing import Frame, \
OPCODE_CONTINUATION, OPCODE_TEXT, \
Expand Down

0 comments on commit 646dbe9

Please sign in to comment.