Skip to content

Commit 4a32d6d

Browse files
committed
Move to unittest.mock.patch
1 parent 6963ce9 commit 4a32d6d

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

Lib/test/test_netrc.py

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from pathlib import Path
33
from test import support
44
from test.support import os_helper
5-
from unittest.mock import Mock
5+
from unittest.mock import patch
66

77

88
temp_filename = os_helper.TESTFN
@@ -318,22 +318,19 @@ def test_security(self):
318318
def test_security_only_once(self):
319319
# Make sure security check is only run once per parse when multiple
320320
# entries are found.
321-
check_called = netrc.netrc._security_check = Mock(return_value=True)
322-
323-
# Parse a default netrc with more than one password line.
324-
with os_helper.temp_dir() as tmp_dir:
325-
netrc_path = Path(tmp_dir) / '.netrc'
326-
netrc_path.write_text("""\
327-
machine foo.domain.com login bar password pass
328-
machine bar.domain.com login foo password pass
329-
""")
330-
netrc_path.chmod(0o600)
331-
with os_helper.EnvironmentVarGuard() as environ:
332-
environ.set('HOME', tmp_dir)
333-
netrc.netrc()
321+
with patch.object(netrc.netrc, "_security_check") as mock:
322+
with os_helper.temp_dir() as tmp_dir:
323+
netrc_path = Path(tmp_dir) / '.netrc'
324+
netrc_path.write_text("""\
325+
machine foo.domain.com login bar password pass
326+
machine bar.domain.com login foo password pass
327+
""")
328+
netrc_path.chmod(0o600)
329+
with os_helper.EnvironmentVarGuard() as environ:
330+
environ.set('HOME', tmp_dir)
331+
netrc.netrc()
334332

335-
check_called.assert_called_once()
336-
del check_called
333+
mock.assert_called_once()
337334

338335

339336
if __name__ == "__main__":

0 commit comments

Comments
 (0)