Commit b8543f31 authored by Sam Thursfield's avatar Sam Thursfield Committed by Sam Thursfield

functional-tests: Make quiet by default

Add -v / --verbose option, which enables output of the helper status
messages and also stdin/stderr of the tracker processes being tested.
parent 87827c18
......@@ -188,7 +188,6 @@ class PropertyRangeStringToDate (OntologyChangeTestTemplate):
% (self.instance))
def validate_status (self):
print "validating"
# Query the ontology itself
result = self.tracker.query ("SELECT ?o WHERE { test:a_string rdfs:range ?o }")
self.assertEquals (result[0][0], XSD_DATETIME)
......
......@@ -30,6 +30,7 @@ import shutil
import time
import unittest2 as ut
from common.utils.helpers import log
from common.utils.minertest import CommonTrackerMinerTest, MINER_TMP_DIR, uri, path
class MinerCrawlTest (CommonTrackerMinerTest):
......@@ -120,7 +121,7 @@ class MinerCrawlTest (CommonTrackerMinerTest):
self.assertIn ( uri ("test-monitored/file0.txt"), unpacked_result)
# Clean the new file so the test directory is as before
print "Remove and wait"
log ("Remove and wait")
os.remove (dest)
self.system.tracker_miner_fs_wait_for_idle ()
......
......@@ -31,6 +31,7 @@ import shutil
import locale
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 import configuration as cfg
......@@ -59,7 +60,7 @@ class CommonMinerFTS (CommonTrackerMinerTest):
"""
Return list of URIs with the word in them
"""
print word
log ("Search for: %s" % word)
results = self.tracker.query ("""
SELECT ?url WHERE {
?u a nfo:TextDocument ;
......@@ -295,7 +296,7 @@ class MinerFTSStopwordsTest (CommonMinerFTS):
self.set_text (TEXT)
results = self.search_word ("automobile")
self.assertEquals (len (results), 1)
print stopwords
log ("Stopwords: %s" % stopwords)
for i in range (0, len (stopwords)):
results = self.search_word (stopwords[i])
self.assertEquals (len (results), 0)
......
......@@ -18,6 +18,7 @@
# Boston, MA 02110-1301, USA.
#
from common.utils.writebacktest import CommonTrackerWritebackTest as CommonTrackerWritebackTest
from common.utils.helpers import log
import unittest2 as ut
from common.utils.expectedFailure import expectedFailureBug
import time
......@@ -59,7 +60,7 @@ class WritebackKeepDateTest (CommonTrackerWritebackTest):
results = self.tracker.query (query_images)
self.assertEquals (len (results), 3, results)
print "Waiting 2 seconds to ensure there is a noticiable difference in the timestamp"
log ("Waiting 2 seconds to ensure there is a noticiable difference in the timestamp")
time.sleep (2)
# This triggers the writeback
......@@ -71,7 +72,7 @@ class WritebackKeepDateTest (CommonTrackerWritebackTest):
}
""" % (self.get_test_filename_jpeg ())
self.tracker.update (mark_as_favorite)
print "Setting favorite in <%s>" % (self.get_test_filename_jpeg ())
log ("Setting favorite in <%s>" % (self.get_test_filename_jpeg ()))
time.sleep (REASONABLE_TIMEOUT)
# Check the value is written in the file
......
......@@ -34,6 +34,7 @@ import fcntl
from common.utils import configuration as cfg
import unittest2 as ut
from common.utils.applicationstest import CommonTrackerApplicationTest as CommonTrackerApplicationTest
from common.utils.helpers import log
MINER_FS_IDLE_TIMEOUT = 5
......@@ -88,7 +89,7 @@ class TrackerCameraPicturesApplicationTests (CommonTrackerApplicationTest):
self.assertEquals (self.get_urn_count_by_url (dest_fileuri), 1)
# Clean the new file so the test directory is as before
print "Remove and wait"
log ("Remove and wait")
os.remove (dest_filepath)
self.system.tracker_miner_fs_wait_for_idle (MINER_FS_IDLE_TIMEOUT)
self.assertEquals (self.get_urn_count_by_url (dest_fileuri), 0)
......@@ -174,7 +175,7 @@ class TrackerCameraPicturesApplicationTests (CommonTrackerApplicationTest):
self.assertEquals (self.get_urn_count_by_url (dest_fileuri), 1)
# Clean the new file so the test directory is as before
print "Remove and wait"
log ("Remove and wait")
os.remove (dest_filepath)
self.system.tracker_miner_fs_wait_for_idle (MINER_FS_IDLE_TIMEOUT)
self.assertEquals (self.get_urn_count_by_url (dest_fileuri), 0)
......@@ -231,7 +232,7 @@ class TrackerCameraVideosApplicationTests (CommonTrackerApplicationTest):
self.assertEquals (self.get_urn_count_by_url (dest_fileuri), 1)
# Clean the new file so the test directory is as before
print "Remove and wait"
log ("Remove and wait")
os.remove (dest_filepath)
self.system.tracker_miner_fs_wait_for_idle (MINER_FS_IDLE_TIMEOUT)
self.assertEquals (self.get_urn_count_by_url (dest_fileuri), 0)
......@@ -317,7 +318,7 @@ class TrackerCameraVideosApplicationTests (CommonTrackerApplicationTest):
self.assertEquals (self.get_urn_count_by_url (dest_fileuri), 1)
# Clean the new file so the test directory is as before
print "Remove and wait"
log ("Remove and wait")
os.remove (dest_filepath)
self.system.tracker_miner_fs_wait_for_idle (MINER_FS_IDLE_TIMEOUT)
self.assertEquals (self.get_urn_count_by_url (dest_fileuri), 0)
......
......@@ -34,6 +34,7 @@ import fcntl
from common.utils import configuration as cfg
import unittest2 as ut
from common.utils.applicationstest import CommonTrackerApplicationTest as CommonTrackerApplicationTest
from common.utils.helpers import log
MINER_FS_IDLE_TIMEOUT = 5
......@@ -53,7 +54,7 @@ class TrackerSyncApplicationTests (CommonTrackerApplicationTest):
dest_filepath = os.path.join (self.get_dest_dir (), self.get_test_music ())
dest_fileuri = "file://" + dest_filepath
print "Synchronizing audio file in '%s'..." % (dest_filepath)
log ("Synchronizing audio file in '%s'..." % (dest_filepath))
# Insert new resource in the store
insert = """
......@@ -94,7 +95,7 @@ class TrackerSyncApplicationTests (CommonTrackerApplicationTest):
self.assertEquals (self.get_urn_count_by_url (dest_fileuri), 1)
# Clean the new file so the test directory is as before
print "Remove and wait"
log ("Remove and wait")
os.remove (dest_filepath)
self.system.tracker_miner_fs_wait_for_idle (MINER_FS_IDLE_TIMEOUT)
self.assertEquals (self.get_urn_count_by_url (dest_fileuri), 0)
......
......@@ -19,6 +19,7 @@
#
from common.utils import configuration as cfg
from common.utils.system import TrackerSystemAbstraction
from common.utils.helpers import log
import unittest2 as ut
import shutil
......@@ -68,7 +69,7 @@ class CommonTrackerApplicationTest (ut.TestCase):
"""
@rate: bytes per 100ms
"""
print "Copying slowly\n '%s' to\n '%s'" % (src, fdest.name)
log ("Copying slowly\n '%s' to\n '%s'" % (src, fdest.name))
fsrc = open (src, 'rb')
buffer_ = fsrc.read (rate)
while (buffer_ != ""):
......@@ -110,7 +111,7 @@ class CommonTrackerApplicationTest (ut.TestCase):
# Returns when ready
self.tracker = self.system.store
print "Ready to go!"
log ("Ready to go!")
@classmethod
def tearDown (self):
......
import subprocess
import os
from helpers import log
class DConfClient:
"""
......@@ -24,7 +25,7 @@ class DConfClient:
# XDG_CONFIG_HOME is useless
dconf_db = os.path.join (os.environ ["HOME"], ".config", "dconf", profile)
if os.path.exists (dconf_db):
print "[Conf] Removing dconf-profile:", dconf_db
log ("[Conf] Removing dconf-profile: " + dconf_db)
os.remove (dconf_db)
......
......@@ -36,6 +36,10 @@ class NoMetadataException (Exception):
REASONABLE_TIMEOUT = 30
def log (message):
if options.is_verbose ():
print (message)
class Helper:
"""
Abstract helper for Tracker processes. Launches the process manually
......@@ -72,12 +76,16 @@ class Helper:
"PROCESS_PATH",
os.path.join (cfg.EXEC_PREFIX, self.PROCESS_NAME))
FNULL = open ('/dev/null', 'w')
if options.is_manual_start ():
print ("Start %s manually" % self.PROCESS_NAME)
else:
return subprocess.Popen ([path], stdout=FNULL, stderr=FNULL)
kws = {}
if not options.is_verbose ():
FNULL = open ('/dev/null', 'w')
kws = { 'stdout': FNULL, 'stderr': FNULL }
return subprocess.Popen ([path], **kws)
def _stop_process (self):
if options.is_manual_start ():
......@@ -92,13 +100,13 @@ class Helper:
def _name_owner_changed_cb (self, name, old_owner, new_owner):
if name == self.BUS_NAME:
if old_owner == '' and new_owner != '':
print ("[%s] appeared in the bus" % self.PROCESS_NAME)
log ("[%s] appeared in the bus" % self.PROCESS_NAME)
self.available = True
elif old_owner != '' and new_owner == '':
print ("[%s] disappeared from the bus" % self.PROCESS_NAME)
log ("[%s] disappeared from the bus" % self.PROCESS_NAME)
self.available = False
else:
print ("[%s] name change %s -> %s" % (self.PROCESS_NAME, old_owner, new_owner))
log ("[%s] name change %s -> %s" % (self.PROCESS_NAME, old_owner, new_owner))
self.loop.quit ()
......@@ -111,7 +119,7 @@ class Helper:
raise Exception("%s exited with status: %i" % (self.PROCESS_NAME, status))
def _timeout_on_idle_cb (self):
print ("[%s] Timeout waiting... asumming idle." % self.PROCESS_NAME)
log ("[%s] Timeout waiting... asumming idle." % self.PROCESS_NAME)
self.loop.quit ()
return False
......@@ -147,7 +155,7 @@ class Helper:
self.timeout_id = glib.timeout_add_seconds (REASONABLE_TIMEOUT, self._timeout_on_idle_cb)
self.loop.run ()
print ("[%s] stop." % self.PROCESS_NAME)
log ("[%s] stop." % self.PROCESS_NAME)
# Disconnect the signals of the next start we get duplicated messages
self.bus._clean_up_signal_match (self.name_owner_match)
......@@ -157,7 +165,7 @@ class Helper:
# Name owner changed callback should take us out from this loop
self.loop.run ()
print ("[%s] killed." % self.PROCESS_NAME)
log ("[%s] killed." % self.PROCESS_NAME)
self.bus._clean_up_signal_match (self.name_owner_match)
......@@ -192,9 +200,9 @@ class StoreHelper (Helper):
cfg.TRACKER_STATUS_OBJ_PATH)
self.status_iface = dbus.Interface (tracker_status, dbus_interface=cfg.STATUS_IFACE)
print ("[%s] booting..." % self.PROCESS_NAME)
log ("[%s] booting..." % self.PROCESS_NAME)
self.status_iface.Wait ()
print ("[%s] ready." % self.PROCESS_NAME)
log ("[%s] ready." % self.PROCESS_NAME)
def query (self, query, timeout=5000):
......@@ -297,17 +305,22 @@ class MinerFsHelper (Helper):
def _stop_process (self):
if options.is_manual_start ():
if self.available:
print ("Kill %s manually" % self.PROCESS_NAME)
log ("Kill %s manually" % self.PROCESS_NAME)
self.loop.run ()
else:
control_binary = os.path.join (cfg.BINDIR, "tracker-control")
FNULL = open('/dev/null', 'w')
subprocess.call ([control_binary, "--kill=miners"], stdout=FNULL)
kws = {}
if not options.is_verbose ():
FNULL = open ('/dev/null', 'w')
kws = { 'stdout': FNULL }
subprocess.call ([control_binary, "--kill=miners"], **kws)
return False
def _minerfs_status_cb (self, status, progress, remaining_time):
print ("[%s] status is now %s" % (self.PROCESS_NAME, status.encode ("utf-8")))
if (status == "Idle"):
self.loop.quit ()
......
......@@ -4,20 +4,33 @@ import sys
usage = "usage: %prog [options]"
parser = OptionParser(usage=usage)
parser.add_option("-m", "--start-manually", dest="startmanually",
action="store_true",
default=False,
help="Wait for an external instance of the processes to appear in the system")
parser.add_option("-v", "--verbose", dest="verbose",
action="store_true",
default=False,
help="Display a log of test process statuses")
(options, args) = parser.parse_args()
# Deleting options from the args. Otherwise unittest will complain
for option in ["--startmanually", "-m"]:
# Deleting options from the args. Otherwise unittest and the tests which
# have their own simple commandline parsers will complain
for option in ["--startmanually", "-m", "--verbose", "-v"]:
try:
sys.argv.remove (option)
except ValueError:
pass
def is_verbose ():
"""
True to log process status information to stdout
"""
return options.verbose
def is_manual_start ():
"""
False to start the processes automatically
......
......@@ -45,10 +45,10 @@ class TrackerSystemAbstraction:
assert not gsettings or type(gsettings) is list
print "[Conf] Setting test environment..."
helpers.log ("[Conf] Setting test environment...")
for var, directory in TEST_ENV_DIRS.iteritems ():
print "export %s=%s" %(var, directory)
helpers.log ("export %s=%s" %(var, directory))
self.__recreate_directory (directory)
os.environ [var] = directory
......@@ -56,11 +56,11 @@ class TrackerSystemAbstraction:
self.__recreate_directory (directory)
if ontodir:
print "export %s=%s" % ("TRACKER_DB_ONTOLOGIES_DIR", ontodir)
helpers.log ("export %s=%s" % ("TRACKER_DB_ONTOLOGIES_DIR", ontodir))
os.environ ["TRACKER_DB_ONTOLOGIES_DIR"] = ontodir
for var, value in TEST_ENV_VARS.iteritems ():
print "export %s=%s" %(var, value)
helpers.log ("export %s=%s" %(var, value))
os.environ [var] = value
# Previous loop should have set DCONF_PROFILE to the test location
......@@ -70,7 +70,7 @@ class TrackerSystemAbstraction:
for (schema, key, value) in gsettings:
self.dconf.write (schema, key, value)
print "[Conf] environment ready"
helpers.log ("[Conf] environment ready")
def unset_up_environment (self):
"""
......@@ -111,7 +111,7 @@ class TrackerSystemAbstraction:
def tracker_store_restart_with_new_ontologies (self, ontodir):
self.store.stop ()
if ontodir:
print "[Conf] Setting %s - %s" % ("TRACKER_DB_ONTOLOGIES_DIR", ontodir)
helpers.log ("[Conf] Setting %s - %s" % ("TRACKER_DB_ONTOLOGIES_DIR", ontodir))
os.environ ["TRACKER_DB_ONTOLOGIES_DIR"] = ontodir
try:
self.store.start ()
......
......@@ -22,6 +22,7 @@ import shutil
import unittest2 as ut
import os
from common.utils import configuration as cfg
from common.utils.helpers import log
import time
TEST_FILE_JPEG = "writeback-test-1.jpeg"
......@@ -68,7 +69,7 @@ class CommonTrackerWritebackTest (ut.TestCase):
for testfile in [TEST_FILE_JPEG, TEST_FILE_PNG,TEST_FILE_TIFF]:
origin = os.path.join (datadir, testfile)
print "Copying", origin, WRITEBACK_TMP_DIR
log ("Copying %s -> %s" % (origin, WRITEBACK_TMP_DIR))
shutil.copy (origin, WRITEBACK_TMP_DIR)
time.sleep (2)
......@@ -82,7 +83,7 @@ class CommonTrackerWritebackTest (ut.TestCase):
self.system.tracker_writeback_testing_start (CONF_OPTIONS)
# Returns when ready
print "Ready to go!"
log ("Ready to go!")
@classmethod
def tearDownClass (self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment