File tree Expand file tree Collapse file tree 1 file changed +56
-0
lines changed Expand file tree Collapse file tree 1 file changed +56
-0
lines changed Original file line number Diff line number Diff line change 1+ """
2+ Don't use ``tempfile`` in these tests, as ``tempfile`` relies on ``shutil``.
3+ """
4+
5+ import os
6+ import shutil
7+ import unittest
8+
9+
10+ class TestRmtree (unittest .TestCase ):
11+ def test_dir_dne (self ):
12+ with self .assertRaises (OSError ):
13+ os .stat ("foo" )
14+
15+ with self .assertRaises (OSError ):
16+ shutil .rmtree ("foo" )
17+
18+ def test_file (self ):
19+ fn = "foo"
20+ with open (fn , "w" ):
21+ pass
22+
23+ with self .assertRaises (OSError ):
24+ shutil .rmtree (fn )
25+
26+ os .remove (fn )
27+
28+ def test_empty_dir (self ):
29+ with self .assertRaises (OSError ):
30+ # If this triggers, a previous test didn't clean up.
31+ # bit of a chicken/egg situation with ``tempfile``
32+ os .stat ("foo" )
33+
34+ os .mkdir ("foo" )
35+ shutil .rmtree ("foo" )
36+
37+ with self .assertRaises (OSError ):
38+ os .stat ("foo" )
39+
40+ def test_dir (self ):
41+ with self .assertRaises (OSError ):
42+ # If this triggers, a previous test didn't clean up.
43+ # bit of a chicken/egg situation with ``tempfile``
44+ os .stat ("foo" )
45+
46+ os .mkdir ("foo" )
47+ os .mkdir ("foo/bar" )
48+ with open ("foo/bar/baz1.txt" , "w" ):
49+ pass
50+ with open ("foo/bar/baz2.txt" , "w" ):
51+ pass
52+
53+ shutil .rmtree ("foo" )
54+
55+ with self .assertRaises (OSError ):
56+ os .stat ("foo" )
You can’t perform that action at this time.
0 commit comments