(self)
| 3139 | |
| 3140 | @unittest.skipIf(os.name != 'nt', "Windows only") |
| 3141 | def test_win_impl(self): |
| 3142 | # Make sure alternate Windows implementation is called. |
| 3143 | with unittest.mock.patch("shutil._copyfileobj_readinto") as m: |
| 3144 | shutil.copyfile(TESTFN, TESTFN2) |
| 3145 | assert m.called |
| 3146 | |
| 3147 | # File size is 2 MiB but max buf size should be 1 MiB. |
| 3148 | self.assertEqual(m.call_args[0][2], 1 * 1024 * 1024) |
| 3149 | |
| 3150 | # If file size < 1 MiB memoryview() length must be equal to |
| 3151 | # the actual file size. |
| 3152 | with tempfile.NamedTemporaryFile(dir=os.getcwd(), delete=False) as f: |
| 3153 | f.write(b'foo') |
| 3154 | fname = f.name |
| 3155 | self.addCleanup(os_helper.unlink, fname) |
| 3156 | with unittest.mock.patch("shutil._copyfileobj_readinto") as m: |
| 3157 | shutil.copyfile(fname, TESTFN2) |
| 3158 | self.assertEqual(m.call_args[0][2], 3) |
| 3159 | |
| 3160 | # Empty files should not rely on readinto() variant. |
| 3161 | with tempfile.NamedTemporaryFile(dir=os.getcwd(), delete=False) as f: |
| 3162 | pass |
| 3163 | fname = f.name |
| 3164 | self.addCleanup(os_helper.unlink, fname) |
| 3165 | with unittest.mock.patch("shutil._copyfileobj_readinto") as m: |
| 3166 | shutil.copyfile(fname, TESTFN2) |
| 3167 | assert not m.called |
| 3168 | self.assert_files_eq(fname, TESTFN2) |
| 3169 | |
| 3170 | |
| 3171 | class _ZeroCopyFileTest(object): |
nothing calls this directly
no test coverage detected