Skip to content

Commit f0afaab

Browse files
committed
Add test.test_pathlib.test_copy with a single test function.
1 parent e08f358 commit f0afaab

File tree

4 files changed

+53
-12
lines changed

4 files changed

+53
-12
lines changed

Lib/test/test_pathlib/support/local_path.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ class LocalPathGround:
123123
def __init__(self, path_cls):
124124
self.path_cls = path_cls
125125

126-
def setup(self):
127-
root = self.path_cls(os_helper.TESTFN)
126+
def setup(self, local_suffix=""):
127+
root = self.path_cls(os_helper.TESTFN + local_suffix)
128128
os.mkdir(root)
129129
return root
130130

Lib/test/test_pathlib/support/zip_path.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ class ZipPathGround:
203203
def __init__(self, path_cls):
204204
self.path_cls = path_cls
205205

206-
def setup(self):
206+
def setup(self, local_suffix=""):
207207
return self.path_cls(zip_file=zipfile.ZipFile(io.BytesIO(), "w"))
208208

209209
def teardown(self, root):

Lib/test/test_pathlib/test_copy.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import unittest
2+
3+
from pathlib import Path
4+
5+
from test.test_pathlib.support.local_path import LocalPathGround
6+
from test.test_pathlib.support.zip_path import ZipPathGround, ReadableZipPath, WritableZipPath
7+
8+
9+
class CopyPathTestBase:
10+
def setUp(self):
11+
self.source_root = self.source_ground.setup()
12+
self.source_ground.create_hierarchy(self.source_root)
13+
self.target_root = self.target_ground.setup(local_suffix="_target")
14+
15+
def tearDown(self):
16+
self.source_ground.teardown(self.source_root)
17+
self.target_ground.teardown(self.target_root)
18+
19+
def test_copy_file(self):
20+
source = self.source_root / 'fileA'
21+
target = self.target_root / 'copyA'
22+
result = source.copy(target)
23+
self.assertEqual(result, target)
24+
self.assertTrue(self.target_ground.isfile(target))
25+
self.assertEqual(self.source_ground.readbytes(source),
26+
self.target_ground.readbytes(result))
27+
28+
29+
class CopyZipPathToZipPathTest(CopyPathTestBase, unittest.TestCase):
30+
source_ground = ZipPathGround(ReadableZipPath)
31+
target_ground = ZipPathGround(WritableZipPath)
32+
33+
34+
class CopyZipPathToPathTest(CopyPathTestBase, unittest.TestCase):
35+
source_ground = ZipPathGround(ReadableZipPath)
36+
target_ground = LocalPathGround(Path)
37+
38+
39+
class CopyPathToZipPathTest(CopyPathTestBase, unittest.TestCase):
40+
source_ground = LocalPathGround(Path)
41+
target_ground = ZipPathGround(WritableZipPath)
42+
43+
44+
class CopyPathToPathTest(CopyPathTestBase, unittest.TestCase):
45+
source_ground = LocalPathGround(Path)
46+
target_ground = LocalPathGround(Path)
47+
48+
49+
if __name__ == "__main__":
50+
unittest.main()

Lib/test/test_pathlib/test_pathlib_abc.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,15 +1333,6 @@ class RWPathTest(WritablePathTest, ReadablePathTest):
13331333
cls = DummyRWPath
13341334
can_symlink = False
13351335

1336-
def test_copy_file(self):
1337-
base = self.cls(self.base)
1338-
source = base / 'fileA'
1339-
target = base / 'copyA'
1340-
result = source.copy(target)
1341-
self.assertEqual(result, target)
1342-
self.assertTrue(result.info.exists())
1343-
self.assertEqual(source.read_text(), result.read_text())
1344-
13451336
def test_copy_file_to_existing_file(self):
13461337
base = self.cls(self.base)
13471338
source = base / 'fileA'

0 commit comments

Comments
 (0)