Skip to content

Commit 23640a9

Browse files
committed
Use built-in Python 3 unittest.mock module
Replace the use of external 'mock' package with the 'unittest.mock' module provided by Python 3. Since Python 2 is no longer supported, this eliminates an unnecessary dependency.
1 parent 8e39585 commit 23640a9

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

tests/test_integration_distutils.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import distutils.dist
2+
import unittest.mock
23

3-
import mock
44
import pytest
55
import setuptools.dist
66

@@ -11,7 +11,7 @@ def test_valid_rst():
1111
dist = distutils.dist.Distribution(attrs=dict(
1212
long_description="Hello, I am some text."))
1313
checker = readme_renderer.integration.distutils.Check(dist)
14-
checker.warn = mock.Mock()
14+
checker.warn = unittest.mock.Mock()
1515

1616
checker.check_restructuredtext()
1717

@@ -22,14 +22,14 @@ def test_invalid_rst():
2222
dist = distutils.dist.Distribution(attrs=dict(
2323
long_description="Hello, I am some `totally borked< text."))
2424
checker = readme_renderer.integration.distutils.Check(dist)
25-
checker.warn = mock.Mock()
26-
checker.announce = mock.Mock()
25+
checker.warn = unittest.mock.Mock()
26+
checker.announce = unittest.mock.Mock()
2727

2828
checker.check_restructuredtext()
2929

3030
# Should warn once for the syntax error, and finally to warn that the
3131
# overall syntax is invalid
32-
checker.warn.assert_called_once_with(mock.ANY)
32+
checker.warn.assert_called_once_with(unittest.mock.ANY)
3333
message = checker.warn.call_args[0][0]
3434
assert 'invalid markup' in message
3535
assert 'line 1: Warning:' in message
@@ -47,14 +47,14 @@ def test_malicious_rst():
4747
dist = distutils.dist.Distribution(attrs=dict(
4848
long_description=description))
4949
checker = readme_renderer.integration.distutils.Check(dist)
50-
checker.warn = mock.Mock()
51-
checker.announce = mock.Mock()
50+
checker.warn = unittest.mock.Mock()
51+
checker.announce = unittest.mock.Mock()
5252

5353
checker.check_restructuredtext()
5454

5555
# Should warn once for the syntax error, and finally to warn that the
5656
# overall syntax is invalid
57-
checker.warn.assert_called_once_with(mock.ANY)
57+
checker.warn.assert_called_once_with(unittest.mock.ANY)
5858
message = checker.warn.call_args[0][0]
5959
assert 'directive disabled' in message
6060

@@ -68,7 +68,7 @@ def test_markdown():
6868
long_description="Hello, I am some text.",
6969
long_description_content_type="text/markdown"))
7070
checker = readme_renderer.integration.distutils.Check(dist)
71-
checker.warn = mock.Mock()
71+
checker.warn = unittest.mock.Mock()
7272

7373
checker.check_restructuredtext()
7474

@@ -79,21 +79,21 @@ def test_markdown():
7979
def test_invalid_missing():
8080
dist = distutils.dist.Distribution(attrs=dict())
8181
checker = readme_renderer.integration.distutils.Check(dist)
82-
checker.warn = mock.Mock()
82+
checker.warn = unittest.mock.Mock()
8383

8484
checker.check_restructuredtext()
8585

86-
checker.warn.assert_called_once_with(mock.ANY)
86+
checker.warn.assert_called_once_with(unittest.mock.ANY)
8787
assert 'missing' in checker.warn.call_args[0][0]
8888

8989

9090
def test_invalid_empty():
9191
dist = distutils.dist.Distribution(attrs=dict(
9292
long_description=""))
9393
checker = readme_renderer.integration.distutils.Check(dist)
94-
checker.warn = mock.Mock()
94+
checker.warn = unittest.mock.Mock()
9595

9696
checker.check_restructuredtext()
9797

98-
checker.warn.assert_called_once_with(mock.ANY)
98+
checker.warn.assert_called_once_with(unittest.mock.ANY)
9999
assert 'missing' in checker.warn.call_args[0][0]

tox.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ envlist = py36,py37,py38,py39,pep8,packaging,noextra
44
[testenv]
55
deps =
66
pytest
7-
mock
87
commands =
98
py.test --strict {posargs}
109
extras = md

0 commit comments

Comments
 (0)