summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMichał Górny <mgorny@gentoo.org>2017-10-25 09:44:49 +0200
committerMichał Górny <mgorny@gentoo.org>2017-10-25 09:44:49 +0200
commit5ab985a8d4a9bb8bc3b7ec4dd5c519aa44cbe3a6 (patch)
tree3aa430f5c31c5a3399a5160ac75e42911c7a0958 /tests
parentb8a46d60e78e99afd1e76629a669ff15eafeef7c (diff)
downloadgemato-5ab985a8d4a9bb8bc3b7ec4dd5c519aa44cbe3a6.tar.gz
tests: Split TempDirTestCase into common module
Diffstat (limited to 'tests')
-rw-r--r--tests/test_recursiveloader.py23
-rw-r--r--tests/testutil.py30
2 files changed, 31 insertions, 22 deletions
diff --git a/tests/test_recursiveloader.py b/tests/test_recursiveloader.py
index 7889956..bc98fb7 100644
--- a/tests/test_recursiveloader.py
+++ b/tests/test_recursiveloader.py
@@ -4,33 +4,12 @@
# Licensed under the terms of 2-clause BSD license
import datetime
-import io
import os
-import tempfile
-import unittest
import gemato.exceptions
import gemato.recursiveloader
-
-class TempDirTestCase(unittest.TestCase):
- DIRS = []
- FILES = {}
-
- def setUp(self):
- self.dir = tempfile.mkdtemp()
- for k in self.DIRS:
- os.mkdir(os.path.join(self.dir, k))
- for k, v in self.FILES.items():
- with io.open(os.path.join(self.dir, k), 'w', encoding='utf8') as f:
- f.write(v)
-
- def tearDown(self):
- for k in self.FILES:
- os.unlink(os.path.join(self.dir, k))
- for k in reversed(self.DIRS):
- os.rmdir(os.path.join(self.dir, k))
- os.rmdir(self.dir)
+from tests.testutil import TempDirTestCase
class BasicNestingTest(TempDirTestCase):
diff --git a/tests/testutil.py b/tests/testutil.py
new file mode 100644
index 0000000..170b83b
--- /dev/null
+++ b/tests/testutil.py
@@ -0,0 +1,30 @@
+# gemato: Test utility functions
+# vim:fileencoding=utf-8
+# (c) 2017 Michał Górny
+# Licensed under the terms of 2-clause BSD license
+
+import io
+import os
+import os.path
+import tempfile
+import unittest
+
+
+class TempDirTestCase(unittest.TestCase):
+ DIRS = []
+ FILES = {}
+
+ def setUp(self):
+ self.dir = tempfile.mkdtemp()
+ for k in self.DIRS:
+ os.mkdir(os.path.join(self.dir, k))
+ for k, v in self.FILES.items():
+ with io.open(os.path.join(self.dir, k), 'w', encoding='utf8') as f:
+ f.write(v)
+
+ def tearDown(self):
+ for k in self.FILES:
+ os.unlink(os.path.join(self.dir, k))
+ for k in reversed(self.DIRS):
+ os.rmdir(os.path.join(self.dir, k))
+ os.rmdir(self.dir)