|
2 | 2 | from pathlib import Path |
3 | 3 | from test import support |
4 | 4 | from test.support import os_helper |
5 | | -from unittest.mock import Mock |
| 5 | +from unittest.mock import patch |
6 | 6 |
|
7 | 7 |
|
8 | 8 | temp_filename = os_helper.TESTFN |
@@ -318,22 +318,19 @@ def test_security(self): |
318 | 318 | def test_security_only_once(self): |
319 | 319 | # Make sure security check is only run once per parse when multiple |
320 | 320 | # 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() |
334 | 332 |
|
335 | | - check_called.assert_called_once() |
336 | | - del check_called |
| 333 | + mock.assert_called_once() |
337 | 334 |
|
338 | 335 |
|
339 | 336 | if __name__ == "__main__": |
|
0 commit comments