21
21
logger = logging .getLogger ("dvc" )
22
22
23
23
24
- class EmptyDirFixture (object ):
25
- def __init__ (self ):
26
- root_dir = self .mkdtemp ()
27
- self ._root_dir = os .path .realpath (root_dir )
28
-
29
- @property
30
- def root_dir (self ):
31
- return self ._root_dir
32
-
33
- def _pushd (self , d ):
34
- if not hasattr (self , "_saved_dir" ):
35
- self ._saved_dir = os .path .realpath (os .curdir )
36
- os .chdir (d )
37
-
38
- def _popd (self ):
39
- os .chdir (self ._saved_dir )
40
- self ._saved_dir = None
41
-
42
- @staticmethod
43
- def mkdtemp (base_directory = None ):
44
- prefix = "dvc-test.{}." .format (os .getpid ())
45
- suffix = ".{}" .format (shortuuid .uuid ())
46
- return tempfile .mkdtemp (
47
- prefix = prefix , suffix = suffix , dir = base_directory
48
- )
49
-
50
- def setUp (self ):
51
- self ._pushd (self ._root_dir )
52
-
53
- def tearDown (self ):
54
- self ._popd ()
55
- try :
56
- remove (self ._root_dir )
57
- except OSError as exc :
58
- # We ignore this under Windows with a warning because it happened
59
- # to be really hard to trace all not properly closed files.
60
- #
61
- # Best guess so far is that gitpython is the culprit:
62
- # it opens files and uses __del__ to close them, which can happen
63
- # late in current pythons. TestGitFixture and TestDvcFixture try
64
- # to close that and it works on most of the tests, but not all.
65
- # Repos and thus git repos are created all over the dvc ;)
66
- if os .name == "nt" and exc .winerror == 32 :
67
- warnings .warn ("Failed to remove test dir: " + str (exc ))
68
- else :
69
- raise
70
-
71
-
72
- class TestDirFixture (EmptyDirFixture ):
24
+ class TestDirFixture (object ):
73
25
DATA_DIR = "data_dir"
74
26
DATA_SUB_DIR = os .path .join (DATA_DIR , "data_sub_dir" )
75
27
DATA = os .path .join (DATA_DIR , "data" )
@@ -97,6 +49,23 @@ class TestDirFixture(EmptyDirFixture):
97
49
UNICODE = "тест"
98
50
UNICODE_CONTENTS = "проверка"
99
51
52
+ def __init__ (self ):
53
+ root_dir = self .mkdtemp ()
54
+ self ._root_dir = os .path .realpath (root_dir )
55
+
56
+ @property
57
+ def root_dir (self ):
58
+ return self ._root_dir
59
+
60
+ def _pushd (self , d ):
61
+ if not hasattr (self , "_saved_dir" ):
62
+ self ._saved_dir = os .path .realpath (os .curdir )
63
+ os .chdir (d )
64
+
65
+ def _popd (self ):
66
+ os .chdir (self ._saved_dir )
67
+ self ._saved_dir = None
68
+
100
69
def create (self , name , contents ):
101
70
dname = os .path .dirname (name )
102
71
if len (dname ) > 0 and not os .path .isdir (dname ):
@@ -109,8 +78,16 @@ def create(self, name, contents):
109
78
else contents .decode ("utf-8" )
110
79
)
111
80
81
+ @staticmethod
82
+ def mkdtemp (base_directory = None ):
83
+ prefix = "dvc-test.{}." .format (os .getpid ())
84
+ suffix = ".{}" .format (shortuuid .uuid ())
85
+ return tempfile .mkdtemp (
86
+ prefix = prefix , suffix = suffix , dir = base_directory
87
+ )
88
+
112
89
def setUp (self ):
113
- super ( TestDirFixture , self ). setUp ( )
90
+ self . _pushd ( self . _root_dir )
114
91
self .create (self .FOO , self .FOO_CONTENTS )
115
92
self .create (self .BAR , self .BAR_CONTENTS )
116
93
self .create (self .CODE , self .CODE_CONTENTS )
@@ -120,6 +97,24 @@ def setUp(self):
120
97
self .create (self .DATA_SUB , self .DATA_SUB_CONTENTS )
121
98
self .create (self .UNICODE , self .UNICODE_CONTENTS )
122
99
100
+ def tearDown (self ):
101
+ self ._popd ()
102
+ try :
103
+ remove (self ._root_dir )
104
+ except OSError as exc :
105
+ # We ignore this under Windows with a warning because it happened
106
+ # to be really hard to trace all not properly closed files.
107
+ #
108
+ # Best guess so far is that gitpython is the culprit:
109
+ # it opens files and uses __del__ to close them, which can happen
110
+ # late in current pythons. TestGitFixture and TestDvcFixture try
111
+ # to close that and it works on most of the tests, but not all.
112
+ # Repos and thus git repos are created all over the dvc ;)
113
+ if os .name == "nt" and exc .winerror == 32 :
114
+ warnings .warn ("Failed to remove test dir: " + str (exc ))
115
+ else :
116
+ raise
117
+
123
118
124
119
class TestGitFixture (TestDirFixture ):
125
120
N_RETRIES = 5
0 commit comments