Commit 4f66031b authored by Sam Thursfield's avatar Sam Thursfield

Merge branch 'sam/functional-tests' into 'master'

Enable functional tests in tracker-miners

Closes #4

See merge request GNOME/tracker-miners!8
parents 6d845155 bc66cf7a
Pipeline #20512 passed with stage
in 2 minutes and 53 seconds
......@@ -25,6 +25,7 @@ test-autotools-fedora-latest:
- PKG_CONFIG_PATH=/opt/tracker/lib64/pkgconfig/ su tracker -c './autogen.sh --prefix=/opt/tracker'
- su tracker -c 'make -j'
- su tracker -c 'LD_LIBRARY_PATH=/opt/tracker/lib64 VERBOSE=1 make check'
- su tracker -c 'LD_LIBRARY_PATH=/opt/tracker/lib64 TRACKER_TESTS_VERBOSE=1 dbus-launch make functional-test'
test-meson-fedora-latest:
stage: test
......@@ -41,6 +42,12 @@ test-meson-fedora-latest:
# that Tracker is installed on the host here, thanks to `dnf builddep`.
- su tracker -c 'mkdir subprojects; cd subprojects; git clone https://gitlab.gnome.org/GNOME/tracker'
- su tracker -c 'mkdir build'
- su tracker -c 'cd build; meson .. --prefix=/usr -Dfunctional_tests=false'
- su tracker -c 'cd build; meson .. --prefix=/usr'
- su tracker -c 'cd build; ninja'
- su tracker -c 'cd build; meson test --suite tracker-miners --print-errorlogs'
- |
# Remove the many "CI_" variables from the environment. Meson dumps the
# whole environment for every failed test, and that gives a whole
# screenful of junk each time unless we strip these.
unset $(env|grep -o '^CI_[^=]*')
su tracker -c 'cd build; LANG=en_US.UTF8 dbus-launch meson test --suite tracker-miners --print-errorlogs'
......@@ -436,6 +436,8 @@ if test "$native_win32" = "yes" ; then
AC_DEFINE(OS_WIN32, 1, [Define if we are on win32])
fi
AC_SUBST(FUNCTIONAL_TESTS_TRACKER_EXTRACT_PATH, "@top_builddir@/src/tracker-extract/tracker-extract")
AC_SUBST(FUNCTIONAL_TESTS_TRACKER_MINER_FS_PATH, "@top_builddir@/src/miners/fs/tracker-miner-fs")
AC_SUBST(FUNCTIONAL_TESTS_TRACKER_STORE_PATH, "${libexecdir}/tracker-store")
####################################################################
......
......@@ -26,6 +26,10 @@ if not tracker_sparql.found() or not tracker_miner.found()
tracker_store = tracker_subproject.get_variable('tracker_store')
tracker_store_path = tracker_store.full_path()
tracker_uninstalled_domain_rule = tracker_subproject.get_variable('tracker_uninstalled_domain_rule')
tracker_uninstalled_nepomuk_ontologies_dir = tracker_subproject.get_variable('tracker_uninstalled_nepomuk_ontologies_dir')
tracker_uninstalled_stop_words_dir = tracker_subproject.get_variable('tracker_uninstalled_stop_words_dir')
else
# The tracker-miners will not work unless installed into the same prefix as
# the base 'tracker' package as it expects to be able to access data files
......@@ -35,6 +39,13 @@ else
# right prefix, among other things.
tracker_store = find_program(join_paths(get_option('prefix'), get_option('libexecdir'), 'tracker-store'))
tracker_store_path = tracker_store.path()
# If we are building against an installed version of tracker core rather than
# having it as a subproject, these 'uninstalled' locations point to the actual
# installed locations.
tracker_uninstalled_domain_rule = join_paths(get_option('prefix'), get_option('datadir'), 'tracker', 'domain-ontologies', 'default.rule')
tracker_uninstalled_nepomuk_ontologies_dir = join_paths(get_option('prefix'), get_option('datadir'), 'tracker', 'ontologies', 'nepomuk')
tracker_uninstalled_stop_words_dir = join_paths(get_option('prefix'), get_option('datadir'), 'tracker', 'stop-words', 'default.rule')
endif
avcodec = dependency('libavcodec', version: '>= 0.8.4', required: false)
......@@ -364,6 +375,8 @@ tracker_extract_rules_dir = join_paths(get_option('prefix'), get_option('datadir
tracker_miner_services_dir = join_paths(get_option('prefix'), get_option('datadir'), 'tracker/miners')
tracker_writeback_modules_dir = join_paths(get_option('prefix'), get_option('libdir'), 'tracker-miners-@0@/writeback-modules'.format(tracker_api_version))
tracker_uninstalled_extract_rules_dir = join_paths(meson.current_build_dir(), 'src', 'tracker-extract')
gsettings_schema_dir = join_paths(get_option('prefix'), get_option('datadir'), 'glib-2.0', 'schemas')
vapi_dir = join_paths(get_option('prefix'), get_option('datadir'), 'vala', 'vapi')
......
......@@ -5,35 +5,35 @@
# This might be nicer if Meson supported dictionary types.
modules = [
['extract-bmp', 'tracker-extract-bmp.c', '10-bmp.rule', [tracker_miners_common_dep]],
['extract-bmp', 'tracker-extract-bmp.c', ['10-bmp.rule'], [tracker_miners_common_dep]],
['extract-dummy', 'tracker-extract-dummy.c', ['10-comics.rule', '10-ebooks.rule'], [tracker_miners_common_dep]]
]
if get_option('abiword')
modules += [['extract-abw', 'tracker-extract-abw.c', '10-abw.rule', [tracker_miners_common_dep]]]
modules += [['extract-abw', 'tracker-extract-abw.c', ['10-abw.rule'], [tracker_miners_common_dep]]]
endif
if get_option('dvi')
modules += [['extract-dvi', 'tracker-extract-dvi.c', '10-dvi.rule', [tracker_miners_common_dep]]]
modules += [['extract-dvi', 'tracker-extract-dvi.c', ['10-dvi.rule'], [tracker_miners_common_dep]]]
endif
if libgsf.found()
modules += [['extract-epub', 'tracker-extract-epub.c', '10-epub.rule', [libgsf, tracker_miners_common_dep]]]
modules += [['extract-msoffice', 'tracker-extract-msoffice.c', '10-msoffice.rule', [libgsf, tracker_miners_common_dep]]]
modules += [['extract-msoffice-xml', 'tracker-extract-msoffice-xml.c', '11-msoffice-xml.rule', [libgsf, tracker_miners_common_dep]]]
modules += [['extract-oasis', 'tracker-extract-oasis.c', '10-oasis.rule', [libgsf, tracker_miners_common_dep]]]
modules += [['extract-epub', 'tracker-extract-epub.c', ['10-epub.rule'], [libgsf, tracker_miners_common_dep]]]
modules += [['extract-msoffice', 'tracker-extract-msoffice.c', ['10-msoffice.rule'], [libgsf, tracker_miners_common_dep]]]
modules += [['extract-msoffice-xml', 'tracker-extract-msoffice-xml.c', ['11-msoffice-xml.rule'], [libgsf, tracker_miners_common_dep]]]
modules += [['extract-oasis', 'tracker-extract-oasis.c', ['10-oasis.rule'], [libgsf, tracker_miners_common_dep]]]
endif
if flac.found()
modules += [['extract-flac', 'tracker-extract-flac.c', '10-flac.rule', [flac, tracker_miners_common_dep]]]
modules += [['extract-flac', 'tracker-extract-flac.c', ['10-flac.rule'], [flac, tracker_miners_common_dep]]]
endif
if gexiv2.found()
modules += [['extract-raw', 'tracker-extract-raw.c', '10-raw.rule', [gexiv2, tracker_miners_common_dep]]]
modules += [['extract-raw', 'tracker-extract-raw.c', ['10-raw.rule'], [gexiv2, tracker_miners_common_dep]]]
endif
if libgif.found()
modules += [['extract-gif', 'tracker-extract-gif.c', '10-gif.rule', [libgif, tracker_miners_common_dep]]]
modules += [['extract-gif', 'tracker-extract-gif.c', ['10-gif.rule'], [libgif, tracker_miners_common_dep]]]
endif
if generic_media_handler_name == 'gstreamer'
......@@ -52,45 +52,45 @@ if generic_media_handler_name == 'gstreamer'
endif
if libxml2.found()
modules += [['extract-html', 'tracker-extract-html.c', '10-html.rule', [libxml2]]]
modules += [['extract-html', 'tracker-extract-html.c', ['10-html.rule'], [libxml2]]]
endif
if libjpeg.found()
modules += [['extract-jpeg', 'tracker-extract-jpeg.c', '10-jpeg.rule', [libjpeg, tracker_miners_common_dep]]]
modules += [['extract-jpeg', 'tracker-extract-jpeg.c', ['10-jpeg.rule'], [libjpeg, tracker_miners_common_dep]]]
endif
if generic_media_handler_name == 'libav'
rules = ['90-libav-audio-generic.rule', '90-libav-video-generic.rule']
rules = ['90-libav-audio-generic.rule', ['90-libav-video-generic.rule']]
dependencies = [avcodec, avformat, avutil, tracker_miners_common_dep]
modules += [['extract-libav', 'tracker-extract-libav.c', rules, dependencies]]
endif
if get_option('icon')
modules += [['extract-icon', 'tracker-extract-icon.c', '10-ico.rule', []]]
modules += [['extract-icon', 'tracker-extract-icon.c', ['10-ico.rule'], []]]
endif
if libosinfo.found()
modules += [['extract-iso', 'tracker-extract-iso.c', '11-iso.rule', [libosinfo]]]
modules += [['extract-iso', 'tracker-extract-iso.c', ['11-iso.rule'], [libosinfo]]]
endif
if get_option('mp3')
modules += [['extract-mp3', 'tracker-extract-mp3.c', '10-mp3.rule', [tracker_miners_common_dep]]]
modules += [['extract-mp3', 'tracker-extract-mp3.c', ['10-mp3.rule'], [tracker_miners_common_dep]]]
endif
if poppler.found()
modules += [['extract-pdf', 'tracker-extract-pdf.c', '10-pdf.rule', [poppler, tracker_miners_common_dep]]]
modules += [['extract-pdf', 'tracker-extract-pdf.c', ['10-pdf.rule'], [poppler, tracker_miners_common_dep]]]
endif
if totem_plparser.found()
modules += [['extract-playlist', 'tracker-extract-playlist.c', '15-playlist.rule', [totem_plparser]]]
modules += [['extract-playlist', 'tracker-extract-playlist.c', ['15-playlist.rule'], [totem_plparser]]]
endif
if libpng.found()
modules += [['extract-png', 'tracker-extract-png.c', '10-png.rule', [libpng, tracker_miners_common_dep]]]
modules += [['extract-png', 'tracker-extract-png.c', ['10-png.rule'], [libpng, tracker_miners_common_dep]]]
endif
if get_option('ps')
modules += [['extract-ps', 'tracker-extract-ps.c', '10-ps.rule', [tracker_miners_common_dep]]]
modules += [['extract-ps', 'tracker-extract-ps.c', ['10-ps.rule'], [tracker_miners_common_dep]]]
endif
if get_option('text')
......@@ -98,26 +98,26 @@ if get_option('text')
endif
if libtiff.found()
modules += [['extract-tiff', 'tracker-extract-tiff.c', '10-tiff.rule', [libtiff, tracker_miners_common_dep]]]
modules += [['extract-tiff', 'tracker-extract-tiff.c', ['10-tiff.rule'], [libtiff, tracker_miners_common_dep]]]
endif
if libvorbis.found()
modules += [['extract-vorbis', 'tracker-extract-vorbis.c', '10-vorbis.rule', [libvorbis, tracker_miners_common_dep]]]
modules += [['extract-vorbis', 'tracker-extract-vorbis.c', ['10-vorbis.rule'], [libvorbis, tracker_miners_common_dep]]]
endif
if exempi.found()
modules += [['extract-xmp', 'tracker-extract-xmp.c', '10-xmp.rule', []]]
modules += [['extract-xmp', 'tracker-extract-xmp.c', ['10-xmp.rule'], []]]
endif
if libgxps.found()
modules += [['extract-xps', 'tracker-extract-xps.c', '10-xps.rule', [libgxps, tracker_miners_common_dep]]]
modules += [['extract-xps', 'tracker-extract-xps.c', ['10-xps.rule'], [libgxps, tracker_miners_common_dep]]]
endif
foreach module : modules
name = module[0]
sources = module[1]
rule = module[2]
rules = module[2]
dependencies = module[3]
shared_module(name, sources,
......@@ -127,7 +127,16 @@ foreach module : modules
install: true,
install_dir: tracker_extract_modules_dir)
install_data(rule, install_dir: tracker_extract_rules_dir)
install_data(rules, install_dir: tracker_extract_rules_dir)
# Populate tracker_uninstalled_extract_rules_dir with the enabled .rule files.
foreach rule: rules
empty_conf = configuration_data()
configure_file(
input: rule,
output: rule,
configuration: empty_conf)
endforeach
endforeach
tracker_extract_priority_dbus = gnome.gdbus_codegen(
......
......@@ -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,66 +247,61 @@ 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 ()
self.assertEquals (len (result), 3)
if __name__ == "__main__":
print """
Tests for Copy/move/delete operations of FILES between monitored/unmonitored locations.
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)
#!/usr/bin/python
#-*- coding: utf-8 -*-
# Copyright (C) 2010, Nokia (ivan.frade@nokia.com)
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301, USA.
#
# TODO:
# These tests are for files... we need to write them for folders!
#
"""
Monitor a directory, copy/move/remove/update text files and check that
the text contents are updated accordingly in the indexes.
"""
import os
import shutil
import locale
import time
import unittest2 as ut
from common.utils.helpers import log
from common.utils.minertest import CommonTrackerMinerFTSTest, DEFAULT_TEXT
from common.utils import configuration as cfg
class MinerFTSBasicTest (CommonTrackerMinerFTSTest):
"""
Tests different contents in a single file
"""
def test_01_single_word (self):
TEXT = "automobile"
self.basic_test (TEXT, TEXT)
def test_02_multiple_words (self):
TEXT = "automobile with unlimited power"
self.set_text (TEXT)
results = self.search_word ("automobile")
self.assertEquals (len (results), 1)
self.assertIn (self.uri (self.testfile), results)
results = self.search_word ("unlimited")
self.assertEquals (len (results), 1)
self.assertIn (self.uri (self.testfile), results)
def test_03_long_word (self):
# TEXT is longer than the 20 characters specified in the fts configuration
TEXT = "fsfsfsdfskfweeqrewqkmnbbvkdasdjefjewriqjfnc"
self.set_text (TEXT)
results = self.search_word (TEXT)
self.assertEquals (len (results), 0)
def test_04_non_existent_word (self):
TEXT = "This a trick"
self.set_text (TEXT)
results = self.search_word ("trikc")
self.assertEquals (len (results), 0)
def test_05_word_multiple_times_in_file (self):
TEXT = "automobile is red. automobile is big. automobile is great!"
self.basic_test (TEXT, "automobile")
def test_06_sentence (self):
TEXT = "plastic is fantastic"
self.basic_test (TEXT, TEXT)
def test_07_partial_sentence (self):
TEXT = "plastic is fantastic"
self.basic_test (TEXT, "is fantastic")
@ut.skip("Currently fails with: fts5: syntax error near '.'")
def test_08_strange_word (self):
# FIXME Not sure what are we testing here
TEXT = "'summer.time'"
self.basic_test (TEXT, "summer.time")
# Skip the test 'search for .'
def test_09_mixed_letters_and_numbers (self):
TEXT = "abc123"
self.basic_test (TEXT, "abc123")
def test_10_ignore_numbers (self):
TEXT = "palabra 123123"
self.set_text (TEXT)
results = self.search_word ("123123")
self.assertEquals (len (results), 0)
if __name__ == "__main__":
ut.main (failfast=True)
......@@ -33,156 +33,11 @@ import time
import unittest2 as ut
from common.utils.helpers import log
from common.utils.minertest import CommonTrackerMinerTest, MINER_TMP_DIR, uri, path, DEFAULT_TEXT
from common.utils.minertest import CommonTrackerMinerFTSTest, DEFAULT_TEXT
from common.utils import configuration as cfg
class CommonMinerFTS (CommonTrackerMinerTest):
"""
Superclass to share methods. Shouldn't be run by itself.
"""
def prepare_directories (self):
# Override content from the base class
pass
def setUp (self):
self.testfile = "test-monitored/miner-fts-test.txt"
if os.path.exists (path (self.testfile)):
os.remove (path (self.testfile))
super(CommonMinerFTS, self).setUp()
def set_text (self, text):
exists = os.path.exists(path(self.testfile))
f = open (path (self.testfile), "w")
f.write (text)
f.close ()
if exists:
subject_id = self.tracker.get_resource_id(uri(self.testfile))
self.tracker.await_property_changed(
subject_id=subject_id, property_uri='nie:plainTextContent')
else:
self.tracker.await_resource_inserted(
rdf_class='nfo:Document', url=uri(self.testfile),
required_property='nie:plainTextContent')
self.tracker.reset_graph_updates_tracking()
def search_word (self, word):
"""
Return list of URIs with the word in them
"""
log</