Commit 49b169fe authored by Sam Thursfield's avatar Sam Thursfield

functional-tests: Isolate the test data for each miner test

Previously all tests would share one data directory, which obviously
broke when we started running the tests in parallel with Meson.
parent 82c8c55d
......@@ -31,7 +31,7 @@ import time
import unittest2 as ut
from common.utils.helpers import log
from common.utils.minertest import CommonTrackerMinerTest, MINER_TMP_DIR, uri, path
from common.utils.minertest import CommonTrackerMinerTest
class MinerCrawlTest (CommonTrackerMinerTest):
"""
......@@ -51,7 +51,7 @@ class MinerCrawlTest (CommonTrackerMinerTest):
?u a nfo:FileDataObject ;
nie:url \"%s\" .
}
""" % (uri (filepath)))
""" % (self.uri (filepath)))
self.assertEquals (len (result), 1)
return result[0][0]
......@@ -61,7 +61,7 @@ class MinerCrawlTest (CommonTrackerMinerTest):
?u a nfo:FileDataObject ;
nie:url \"%s\" .
}
""" % (uri (filepath)))
""" % (self.uri (filepath)))
self.assertEquals (len (result), 1)
return result[0][0]
......@@ -77,9 +77,9 @@ class MinerCrawlTest (CommonTrackerMinerTest):
result = self.__get_text_documents ()
self.assertEquals (len (result), 3)
unpacked_result = [ r[0] for r in result]
self.assertIn ( uri ("test-monitored/file1.txt"), unpacked_result)
self.assertIn ( uri ("test-monitored/dir1/file2.txt"), unpacked_result)
self.assertIn ( uri ("test-monitored/dir1/dir2/file3.txt"), unpacked_result)
self.assertIn ( self.uri ("test-monitored/file1.txt"), unpacked_result)
self.assertIn ( self.uri ("test-monitored/dir1/file2.txt"), unpacked_result)
self.assertIn ( self.uri ("test-monitored/dir1/dir2/file3.txt"), unpacked_result)
# We don't check (yet) folders, because Applications module is injecting results
......@@ -94,20 +94,20 @@ class MinerCrawlTest (CommonTrackerMinerTest):
Copy an file from unmonitored directory to monitored directory
and verify if data base is updated accordingly
"""
source = os.path.join (MINER_TMP_DIR, "test-no-monitored", "file0.txt")
dest = os.path.join (MINER_TMP_DIR, "test-monitored", "file0.txt")
source = os.path.join (self.datadir, "test-no-monitored", "file0.txt")
dest = os.path.join (self.datadir, "test-monitored", "file0.txt")
shutil.copyfile (source, dest)
dest_id, dest_urn = self.system.store.await_resource_inserted ('nfo:TextDocument', uri(dest))
dest_id, dest_urn = self.system.store.await_resource_inserted ('nfo:TextDocument', self.uri(dest))
# verify if miner indexed this file.
result = self.__get_text_documents ()
self.assertEquals (len (result), 4)
unpacked_result = [ r[0] for r in result]
self.assertIn ( uri ("test-monitored/file1.txt"), unpacked_result)
self.assertIn ( uri ("test-monitored/dir1/file2.txt"), unpacked_result)
self.assertIn ( uri ("test-monitored/dir1/dir2/file3.txt"), unpacked_result)
self.assertIn ( uri ("test-monitored/file0.txt"), unpacked_result)
self.assertIn ( self.uri ("test-monitored/file1.txt"), unpacked_result)
self.assertIn ( self.uri ("test-monitored/dir1/file2.txt"), unpacked_result)
self.assertIn ( self.uri ("test-monitored/dir1/dir2/file3.txt"), unpacked_result)
self.assertIn ( self.uri ("test-monitored/file0.txt"), unpacked_result)
# Clean the new file so the test directory is as before
log ("Remove and wait")
......@@ -121,8 +121,8 @@ class MinerCrawlTest (CommonTrackerMinerTest):
"""
# Copy from monitored to unmonitored
source = os.path.join (MINER_TMP_DIR, "test-monitored", "file1.txt")
dest = os.path.join (MINER_TMP_DIR, "test-no-monitored", "file1.txt")
source = os.path.join (self.datadir, "test-monitored", "file1.txt")
dest = os.path.join (self.datadir, "test-no-monitored", "file1.txt")
shutil.copyfile (source, dest)
time.sleep (1)
......@@ -130,9 +130,9 @@ class MinerCrawlTest (CommonTrackerMinerTest):
result = self.__get_text_documents ()
self.assertEquals (len (result), 3, "Results:" + str(result))
unpacked_result = [ r[0] for r in result]
self.assertIn ( uri ("test-monitored/file1.txt"), unpacked_result)
self.assertIn ( uri ("test-monitored/dir1/file2.txt"), unpacked_result)
self.assertIn ( uri ("test-monitored/dir1/dir2/file3.txt"), unpacked_result)
self.assertIn ( self.uri ("test-monitored/file1.txt"), unpacked_result)
self.assertIn ( self.uri ("test-monitored/dir1/file2.txt"), unpacked_result)
self.assertIn ( self.uri ("test-monitored/dir1/dir2/file3.txt"), unpacked_result)
# Clean the file
os.remove (dest)
......@@ -141,19 +141,19 @@ class MinerCrawlTest (CommonTrackerMinerTest):
"""
Copy a file between monitored directories
"""
source = os.path.join (MINER_TMP_DIR, "test-monitored", "file1.txt")
dest = os.path.join (MINER_TMP_DIR, "test-monitored", "dir1", "dir2", "file-test04.txt")
source = os.path.join (self.datadir, "test-monitored", "file1.txt")
dest = os.path.join (self.datadir, "test-monitored", "dir1", "dir2", "file-test04.txt")
shutil.copyfile (source, dest)
dest_id, dest_urn = self.system.store.await_resource_inserted ('nfo:TextDocument', uri(dest))
dest_id, dest_urn = self.system.store.await_resource_inserted ('nfo:TextDocument', self.uri(dest))
result = self.__get_text_documents ()
self.assertEquals (len (result), 4)
unpacked_result = [ r[0] for r in result]
self.assertIn ( uri ("test-monitored/file1.txt"), unpacked_result)
self.assertIn ( uri ("test-monitored/dir1/file2.txt"), unpacked_result)
self.assertIn ( uri ("test-monitored/dir1/dir2/file3.txt"), unpacked_result)
self.assertIn ( uri ("test-monitored/dir1/dir2/file-test04.txt"), unpacked_result)
self.assertIn ( self.uri ("test-monitored/file1.txt"), unpacked_result)
self.assertIn ( self.uri ("test-monitored/dir1/file2.txt"), unpacked_result)
self.assertIn ( self.uri ("test-monitored/dir1/dir2/file3.txt"), unpacked_result)
self.assertIn ( self.uri ("test-monitored/dir1/dir2/file-test04.txt"), unpacked_result)
# Clean the file
os.remove (dest)
......@@ -165,18 +165,18 @@ class MinerCrawlTest (CommonTrackerMinerTest):
"""
Move a file from unmonitored to monitored directory
"""
source = os.path.join (MINER_TMP_DIR, "test-no-monitored", "file0.txt")
dest = os.path.join (MINER_TMP_DIR, "test-monitored", "dir1", "file-test05.txt")
source = os.path.join (self.datadir, "test-no-monitored", "file0.txt")
dest = os.path.join (self.datadir, "test-monitored", "dir1", "file-test05.txt")
shutil.move (source, dest)
dest_id, dest_urn = self.system.store.await_resource_inserted ('nfo:TextDocument', uri(dest))
dest_id, dest_urn = self.system.store.await_resource_inserted ('nfo:TextDocument', self.uri(dest))
result = self.__get_text_documents ()
self.assertEquals (len (result), 4)
unpacked_result = [ r[0] for r in result]
self.assertIn ( uri ("test-monitored/file1.txt"), unpacked_result)
self.assertIn ( uri ("test-monitored/dir1/file2.txt"), unpacked_result)
self.assertIn ( uri ("test-monitored/dir1/dir2/file3.txt"), unpacked_result)
self.assertIn ( uri ("test-monitored/dir1/file-test05.txt"), unpacked_result)
self.assertIn ( self.uri ("test-monitored/file1.txt"), unpacked_result)
self.assertIn ( self.uri ("test-monitored/dir1/file2.txt"), unpacked_result)
self.assertIn ( self.uri ("test-monitored/dir1/dir2/file3.txt"), unpacked_result)
self.assertIn ( self.uri ("test-monitored/dir1/file-test05.txt"), unpacked_result)
# Clean the file
os.remove (dest)
......@@ -191,21 +191,21 @@ class MinerCrawlTest (CommonTrackerMinerTest):
"""
Move a file from monitored to unmonitored directory
"""
source = path("test-monitored/dir1/file2.txt")
dest = path("test-no-monitored/file2.txt")
source_id = self.system.store.get_resource_id (uri(source))
source = self.path("test-monitored/dir1/file2.txt")
dest = self.path("test-no-monitored/file2.txt")
source_id = self.system.store.get_resource_id (self.uri(source))
shutil.move (source, dest)
self.system.store.await_resource_deleted (source_id)
result = self.__get_text_documents ()
self.assertEquals (len (result), 2)
unpacked_result = [ r[0] for r in result]
self.assertIn ( uri ("test-monitored/file1.txt"), unpacked_result)
self.assertIn ( uri ("test-monitored/dir1/dir2/file3.txt"), unpacked_result)
self.assertIn ( self.uri ("test-monitored/file1.txt"), unpacked_result)
self.assertIn ( self.uri ("test-monitored/dir1/dir2/file3.txt"), unpacked_result)
# Restore the file
shutil.move (dest, source)
self.system.store.await_resource_inserted ('nfo:TextDocument', uri(source))
self.system.store.await_resource_inserted ('nfo:TextDocument', self.uri(source))
self.assertEquals (3, self.tracker.count_instances ("nfo:TextDocument"))
......@@ -214,10 +214,10 @@ class MinerCrawlTest (CommonTrackerMinerTest):
Move a file between monitored directories
"""
source = path("test-monitored/dir1/file2.txt")
dest = path("test-monitored/file2.txt")
source = self.path("test-monitored/dir1/file2.txt")
dest = self.path("test-monitored/file2.txt")
resource_id = self.tracker.get_resource_id(url=uri(source))
resource_id = self.tracker.get_resource_id(url=self.uri(source))
source_dir_urn = self.__get_file_urn (os.path.dirname(source))
parent_before = self.__get_parent_urn (source)
......@@ -236,9 +236,9 @@ class MinerCrawlTest (CommonTrackerMinerTest):
result = self.__get_text_documents ()
self.assertEquals (len (result), 3)
unpacked_result = [ r[0] for r in result]
self.assertIn ( uri ("test-monitored/file1.txt"), unpacked_result)
self.assertIn ( uri ("test-monitored/file2.txt"), unpacked_result)
self.assertIn ( uri ("test-monitored/dir1/dir2/file3.txt"), unpacked_result)
self.assertIn ( self.uri ("test-monitored/file1.txt"), unpacked_result)
self.assertIn ( self.uri ("test-monitored/file2.txt"), unpacked_result)
self.assertIn ( self.uri ("test-monitored/dir1/dir2/file3.txt"), unpacked_result)
# Restore the file
shutil.move (dest, source)
......@@ -247,57 +247,57 @@ class MinerCrawlTest (CommonTrackerMinerTest):
result = self.__get_text_documents ()
self.assertEquals (len (result), 3)
unpacked_result = [ r[0] for r in result]
self.assertIn ( uri ("test-monitored/dir1/file2.txt"), unpacked_result)
self.assertIn ( self.uri ("test-monitored/dir1/file2.txt"), unpacked_result)
def test_08_deletion_single_file (self):
"""
Delete one of the files
"""
victim = path("test-monitored/dir1/file2.txt")
victim_id = self.system.store.get_resource_id (uri(victim))
victim = self.path("test-monitored/dir1/file2.txt")
victim_id = self.system.store.get_resource_id (self.uri(victim))
os.remove (victim)
self.system.store.await_resource_deleted (victim_id)
result = self.__get_text_documents ()
self.assertEquals (len (result), 2)
unpacked_result = [ r[0] for r in result]
self.assertIn ( uri ("test-monitored/file1.txt"), unpacked_result)
self.assertIn ( uri ("test-monitored/dir1/dir2/file3.txt"), unpacked_result)
self.assertIn ( self.uri ("test-monitored/file1.txt"), unpacked_result)
self.assertIn ( self.uri ("test-monitored/dir1/dir2/file3.txt"), unpacked_result)
# Restore the file
f = open (victim, "w")
f.write ("Don't panic, everything is fine")
f.close ()
self.system.store.await_resource_inserted ('nfo:TextDocument', uri(victim))
self.system.store.await_resource_inserted ('nfo:TextDocument', self.uri(victim))
def test_09_deletion_directory (self):
"""
Delete a directory
"""
victim = path("test-monitored/dir1")
victim_id = self.system.store.get_resource_id (uri(victim))
victim = self.path("test-monitored/dir1")
victim_id = self.system.store.get_resource_id (self.uri(victim))
shutil.rmtree (victim)
file_inside_victim_url = uri (os.path.join (victim, "file2.txt"))
file_inside_victim_url = self.uri (os.path.join (victim, "file2.txt"))
file_inside_victim_id = self.system.store.get_resource_id (file_inside_victim_url)
self.system.store.await_resource_deleted (file_inside_victim_id)
result = self.__get_text_documents ()
self.assertEquals (len (result), 1)
unpacked_result = [ r[0] for r in result]
self.assertIn ( uri ("test-monitored/file1.txt"), unpacked_result)
self.assertIn ( self.uri ("test-monitored/file1.txt"), unpacked_result)
# Restore the dirs
os.makedirs (path("test-monitored/dir1"))
os.makedirs (path("test-monitored/dir1/dir2"))
os.makedirs (self.path("test-monitored/dir1"))
os.makedirs (self.path("test-monitored/dir1/dir2"))
for f in ["test-monitored/dir1/file2.txt",
"test-monitored/dir1/dir2/file3.txt"]:
filename = path(f)
filename = self.path(f)
writer = open (filename, "w")
writer.write ("Don't panic, everything is fine")
writer.close ()
self.system.store.await_resource_inserted ('nfo:TextDocument', uri(f))
self.system.store.await_resource_inserted ('nfo:TextDocument', self.uri(f))
# Check everything is fine
result = self.__get_text_documents ()
......@@ -309,4 +309,4 @@ if __name__ == "__main__":
We need to do the same for DIRECTORIES!
"""
ut.main()
ut.main(failfast=True)
......@@ -23,27 +23,13 @@ especially in the case where nie:InformationElement != nie:DataObject
"""
from common.utils import configuration as cfg
from common.utils.minertest import CommonTrackerMinerTest, path, uri
from common.utils.minertest import CommonTrackerMinerTest
from gi.repository import GLib
import os
import unittest2 as ut
MINER_TMP_DIR = cfg.TEST_MONITORED_TMP_DIR
CONF_OPTIONS = {
cfg.DCONF_MINER_SCHEMA: {
'enable-writeback': GLib.Variant.new_boolean(False),
'index-recursive-directories': GLib.Variant.new_strv([MINER_TMP_DIR]),
'index-single-directories': GLib.Variant.new_strv([]),
'index-optical-discs': GLib.Variant.new_boolean(False),
'index-removable-devices': GLib.Variant.new_boolean(False),
'throttle': GLib.Variant.new_int32(5),
}
}
class MinerResourceRemovalTest (CommonTrackerMinerTest):
......@@ -64,14 +50,14 @@ class MinerResourceRemovalTest (CommonTrackerMinerTest):
title = title)
def create_test_file (self, file_name):
file_path = path(file_name)
file_path = self.path(file_name)
file = open (file_path, 'w')
file.write ("Test")
file.close ()
return self.tracker.await_resource_inserted (rdf_class = 'nfo:Document',
url = uri(file_name))
url = self.uri(file_name))
def test_01_file_deletion (self):
"""
......@@ -84,7 +70,7 @@ class MinerResourceRemovalTest (CommonTrackerMinerTest):
(ie_1_id, ie_1_urn) = self.create_test_content (file_1_urn, "Test resource 1")
(ie_2_id, ie_2_urn) = self.create_test_content (file_2_urn, "Test resource 2")
os.unlink (path ("test-monitored/test_1.txt"))
os.unlink (self.path ("test-monitored/test_1.txt"))
self.tracker.await_resource_deleted (file_1_id)
self.tracker.await_resource_deleted (ie_1_id,
......@@ -122,4 +108,4 @@ class MinerResourceRemovalTest (CommonTrackerMinerTest):
if __name__ == "__main__":
ut.main()
ut.main(failfast=True)
......@@ -33,7 +33,7 @@ import time
import unittest2 as ut
from common.utils.helpers import log
from common.utils.minertest import CommonTrackerMinerFTSTest, MINER_TMP_DIR, uri, path, DEFAULT_TEXT
from common.utils.minertest import CommonTrackerMinerFTSTest, DEFAULT_TEXT
from common.utils import configuration as cfg
......@@ -52,11 +52,11 @@ class MinerFTSBasicTest (CommonTrackerMinerFTSTest):
results = self.search_word ("automobile")
self.assertEquals (len (results), 1)
self.assertIn (uri (self.testfile), results)
self.assertIn (self.uri (self.testfile), results)
results = self.search_word ("unlimited")
self.assertEquals (len (results), 1)
self.assertIn (uri (self.testfile), results)
self.assertIn (self.uri (self.testfile), results)
def test_03_long_word (self):
......@@ -105,4 +105,4 @@ class MinerFTSBasicTest (CommonTrackerMinerFTSTest):
if __name__ == "__main__":
ut.main ()
ut.main (failfast=True)
......@@ -33,7 +33,7 @@ import time
import unittest2 as ut
from common.utils.helpers import log
from common.utils.minertest import CommonTrackerMinerFTSTest, MINER_TMP_DIR, uri, path, DEFAULT_TEXT
from common.utils.minertest import CommonTrackerMinerFTSTest, DEFAULT_TEXT
from common.utils import configuration as cfg
......@@ -49,8 +49,8 @@ class MinerFTSFileOperationsTest (CommonTrackerMinerFTSTest):
TEXT = "automobile is red and big and whatnot"
self.basic_test (TEXT, "automobile")
id = self._query_id (uri (self.testfile))
os.remove ( path (self.testfile))
id = self._query_id (self.uri (self.testfile))
os.remove (self.path (self.testfile))
self.tracker.await_resource_deleted (id)
results = self.search_word ("automobile")
......@@ -101,12 +101,12 @@ class MinerFTSFileOperationsTest (CommonTrackerMinerFTSTest):
TEXT = "automobile is red"
TEST_15_FILE = "test-no-monitored/fts-indexing-test-15.txt"
self.__recreate_file (path (TEST_15_FILE), TEXT)
self.__recreate_file (self.path (TEST_15_FILE), TEXT)
results = self.search_word ("automobile")
self.assertEquals (len (results), 0)
os.remove (path (TEST_15_FILE))
os.remove (self.path (TEST_15_FILE))
def test_05_move_file_unmonitored_monitored (self):
"""
......@@ -117,23 +117,23 @@ class MinerFTSFileOperationsTest (CommonTrackerMinerFTSTest):
TEST_16_SOURCE = "test-no-monitored/fts-indexing-text-16.txt"
TEST_16_DEST = "test-monitored/fts-indexing-text-16.txt"
self.__recreate_file (path (TEST_16_SOURCE), TEXT)
self.__recreate_file (self.path (TEST_16_SOURCE), TEXT)
# the file is supposed to be ignored by tracker, so there is no notification..
time.sleep (2)
results = self.search_word ("airplane")
self.assertEquals (len (results), 0)
shutil.copyfile ( path (TEST_16_SOURCE), path (TEST_16_DEST))
shutil.copyfile (self.path (TEST_16_SOURCE), self.path (TEST_16_DEST))
self.tracker.await_resource_inserted (rdf_class = 'nfo:Document',
url = uri(TEST_16_DEST),
url = self.uri(TEST_16_DEST),
required_property = 'nie:plainTextContent')
results = self.search_word ("airplane")
self.assertEquals (len (results), 1)
os.remove ( path (TEST_16_SOURCE))
os.remove ( path (TEST_16_DEST))
os.remove (self.path (TEST_16_SOURCE))
os.remove (self.path (TEST_16_DEST))
# skip test for a file in a hidden directory
......
......@@ -33,7 +33,7 @@ import time
import unittest2 as ut
from common.utils.helpers import log
from common.utils.minertest import CommonTrackerMinerFTSTest, MINER_TMP_DIR, uri, path, DEFAULT_TEXT
from common.utils.minertest import CommonTrackerMinerFTSTest, DEFAULT_TEXT
from common.utils import configuration as cfg
class MinerFTSStopwordsTest (CommonTrackerMinerFTSTest):
......@@ -82,4 +82,4 @@ class MinerFTSStopwordsTest (CommonTrackerMinerFTSTest):
if __name__ == "__main__":
ut.main ()
ut.main (failfast=True)
......@@ -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)
def test_reextraction(self):
"""Tests whether known files are still re-extracted on user request."""
......@@ -78,7 +82,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)
......@@ -92,7 +96,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.
......
......@@ -89,12 +89,16 @@ TEST_TMP_DIR = os.path.join (os.environ["HOME"], "tracker-tests")
TEST_MONITORED_TMP_DIR = TEST_TMP_DIR
if TEST_TMP_DIR.startswith('/tmp'):
if os.environ.has_key('REAL_HOME'):
TEST_MONITORED_TMP_DIR = os.path.join (os.environ["REAL_HOME"], "tracker-tests")
else:
print ("HOME is in the /tmp prefix - this will cause tests that rely " +
"on filesystem monitoring to fail as changes in that prefix are " +
"ignored.")
if os.environ.has_key('REAL_HOME'):
# Note that this MUST NOT be a hidden directory, as Tracker is
# hardcoded to ignore those. The 'ignore-files' configuration option
# can be changed, but the 'filter-hidden' property of
# TrackerIndexingTree is hardwired to be True at present :/
TEST_MONITORED_TMP_DIR = os.path.join (os.environ["REAL_HOME"], "tracker-tests")
else:
print ("HOME is in the /tmp prefix - this will cause tests that rely " +
"on filesystem monitoring to fail as changes in that prefix are " +
"ignored.")
BUILD_DIR = os.environ.get('TRACKER_FUNCTIONAL_TEST_BUILD_DIR')
......
......@@ -107,7 +107,7 @@ class Helper:
self.loop.quit()
def _process_watch_cb (self):
if self.process_watch_timeout == 0:
if self.process_watch_timeout == 0 or self.process is None:
# The GLib seems to call the timeout after we've removed it
# sometimes, which causes errors unless we detect it.
return False
......
#!/usr/bin/env python
#
# Copyright (C) 2010, Nokia <ivan.frade@nokia.com>
# Copyright (C) 2018, Sam Thursfield <sam@afuera.me.uk>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
......@@ -24,50 +25,75 @@ import unittest2 as ut
from gi.repository import GLib
import shutil
import os
import warnings
import shutil
import tempfile
from itertools import chain
MINER_TMP_DIR = cfg.TEST_MONITORED_TMP_DIR
DEFAULT_TEXT = "Some stupid content, to have a test file"
def path (filename):
return os.path.join (MINER_TMP_DIR, filename)
def uri (filename):
return "file://" + os.path.join (MINER_TMP_DIR, filename)
def ensure_dir_exists(dirname):
if not os.path.exists(dirname):
os.makedirs(dirname)
DEFAULT_TEXT = "Some stupid content, to have a test file"
class CommonTrackerMinerTest (ut.TestCase):
def setUp (self):
ensure_dir_exists(cfg.TEST_MONITORED_TMP_DIR)
index_dirs = [os.path.join (MINER_TMP_DIR, "test-monitored")]
CONF_OPTIONS = {
cfg.DCONF_MINER_SCHEMA: {
'index-recursive-directories': GLib.Variant.new_strv(index_dirs),
'index-single-directories': GLib.Variant.new_strv([]),
'index-optical-discs': GLib.Variant.new_boolean(False),
'index-removable-devices': GLib.Variant.new_boolean(False),
'throttle': GLib.Variant.new_int32(5),
}
}
# 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)
self.indexed_dir = os.path.join(self.datadir, 'test-monitored')
class CommonTrackerMinerTest (ut.TestCase):
# It's important that this directory exists BEFORE we start Tracker:
# it won't monitor an indexing root for changes if it doesn't exist,
# it'll silently ignore it instead. See the tracker_crawler_start()
# function.
ensure_dir_exists(self.indexed_dir)
def prepare_directories (self):
#
# ~/test-monitored/
# /file1.txt
# /dir1/
# /file2.txt
# /dir2/
# /file3.txt
#
#
# ~/test-no-monitored/
# /file0.txt
#
self.system = TrackerSystemAbstraction (
settings={
'org.freedesktop.Tracker.Store': {
'graphupdated-delay': GLib.Variant('i', 100)
}
}
)
config = {
cfg.DCONF_MINER_SCHEMA: {
'index-recursive-directories': GLib.Variant.new_strv([self.indexed_dir]),
'index-single-directories': GLib.Variant.new_strv([]),
'index-optical-discs': GLib.Variant.new_boolean(False),
'index-removable-devices': GLib.Variant.new_boolean(False),
'throttle': GLib.Variant.new_int32(5),
}
}
self.system.tracker_miner_fs_testing_start (config)
self.tracker = self.system.store
try:
self.create_test_data ()
self.tracker.reset_graph_updates_tracking ()
except Exception as e:
self.tearDown ()
raise
def tearDown (self):
self.remove_test_data ()
self.system.tracker_miner_fs_testing_stop ()
def path (self, filename):
return os.path.join (self.datadir, filename)
def uri (self, filename):
return "file://" + os.path.join (self.datadir, filename)
def create_test_data (self):
monitored_files = [
'test-monitored/file1.txt',
'test-monitored/dir1/file2.txt',
......@@ -78,47 +104,21 @@ class CommonTrackerMinerTest (ut.TestCase):
'test-no-monitored/file0.txt'
]
def ensure_dir_exists(dirname):
if not os.path.exists(dirname):
os.makedirs(dirname)
for tf in chain(monitored_files, unmonitored_files):
testfile = path(tf)
ensure_dir_exists(os.path.dirname(testfile))
testfile = self.path(tf)
ensure_dir_exists (os.path.dirname(testfile))
with open (testfile, 'w') as f:
f.write (DEFAULT_TEXT)
for tf in monitored_files:
self.tracker.await_resource_inserted(
'nfo:TextDocument', url=uri(tf))
def setUp (self):
for d in ['test-monitored', 'test-no-monitored']:
dirname = path(d)
if os.path.exists (dirname):
shutil.rmtree(dirname)
os.makedirs(dirname)