[chronojump] Adds unit test for encoder_importer_files.
- From: Carles Pina i Estany <carlespina src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] Adds unit test for encoder_importer_files.
- Date: Mon, 10 Oct 2016 17:23:09 +0000 (UTC)
commit 962e50fa7f793b73e1c5fd68b6f231e1386f0f4d
Author: Carles Pina i Estany <carles pina cat>
Date: Mon Oct 10 18:58:31 2016 +0200
Adds unit test for encoder_importer_files.
In _encoder_url() uses os.path.join() to join components of a path
instead of using forward slashes.
Detected another problem in the path, will fix soon.
src/chronojump-importer/chronojump_importer.py | 4 +-
.../chronojump_importer_test.py | 33 +++++++++++++++-----
2 files changed, 27 insertions(+), 10 deletions(-)
---
diff --git a/src/chronojump-importer/chronojump_importer.py b/src/chronojump-importer/chronojump_importer.py
index ded0390..5a4115d 100755
--- a/src/chronojump-importer/chronojump_importer.py
+++ b/src/chronojump-importer/chronojump_importer.py
@@ -591,7 +591,7 @@ class ImportSession:
@staticmethod
def _encoder_url(session_id, signal_or_curve):
- return 'encoder/data/{session_id}/{signal_or_curve}'.format(session_id=session_id,
signal_or_curve=signal_or_curve)
+ return os.path.join("encoder", "data", str(session_id), signal_or_curve)
def _import_encoder_files(self, encoder_table):
if self.source_base_directory is None:
@@ -608,7 +608,7 @@ class ImportSession:
# Prepares the new filename and destination_url
filename=self._encoder_filename(person_id, original_filename)
- destination_url=self._encoder_url(session_id, signal_or_curve)
+ destination_url = self._encoder_url(session_id, signal_or_curve)
# Sets it to the row
row.set("filename", filename)
diff --git a/src/chronojump-importer/chronojump_importer_test.py
b/src/chronojump-importer/chronojump_importer_test.py
index 2653452..a5502b1 100755
--- a/src/chronojump-importer/chronojump_importer_test.py
+++ b/src/chronojump-importer/chronojump_importer_test.py
@@ -42,11 +42,11 @@ class TestImporter(unittest.TestCase):
{'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': 'padu-{}.sqlite', 'session': 1},
+ {'base_filename': 'yoyo-{}.sqlite', 'session': 1},
{'base_filename': 'user-jump-{}.sqlite', 'session': 1}
)
- def test_importerGeneric(self, data):
+ def test_importer_generic(self, data):
re_creates_test = False # During development change it to True
# to execute the tests and copy the new
# result as expected test
@@ -55,7 +55,7 @@ class TestImporter(unittest.TestCase):
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)
+ importer.import_as_new_session(data["session"])
os.system(
"echo .dump | sqlite3 {} > {}/destination.sql".format(destination_file_path,
temporary_directory_path))
@@ -87,8 +87,25 @@ class TestImporter(unittest.TestCase):
shutil.rmtree(temporary_directory_path)
- def test_import_encoder(self):
- pass
+ @unittest.mock.patch("os.makedirs", side_effect=os.makedirs)
+ @unittest.mock.patch("shutil.copy", side_effect=shutil.copy)
+ def test_import_encoder_files(self, copy_function, makedirs_function):
+ (source_file_path, destination_file_path, expected_file_name, temporary_directory_path) = \
+ self._prepare_database_to_import("yoyo-{}.sqlite")
+
+ importer = chronojump_importer.ImportSession(source_file_path, destination_file_path,
"fake-base-directory")
+
+ # Mock couldn't be done earlier because these methods are used by sqlite3 when opening the database.
+ copy_function.reset_mock()
+ makedirs_function.reset_mock()
+
+ copy_function.side_effect = None
+ makedirs_function.side_effect = None
+
+ importer.import_as_new_session(7)
+
+ self.assertTrue(copy_function.called)
+ self.assertEqual(copy_function.call_count, 11) # 11 encoding for session number 7
def test_encoder_filename(self):
new_filename = chronojump_importer.ImportSession._encoder_filename(10, "19-test.txt")
@@ -96,9 +113,9 @@ class TestImporter(unittest.TestCase):
def test_encoder_url(self):
new_url = chronojump_importer.ImportSession._encoder_url(11, "signal")
- self.assertEqual("encoder/data/11/signal", new_url)
+ self.assertEqual(os.path.join("encoder", "data", "11", "signal"), new_url)
- def test_databaseVersion(self):
+ def test_database_version(self):
database_file = "tests/yoyo-source.sqlite"
information = chronojump_importer.json_information(database_file)
print(information)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]