-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathtest_copy_lib.py
More file actions
75 lines (50 loc) · 2.21 KB
/
test_copy_lib.py
File metadata and controls
75 lines (50 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
"""Tests for copy_lib.py - library copying with dependencies."""
import pathlib
import tempfile
import unittest
class TestCopySingle(unittest.TestCase):
"""Tests for _copy_single helper function."""
def test_copies_file(self):
"""Test copying a single file."""
from update_lib.cmd_copy_lib import _copy_single
with tempfile.TemporaryDirectory() as tmpdir:
tmpdir = pathlib.Path(tmpdir)
src = tmpdir / "source.py"
src.write_text("content")
dst = tmpdir / "dest.py"
_copy_single(src, dst, verbose=False)
self.assertTrue(dst.exists())
self.assertEqual(dst.read_text(), "content")
def test_copies_directory(self):
"""Test copying a directory."""
from update_lib.cmd_copy_lib import _copy_single
with tempfile.TemporaryDirectory() as tmpdir:
tmpdir = pathlib.Path(tmpdir)
src = tmpdir / "source_dir"
src.mkdir()
(src / "file.py").write_text("content")
dst = tmpdir / "dest_dir"
_copy_single(src, dst, verbose=False)
self.assertTrue(dst.exists())
self.assertTrue((dst / "file.py").exists())
def test_removes_existing_before_copy(self):
"""Test that existing destination is removed before copy."""
from update_lib.cmd_copy_lib import _copy_single
with tempfile.TemporaryDirectory() as tmpdir:
tmpdir = pathlib.Path(tmpdir)
src = tmpdir / "source.py"
src.write_text("new content")
dst = tmpdir / "dest.py"
dst.write_text("old content")
_copy_single(src, dst, verbose=False)
self.assertEqual(dst.read_text(), "new content")
class TestCopyLib(unittest.TestCase):
"""Tests for copy_lib function."""
def test_raises_on_path_without_lib(self):
"""Test that copy_lib raises ValueError when path doesn't contain /Lib/."""
from update_lib.cmd_copy_lib import copy_lib
with self.assertRaises(ValueError) as ctx:
copy_lib(pathlib.Path("some/path/without/lib.py"))
self.assertIn("/Lib/", str(ctx.exception))
if __name__ == "__main__":
unittest.main()