[chronojump] chronojump-importer test: refactors code to prepapre database data to be able to test the encoder im



commit 8162f189ac3ecea87ef2cea00dca4eb1ad118347
Author: Carles Pina i Estany <carles pina cat>
Date:   Mon Oct 10 17:50:02 2016 +0200

    chronojump-importer test: refactors code to prepapre database data to be able to test the encoder 
importer easier.

 .../chronojump_importer_test.py                    |   43 ++++++++++++--------
 1 files changed, 26 insertions(+), 17 deletions(-)
---
diff --git a/src/chronojump-importer/chronojump_importer_test.py 
b/src/chronojump-importer/chronojump_importer_test.py
index 23ef524..01b4386 100755
--- a/src/chronojump-importer/chronojump_importer_test.py
+++ b/src/chronojump-importer/chronojump_importer_test.py
@@ -1,5 +1,6 @@
 #!/usr/bin/env python3
 
+import unittest.mock
 import unittest
 import chronojump_importer
 import os
@@ -17,21 +18,8 @@ class TestImporter(unittest.TestCase):
     def tearDown(self):
         pass
 
-    # lists the names. {} will expand to source/destination/expected.
-    @ddt.data(
-        {'base_filename': 'generic-{}-a.sqlite', 'session': 1},
-        {'base_filename': 'generic-{}-b.sqlite', 'session': 1},
-        {'base_filename': 'generic-{}-c.sqlite', 'session': 1},
-        {'base_filename': 'padu-{}.sqlite', 'session': 19},
-        {'base_filename': 'yoyo-{}.sqlite', 'session': 19},
-        {'base_filename': 'user-jump-{}.sqlite', 'session': 1}
-    )
-    def test_importerGeneric(self, data):
-        re_creates_test = False  # During development change it to True
-                                 # to execute the tests and copy the new
-                                 # result as expected test
-
-        base_filename = data['base_filename']
+    @staticmethod
+    def _prepare_database_to_import(base_filename):
         source_file_name = base_filename.format('source')
         destination_file_name = base_filename.format('destination')
         expected_file_name = base_filename.format('expected')
@@ -39,7 +27,6 @@ class TestImporter(unittest.TestCase):
 
         temporary_directory_path = tempfile.mkdtemp(
             prefix="chronojump_importer_test_{}".format(base_filename.replace("{}", "")))
-
         source_file_path = "{}/{}".format(temporary_directory_path, source_file_name)
         destination_file_path = "{}/{}".format(temporary_directory_path, destination_file_name)
         original_destination_file_path = "{}/{}".format(temporary_directory_path, 
original_destination_file_path)
@@ -48,6 +35,25 @@ class TestImporter(unittest.TestCase):
         shutil.copy("tests/{}".format(destination_file_name), destination_file_path)
         shutil.copy("tests/{}".format(destination_file_name), original_destination_file_path)
 
+        return (source_file_path, destination_file_path, expected_file_name, temporary_directory_path)
+
+    # lists the names. {} will expand to source/destination/expected.
+    @ddt.data(
+        {'base_filename': 'generic-{}-a.sqlite', 'session': 1},
+        {'base_filename': 'generic-{}-b.sqlite', 'session': 1},
+        {'base_filename': 'generic-{}-c.sqlite', 'session': 1},
+        {'base_filename': 'padu-{}.sqlite', 'session': 19},
+        {'base_filename': 'yoyo-{}.sqlite', 'session': 19},
+        {'base_filename': 'user-jump-{}.sqlite', 'session': 1}
+    )
+    def test_importerGeneric(self, data):
+        re_creates_test = False  # During development change it to True
+                                 # to execute the tests and copy the new
+                                 # result as expected test
+
+        (source_file_path, destination_file_path, expected_file_name, temporary_directory_path) = \
+            self._prepare_database_to_import(data["base_filename"])
+
         importer = chronojump_importer.ImportSession(source_file_path, destination_file_path, None)
         importer.import_as_new_session(1)
 
@@ -71,7 +77,7 @@ class TestImporter(unittest.TestCase):
         if diff != "":
             # Just to help where the files are when debugging
             print("Temporary directory: ", temporary_directory_path)
-            print("Base filename: ", base_filename)
+            print("Base filename: ", data["base_filename"])
 
         if re_creates_test:
             shutil.copy(destination_file_path, "tests/" + expected_file_name)
@@ -81,6 +87,9 @@ class TestImporter(unittest.TestCase):
 
         shutil.rmtree(temporary_directory_path)
 
+    def test_import_encoder(self):
+        pass
+
     def test_databaseVersion(self):
         database_file = "tests/yoyo-source.sqlite"
         information = chronojump_importer.json_information(database_file)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]