forked from micropython/micropython-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_shutil.py
More file actions
56 lines (42 loc) · 1.33 KB
/
Copy pathtest_shutil.py
File metadata and controls
56 lines (42 loc) · 1.33 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
"""
Don't use ``tempfile`` in these tests, as ``tempfile`` relies on ``shutil``.
"""
import os
import shutil
import unittest
class TestRmtree(unittest.TestCase):
def test_dir_dne(self):
with self.assertRaises(OSError):
os.stat("foo")
with self.assertRaises(OSError):
shutil.rmtree("foo")
def test_file(self):
fn = "foo"
with open(fn, "w"):
pass
with self.assertRaises(OSError):
shutil.rmtree(fn)
os.remove(fn)
def test_empty_dir(self):
with self.assertRaises(OSError):
# If this triggers, a previous test didn't clean up.
# bit of a chicken/egg situation with ``tempfile``
os.stat("foo")
os.mkdir("foo")
shutil.rmtree("foo")
with self.assertRaises(OSError):
os.stat("foo")
def test_dir(self):
with self.assertRaises(OSError):
# If this triggers, a previous test didn't clean up.
# bit of a chicken/egg situation with ``tempfile``
os.stat("foo")
os.mkdir("foo")
os.mkdir("foo/bar")
with open("foo/bar/baz1.txt", "w"):
pass
with open("foo/bar/baz2.txt", "w"):
pass
shutil.rmtree("foo")
with self.assertRaises(OSError):
os.stat("foo")