Skip to content

Commit 2699453

Browse files
committed
Get rid of pretend in favor of native unittest.mock
1 parent 6a9c0b3 commit 2699453

File tree

2 files changed

+13
-19
lines changed

2 files changed

+13
-19
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from setuptools import Extension, find_packages, setup
44

55

6-
tests_require = ['pytest', 'pretend']
6+
tests_require = ['pytest']
77

88
setup(
99
name='getdents',

tests/test_cli.py

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import re
22
from sys import stdout
3-
4-
import pretend
3+
from unittest.mock import Mock
54

65
from pytest import mark, raises
76

@@ -38,49 +37,44 @@ def test_parse_args_min_buff_size(capsys):
3837

3938

4039
def test_main(monkeypatch):
41-
directory_entries = pretend.stub()
42-
43-
@pretend.call_recorder
44-
def format_test(directory_entries, file):
45-
pass
46-
47-
@pretend.call_recorder
48-
def getdents(path, buff_size=32768):
49-
return directory_entries
40+
format_test = Mock()
41+
getdents = Mock()
42+
directory_entries = getdents.return_value
5043

5144
monkeypatch.setitem(FORMATTERS, 'test', format_test)
5245
monkeypatch.setattr(cli, 'getdents', getdents)
5346

5447
assert main(['x', '-o', 'test', '-b', '1024'], 'test') == 0
55-
assert getdents.calls == [pretend.call('x', buff_size=1024)]
56-
assert format_test.calls == [pretend.call(directory_entries, stdout)]
48+
49+
getdents.assert_called_once_with('x', buff_size=1024)
50+
format_test.assert_called_once_with(directory_entries, stdout)
5751

5852

5953
def test_main_memory_error(monkeypatch):
60-
monkeypatch.setattr(cli, 'getdents', pretend.raiser(MemoryError))
54+
monkeypatch.setattr(cli, 'getdents', Mock(side_effect=MemoryError))
6155

6256
assert main(['x']) == 3
6357

6458

6559
def test_main_file_not_found_error(monkeypatch):
66-
monkeypatch.setattr(cli, 'getdents', pretend.raiser(FileNotFoundError))
60+
monkeypatch.setattr(cli, 'getdents', Mock(side_effect=FileNotFoundError))
6761

6862
assert main(['x']) == 4
6963

7064

7165
def test_main_not_a_directory_error(monkeypatch):
72-
monkeypatch.setattr(cli, 'getdents', pretend.raiser(NotADirectoryError))
66+
monkeypatch.setattr(cli, 'getdents', Mock(side_effect=NotADirectoryError))
7367

7468
assert main(['x']) == 5
7569

7670

7771
def test_main_permission_error(monkeypatch):
78-
monkeypatch.setattr(cli, 'getdents', pretend.raiser(PermissionError))
72+
monkeypatch.setattr(cli, 'getdents', Mock(side_effect=PermissionError))
7973

8074
assert main(['x']) == 6
8175

8276

8377
def test_main_os_error(monkeypatch):
84-
monkeypatch.setattr(cli, 'getdents', pretend.raiser(OSError))
78+
monkeypatch.setattr(cli, 'getdents', Mock(side_effect=OSError))
8579

8680
assert main(['x']) == 7

0 commit comments

Comments
 (0)