[tracker-miners/sam/functional-tests] Fix issues with file handling



commit db33d0f5e8b531ecf6f190c6e095f642811aee78
Author: Sam Thursfield <sam afuera me uk>
Date:   Tue Jul 17 19:30:07 2018 +0200

    Fix issues with file handling

 tests/functional-tests/410-extractor-decorator.py | 42 +++++++++++++----------
 tests/functional-tests/common/utils/minertest.py  |  2 ++
 2 files changed, 25 insertions(+), 19 deletions(-)
---
diff --git a/tests/functional-tests/410-extractor-decorator.py 
b/tests/functional-tests/410-extractor-decorator.py
index 0cd4ec55d..59fba795b 100755
--- a/tests/functional-tests/410-extractor-decorator.py
+++ b/tests/functional-tests/410-extractor-decorator.py
@@ -31,20 +31,9 @@ import time
 
 import common.utils.configuration as cfg
 from common.utils.helpers import log
-from common.utils.minertest import MINER_TMP_DIR, path, uri
 from common.utils.system import TrackerSystemAbstraction
 
 
-CONF_OPTIONS = {
-    cfg.DCONF_MINER_SCHEMA: {
-        'index-recursive-directories': GLib.Variant.new_strv([]),
-        'index-single-directories': GLib.Variant.new_strv([MINER_TMP_DIR]),
-        'index-optical-discs': GLib.Variant.new_boolean(False),
-        'index-removable-devices': GLib.Variant.new_boolean(False),
-    }
-}
-
-
 CORRUPT_FILE = os.path.join(
     os.path.dirname(__file__), 'test-extraction-data', 'audio',
     'audio-corrupt.mp3')
@@ -57,20 +46,35 @@ VALID_FILE_TITLE = 'Simply Juvenile'
 
 TRACKER_EXTRACT_FAILURE_DATA_SOURCE = 'tracker:extractor-failure-data-source'
 
+def ensure_dir_exists(dirname):
+    if not os.path.exists(dirname):
+        os.makedirs(dirname)
+
 
 class ExtractorDecoratorTest(ut.TestCase):
     def setUp(self):
-        if not os.path.exists(MINER_TMP_DIR):
-            os.makedirs(MINER_TMP_DIR)
-        assert os.path.isdir(MINER_TMP_DIR)
-
-        self.system = TrackerSystemAbstraction(CONF_OPTIONS)
+        ensure_dir_exists(cfg.TEST_MONITORED_TMP_DIR)
+
+        # It's important that this directory is NOT inside /tmp, because
+        # monitoring files in /tmp usually doesn't work.
+        self.datadir = tempfile.mkdtemp(dir=cfg.TEST_MONITORED_TMP_DIR)
+
+        config = {
+            cfg.DCONF_MINER_SCHEMA: {
+                'index-recursive-directories': GLib.Variant.new_strv([]),
+                'index-single-directories': GLib.Variant.new_strv([self.datadir]),
+                'index-optical-discs': GLib.Variant.new_boolean(False),
+                'index-removable-devices': GLib.Variant.new_boolean(False),
+            }
+        }
+
+        self.system = TrackerSystemAbstraction(config)
         self.system.tracker_miner_fs_testing_start()
 
     def tearDown(self):
         self.system.tracker_miner_fs_testing_stop()
 
-        shutil.rmtree(MINER_TMP_DIR)
+        shutil.rmtree(self.datadir)
 
     @ut.skip("Currently fails; possible regression")
     def test_reextraction(self):
@@ -79,7 +83,7 @@ class ExtractorDecoratorTest(ut.TestCase):
         store = self.system.store
 
         # Insert a valid file and wait extraction of its metadata.
-        file_path = os.path.join(MINER_TMP_DIR, os.path.basename(VALID_FILE))
+        file_path = os.path.join(self.datadir, os.path.basename(VALID_FILE))
         shutil.copy(VALID_FILE, file_path)
         file_id, file_urn = store.await_resource_inserted(
             VALID_FILE_CLASS, title=VALID_FILE_TITLE)
@@ -93,7 +97,7 @@ class ExtractorDecoratorTest(ut.TestCase):
 
         log("Sending re-index request")
         # Request re-indexing (same as `tracker index --file ...`)
-        miner_fs.index_file(uri(file_path))
+        miner_fs.index_file('file://' + os.path.join (self.datadir, file_path))
 
         # The extractor should reindex the file and re-add the metadata that we
         # deleted, so we should see the nie:title property change.
diff --git a/tests/functional-tests/common/utils/minertest.py 
b/tests/functional-tests/common/utils/minertest.py
index 1ba75adae..995cd6f4e 100644
--- a/tests/functional-tests/common/utils/minertest.py
+++ b/tests/functional-tests/common/utils/minertest.py
@@ -40,6 +40,8 @@ def ensure_dir_exists(dirname):
 
 class CommonTrackerMinerTest (ut.TestCase):
     def setUp (self):
+        ensure_dir_exists(cfg.TEST_MONITORED_TMP_DIR)
+
         # It's important that this directory is NOT inside /tmp, because
         # monitoring files in /tmp usually doesn't work.
         self.datadir = tempfile.mkdtemp(dir=cfg.TEST_MONITORED_TMP_DIR)


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