Skip to content

Commit c6df67d

Browse files
committed
Add TestCase that creates and uses a temp dir
1 parent 1e0567f commit c6df67d

2 files changed

Lines changed: 20 additions & 7 deletions

File tree

test/unit/__init__.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import os
2+
import shutil
3+
import tempfile
4+
import unittest
5+
6+
7+
class TmpDirTestCase(unittest.TestCase):
8+
9+
def setUp(self):
10+
super().setUp()
11+
self.prev_wd = os.getcwd()
12+
self.tmp_dir = tempfile.mkdtemp()
13+
os.chdir(self.tmp_dir)
14+
15+
def tearDown(self):
16+
os.chdir(self.prev_wd)
17+
shutil.rmtree(self.tmp_dir)
18+
super().tearDown()

test/unit/test_dss_client.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import logging
44
import os
55
import random
6-
import shutil
76
import tempfile
87
import threading
98
import time
@@ -13,6 +12,7 @@
1312
from mock import patch
1413
from hca.util.compat import walk
1514
from hca.dss import DSSClient, ManifestDownloadContext, TaskRunner
15+
from test.unit import TmpDirTestCase
1616

1717
logging.basicConfig()
1818

@@ -92,7 +92,7 @@ def _fake_do_download_file_with_barrier(*args, **kwargs):
9292
return 'FAKEhash'
9393

9494

95-
class DSSClientTestCase(unittest.TestCase):
95+
class DSSClientTestCase(TmpDirTestCase):
9696
maxDiff = None
9797
manifest = list(zip(
9898
('bundle_uuid', 'a_uuid', 'b_uuid', 'c_uuid'),
@@ -112,16 +112,11 @@ class DSSClientTestCase(unittest.TestCase):
112112

113113
def setUp(self):
114114
super().setUp()
115-
self.prev_wd = os.getcwd()
116-
self.tmp_dir = tempfile.mkdtemp()
117-
os.chdir(self.tmp_dir)
118115
self.dss = DSSClient()
119116
self._write_manifest(self.manifest)
120117
self.manifest_file = 'manifest.tsv'
121118

122119
def tearDown(self):
123-
os.chdir(self.prev_wd)
124-
shutil.rmtree(self.tmp_dir)
125120
super().tearDown()
126121

127122
def _write_manifest(self, manifest):

0 commit comments

Comments
 (0)