[Calypso] [PATCH 1/4] tests: move git repo setup to a separate class

Guido G√ľnther agx at sigxcpu.org
Sat Oct 22 10:28:25 PDT 2016


and set up author and email to reduce clutter
---
 tests/test_collection.py         | 15 +++------------
 tests/test_matchfilterelement.py | 14 +++-----------
 tests/testutils.py               | 20 ++++++++++++++++++++
 3 files changed, 26 insertions(+), 23 deletions(-)
 create mode 100644 tests/testutils.py

diff --git a/tests/test_collection.py b/tests/test_collection.py
index 489d387..26612e4 100644
--- a/tests/test_collection.py
+++ b/tests/test_collection.py
@@ -1,29 +1,20 @@
 # vim: set fileencoding=utf-8 :
-"""Test L{gbp.command_wrappers.Command}'s tarball unpack"""
 
 import subprocess
 import tempfile
 import shutil
 import unittest
 
-import calypso.config
 from calypso.webdav import Collection
 from calypso import paths
 
+from .testutils import CalypsoTestCase
 
-class TestCollection(unittest.TestCase):
+
+class TestCollection(CalypsoTestCase):
     test_vcard = "tests/data/import.vcard"
     test_resource_with_slash = "tests/data/from-tripsync.ics"
 
-    def setUp(self):
-        self.tmpdir = tempfile.mkdtemp()
-        calypso.config.set('storage', 'folder', self.tmpdir)
-        subprocess.call(["git", "init", self.tmpdir]),
-
-    def tearDown(self):
-        if self.tmpdir:
-            shutil.rmtree(self.tmpdir)
-
     def test_import_file(self):
         collection = Collection("")
         self.assertTrue(collection.import_file(self.test_vcard))
diff --git a/tests/test_matchfilterelement.py b/tests/test_matchfilterelement.py
index ca28285..ea070f7 100644
--- a/tests/test_matchfilterelement.py
+++ b/tests/test_matchfilterelement.py
@@ -7,22 +7,14 @@ import shutil
 import unittest
 import xml.etree.ElementTree as ET
 
-import calypso.config
 from calypso.webdav import Collection
 from calypso import xmlutils
 
+from .testutils import CalypsoTestCase
 
-class TestMatchFilterElement(unittest.TestCase):
-    test_vcal = "tests/data/import.vcalendar"
-
-    def setUp(self):
-        self.tmpdir = tempfile.mkdtemp()
-        calypso.config.set('storage', 'folder', self.tmpdir)
-        subprocess.call(["git", "init", self.tmpdir]),
 
-    def tearDown(self):
-        if self.tmpdir:
-            shutil.rmtree(self.tmpdir)
+class TestMatchFilterElement(CalypsoTestCase):
+    test_vcal = "tests/data/import.vcalendar"
 
     def test_start_end(self):
         """
diff --git a/tests/testutils.py b/tests/testutils.py
new file mode 100644
index 0000000..fd9c94d
--- /dev/null
+++ b/tests/testutils.py
@@ -0,0 +1,20 @@
+import shutil
+import subprocess
+import tempfile
+import unittest
+
+import calypso.config
+
+
+class CalypsoTestCase(unittest.TestCase):
+
+    def setUp(self):
+        self.tmpdir = tempfile.mkdtemp()
+        calypso.config.set('storage', 'folder', self.tmpdir)
+        subprocess.call(["git", "init", self.tmpdir])
+        subprocess.call(["git", "config", "user.email", "calypso at example.com"], cwd=self.tmpdir)
+        subprocess.call(["git", "config", "user.name", "cal Ypso"], cwd=self.tmpdir)
+
+    def tearDown(self):
+        if self.tmpdir:
+            shutil.rmtree(self.tmpdir)
-- 
2.9.3



More information about the Calypso mailing list