Skip to content

Commit 8ac13e7

Browse files
authored
Remove 'mock' dependency (#4480)
1 parent 26303ff commit 8ac13e7

18 files changed

+72
-77
lines changed

scapy/utils.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -981,14 +981,10 @@ class ContextManagerCaptureOutput(object):
981981
def __init__(self):
982982
# type: () -> None
983983
self.result_export_object = ""
984-
try:
985-
import mock # noqa: F401
986-
except Exception:
987-
raise ImportError("The mock module needs to be installed !")
988984

989985
def __enter__(self):
990986
# type: () -> ContextManagerCaptureOutput
991-
import mock
987+
from unittest import mock
992988

993989
def write(s, decorator=self):
994990
# type: (str, ContextManagerCaptureOutput) -> None

test/answering_machines.uts

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
+ Answering Machines
99

1010
= Generic answering machine mocker
11-
import mock
11+
from unittest import mock
1212
@mock.patch("scapy.ansmachine.sniff")
1313
def test_am(cls_name, packet_query, check_reply, mock_sniff, **kargs):
1414
packet_query = packet_query.__class__(bytes(packet_query))
@@ -236,7 +236,7 @@ assert res[DHCP6_Solicit]
236236
a.print_reply(req, res)
237237

238238
= WiFi_am
239-
import mock
239+
from unittest import mock
240240
@mock.patch("scapy.layers.dot11.sniff")
241241
def test_WiFi_am(packet_query, check_reply, mock_sniff, **kargs):
242242
def sniff(*args,**kargs):

test/bpf.uts

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ s.close()
114114
= L2bpfListenSocket - read failure
115115
~ needs_root
116116

117-
import mock
117+
from unittest import mock
118118

119119
@mock.patch("scapy.arch.bpf.supersocket.os.read")
120120
def _test_osread(osread):

test/contrib/dtp.uts

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ assert pkt[DTP].tlvlist[3].status == b'\x03'
1616

1717
= Test negotiate_trunk
1818

19-
import mock
19+
from unittest import mock
2020

2121
def test_pkt(pkt):
2222
pkt = Ether(raw(pkt))

test/linux.uts

+6-5
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ else:
6666
= catch loopback device missing
6767
~ linux needs_root
6868

69-
from mock import patch
69+
from unittest.mock import patch
7070

7171
# can't remove the lo device (or its address without causing trouble) - use some pseudo dummy instead
7272

@@ -77,7 +77,7 @@ with patch('scapy.arch.linux.conf.loopback_name', 'scapy_lo_x'):
7777
~ linux needs_root
7878

7979
import os, socket
80-
from mock import patch
80+
from unittest.mock import patch
8181

8282
try:
8383
exit_status = os.system("ip link add name scapy_lo type dummy")
@@ -116,7 +116,7 @@ finally:
116116

117117
conf.ifaces._add_fake_iface("scapy0", 'e2:39:91:79:19:10')
118118

119-
from mock import patch
119+
from unittest.mock import patch
120120
conf.route6.routes = [('fe80::', 64, '::', 'scapy0', ['fe80::e039:91ff:fe79:1910'], 256)]
121121
conf.route6.ipv6_ifaces = set(['scapy0'])
122122
bck_conf_iface = conf.iface
@@ -274,7 +274,7 @@ except Exception:
274274
= Routing table, interface with no names
275275
~ linux
276276

277-
from mock import patch
277+
from unittest.mock import patch
278278

279279
@patch("scapy.arch.linux.ioctl")
280280
def test_read_routes(mock_ioctl):
@@ -293,7 +293,8 @@ test_read_routes()
293293

294294
from scapy.arch.linux import L3PacketSocket
295295

296-
import mock, socket
296+
import socket
297+
from unittest import mock
297298

298299
@mock.patch("scapy.arch.linux.socket.socket.sendto")
299300
def test_L3PacketSocket_sendto_python3(mock_sendto):

test/pipetool.uts

+6-6
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ p.wait_and_stop()
228228

229229
= Test SniffSource
230230

231-
import mock
231+
from unittest import mock
232232
fd = ObjectPipe("sniffsource")
233233
fd.write("test")
234234

@@ -295,7 +295,7 @@ else:
295295

296296
= Test exhausted AutoSource and SniffSource
297297

298-
import mock
298+
from unittest import mock
299299
from scapy.error import Scapy_Exception
300300

301301
def _fail():
@@ -323,7 +323,7 @@ except:
323323
q = ObjectPipe("wiresharksink")
324324
pkt = Ether(dst="aa:aa:aa:aa:aa:aa", src="bb:bb:bb:bb:bb:bb")/IP(dst="127.0.0.1", src="127.0.0.1")/ICMP()
325325

326-
import mock
326+
from unittest import mock
327327
with mock.patch("scapy.scapypipes.subprocess.Popen", return_value=Bunch(stdin=q)) as popen:
328328
sink = WiresharkSink()
329329
sink.start()
@@ -345,7 +345,7 @@ linktype = scapy.data.DLT_EN3MB
345345
q = ObjectPipe("wiresharksink_linktype")
346346
pkt = Ether(dst="aa:aa:aa:aa:aa:aa", src="bb:bb:bb:bb:bb:bb")/IP(dst="127.0.0.1", src="127.0.0.1")/ICMP()
347347

348-
import mock
348+
from unittest import mock
349349
with mock.patch("scapy.scapypipes.subprocess.Popen", return_value=Bunch(stdin=q)) as popen:
350350
sink = WiresharkSink(linktype=linktype)
351351
sink.start()
@@ -363,7 +363,7 @@ linktype = scapy.data.DLT_EN3MB
363363
q = ObjectPipe("wiresharksink_args")
364364
pkt = Ether(dst="aa:aa:aa:aa:aa:aa", src="bb:bb:bb:bb:bb:bb")/IP(dst="127.0.0.1", src="127.0.0.1")/ICMP()
365365

366-
import mock
366+
from unittest import mock
367367
with mock.patch("scapy.scapypipes.subprocess.Popen", return_value=Bunch(stdin=q)) as popen:
368368
sink = WiresharkSink(args=['-c', '1'])
369369
sink.start()
@@ -404,7 +404,7 @@ os.unlink(os.path.join(dname, "t2.pcap.gz"))
404404
= Test InjectSink and Inject3Sink
405405
~ needs_root
406406

407-
import mock
407+
from unittest import mock
408408

409409
a = IP(dst="192.168.0.1")/ICMP()
410410
msgs = []

0 commit comments

Comments
 (0)