[tracker-miners/sam/functional-tests-shared: 8/12] functional-tests: Remove log() helper function



commit 0d0d4695fb5ba13e11923ef71f24cc83ca25ee2a
Author: Sam Thursfield <sam afuera me uk>
Date:   Wed Aug 7 15:13:44 2019 +0200

    functional-tests: Remove log() helper function
    
    Let's use Python's actual 'logging' module instead.

 tests/functional-tests/300-miner-basic-ops.py      |  6 +-
 tests/functional-tests/310-fts-basic.py            |  1 -
 tests/functional-tests/311-fts-file-operations.py  |  1 -
 tests/functional-tests/312-fts-stopwords.py        |  2 -
 .../401-extractor-flac-cuesheet.py                 |  1 -
 tests/functional-tests/410-extractor-decorator.py  |  2 -
 tests/functional-tests/500-writeback-images.py     |  8 ++-
 .../501-writeback-image-details.py                 | 17 ++++--
 tests/functional-tests/502-writeback-audio.py      |  1 -
 tests/functional-tests/600-applications-camera.py  | 12 ++--
 tests/functional-tests/601-applications-sync.py    | 15 ++---
 .../common/utils/applicationstest.py               |  8 ++-
 .../functional-tests/common/utils/configuration.py |  8 +++
 tests/functional-tests/common/utils/dconf.py       |  5 +-
 tests/functional-tests/common/utils/extractor.py   | 10 ++--
 tests/functional-tests/common/utils/helpers.py     | 64 +++++++++++-----------
 tests/functional-tests/common/utils/minertest.py   |  8 ++-
 tests/functional-tests/common/utils/system.py      |  5 +-
 .../functional-tests/common/utils/writebacktest.py | 15 +++--
 19 files changed, 103 insertions(+), 86 deletions(-)
---
diff --git a/tests/functional-tests/300-miner-basic-ops.py b/tests/functional-tests/300-miner-basic-ops.py
index 301914cc9..f783d9fbb 100755
--- a/tests/functional-tests/300-miner-basic-ops.py
+++ b/tests/functional-tests/300-miner-basic-ops.py
@@ -25,14 +25,16 @@
 Monitor a test directory and copy/move/remove/update files and folders there.
 Check the basic data of the files is updated accordingly in tracker.
 """
+import logging
 import os
 import shutil
 import time
 
 import unittest as ut
-from common.utils.helpers import log
 from common.utils.minertest import CommonTrackerMinerTest
 
+log = logging.getLogger(__name__)
+
 NFO_DOCUMENT = 'http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#Document'
 
 
@@ -114,7 +116,7 @@ class MinerCrawlTest (CommonTrackerMinerTest):
         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")
+        log.debug("Remove and wait")
         os.remove(dest)
         self.system.store.await_resource_deleted(NFO_DOCUMENT, dest_id)
 
diff --git a/tests/functional-tests/310-fts-basic.py b/tests/functional-tests/310-fts-basic.py
index 90785b5aa..4fc59fb06 100755
--- a/tests/functional-tests/310-fts-basic.py
+++ b/tests/functional-tests/310-fts-basic.py
@@ -32,7 +32,6 @@ import locale
 import time
 
 import unittest as ut
-from common.utils.helpers import log
 from common.utils.minertest import CommonTrackerMinerFTSTest, DEFAULT_TEXT
 from common.utils import configuration as cfg
 
diff --git a/tests/functional-tests/311-fts-file-operations.py 
b/tests/functional-tests/311-fts-file-operations.py
index 7b27e1c05..32373f1bf 100755
--- a/tests/functional-tests/311-fts-file-operations.py
+++ b/tests/functional-tests/311-fts-file-operations.py
@@ -32,7 +32,6 @@ import locale
 import time
 
 import unittest as ut
-from common.utils.helpers import log
 from common.utils.minertest import CommonTrackerMinerFTSTest, DEFAULT_TEXT
 from common.utils import configuration as cfg
 
diff --git a/tests/functional-tests/312-fts-stopwords.py b/tests/functional-tests/312-fts-stopwords.py
index 5f77a61f5..6ba8ac591 100755
--- a/tests/functional-tests/312-fts-stopwords.py
+++ b/tests/functional-tests/312-fts-stopwords.py
@@ -32,7 +32,6 @@ import locale
 import time
 
 import unittest as ut
-from common.utils.helpers import log
 from common.utils.minertest import CommonTrackerMinerFTSTest, DEFAULT_TEXT
 from common.utils import configuration as cfg
 
@@ -73,7 +72,6 @@ class MinerFTSStopwordsTest (CommonTrackerMinerFTSTest):
         self.set_text(TEXT)
         results = self.search_word("automobile")
         self.assertEqual(len(results), 1)
-        log("Stopwords: %s" % stopwords)
         for i in range(0, len(stopwords)):
             results = self.search_word(stopwords[i])
             self.assertEqual(len(results), 0)
diff --git a/tests/functional-tests/401-extractor-flac-cuesheet.py 
b/tests/functional-tests/401-extractor-flac-cuesheet.py
index fc2df05a4..301a6868d 100755
--- a/tests/functional-tests/401-extractor-flac-cuesheet.py
+++ b/tests/functional-tests/401-extractor-flac-cuesheet.py
@@ -28,7 +28,6 @@ import tempfile
 import unittest as ut
 
 import common.utils.configuration as cfg
-from common.utils.helpers import log
 from common.utils.extractor import get_tracker_extract_jsonld_output, create_test_flac, 
TrackerExtractTestCase
 
 
diff --git a/tests/functional-tests/410-extractor-decorator.py 
b/tests/functional-tests/410-extractor-decorator.py
index 459872ab8..338e64fdb 100755
--- a/tests/functional-tests/410-extractor-decorator.py
+++ b/tests/functional-tests/410-extractor-decorator.py
@@ -31,7 +31,6 @@ import tempfile
 import time
 
 import common.utils.configuration as cfg
-from common.utils.helpers import log
 from common.utils.system import TrackerSystemAbstraction
 
 
@@ -94,7 +93,6 @@ class ExtractorDecoratorTest(ut.TestCase):
             store.await_property_changed(VALID_FILE_CLASS, file_id, 'nie:title')
             assert not store.ask('ASK { <%s> nie:title ?title }' % file_urn)
 
-            log("Sending re-index request")
             # Request re-indexing (same as `tracker index --file ...`)
             miner_fs.index_file('file://' + os.path.join(self.datadir, file_path))
 
diff --git a/tests/functional-tests/500-writeback-images.py b/tests/functional-tests/500-writeback-images.py
index 25d07718c..b9a5b080d 100755
--- a/tests/functional-tests/500-writeback-images.py
+++ b/tests/functional-tests/500-writeback-images.py
@@ -21,15 +21,17 @@
 """Tests for Tracker writeback daemon."""
 
 
+import logging
 import os
 import sys
 import time
 
 from common.utils.extractor import get_tracker_extract_jsonld_output
-from common.utils.helpers import log
 from common.utils.writebacktest import CommonTrackerWritebackTest
 import unittest as ut
 
+log = logging.getLogger(__name__)
+
 REASONABLE_TIMEOUT = 5  # Seconds we wait for tracker-writeback to do the work
 
 
@@ -61,9 +63,9 @@ class WritebackImagesTest (CommonTrackerWritebackTest):
         """
         self.tracker.update(SPARQL_TMPL % (prop, path.as_uri(), prop, prop, TEST_VALUE, path.as_uri()))
 
-        log("Waiting for change on %s" % path)
+        log.debug("Waiting for change on %s", path)
         self.wait_for_file_change(path, initial_mtime)
-        log("Got the change")
+        log.debug("Got the change")
 
         results = get_tracker_extract_jsonld_output(path, mimetype)
         keyDict = expectedKey or prop
diff --git a/tests/functional-tests/501-writeback-image-details.py 
b/tests/functional-tests/501-writeback-image-details.py
index 9475cb394..cfe416b72 100755
--- a/tests/functional-tests/501-writeback-image-details.py
+++ b/tests/functional-tests/501-writeback-image-details.py
@@ -17,13 +17,18 @@
 # Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 # Boston, MA  02110-1301, USA.
 #
-from common.utils.writebacktest import CommonTrackerWritebackTest as CommonTrackerWritebackTest
-from common.utils.extractor import get_tracker_extract_jsonld_output
-from common.utils.helpers import log
-import unittest as ut
+
+import logging
 import os
 import sys
 import time
+import unittest as ut
+
+from common.utils.writebacktest import CommonTrackerWritebackTest as CommonTrackerWritebackTest
+from common.utils.extractor import get_tracker_extract_jsonld_output
+
+
+log = logging.getLogger(__name__)
 
 REASONABLE_TIMEOUT = 5  # Seconds we wait for tracker-writeback to do the work
 
@@ -65,7 +70,7 @@ class WritebackKeepDateTest (CommonTrackerWritebackTest):
         results = self.tracker.query(query_images)
         self.assertEqual(len(results), 3, results)
 
-        log("Waiting 2 seconds to ensure there is a noticiable difference in the timestamp")
+        log.debug("Waiting 2 seconds to ensure there is a noticiable difference in the timestamp")
         time.sleep(2)
 
         initial_mtime = jpeg_path.stat().st_mtime
@@ -79,7 +84,7 @@ class WritebackKeepDateTest (CommonTrackerWritebackTest):
          }
         """ % jpeg_path.as_uri()
         self.tracker.update(mark_as_favorite)
-        log("Setting favorite in <%s>" % jpeg_path.as_uri())
+        log.debug("Setting favorite in <%s>", jpeg_path.as_uri())
 
         self.wait_for_file_change(jpeg_path, initial_mtime)
 
diff --git a/tests/functional-tests/502-writeback-audio.py b/tests/functional-tests/502-writeback-audio.py
index f74ca4913..92b31bed3 100755
--- a/tests/functional-tests/502-writeback-audio.py
+++ b/tests/functional-tests/502-writeback-audio.py
@@ -21,7 +21,6 @@
 import unittest
 
 from common.utils.extractor import get_tracker_extract_jsonld_output
-from common.utils.helpers import log
 from common.utils.writebacktest import CommonTrackerWritebackTest
 
 
diff --git a/tests/functional-tests/600-applications-camera.py 
b/tests/functional-tests/600-applications-camera.py
index edf3726a5..c5322d06c 100755
--- a/tests/functional-tests/600-applications-camera.py
+++ b/tests/functional-tests/600-applications-camera.py
@@ -22,14 +22,16 @@
 Tests trying to simulate the behaviour of applications working with tracker
 """
 
+import logging
 import os
 import random
 
 import unittest as ut
 from common.utils.applicationstest import CommonTrackerApplicationTest as CommonTrackerApplicationTest
-from common.utils.helpers import log
 
 
+log = logging.getLogger(__name__)
+
 NMM_PHOTO = 'http://www.tracker-project.org/temp/nmm#Photo'
 NMM_VIDEO = 'http://www.tracker-project.org/temp/nmm#Video'
 
@@ -154,7 +156,7 @@ class TrackerCameraPicturesApplicationTests (TrackerCameraTestSuite):
         self.assertEqual(self.get_urn_count_by_url(dest_fileuri), 1)
 
         # Clean the new file so the test directory is as before
-        log("Remove and wait")
+        log.debug("Remove and wait")
         os.remove(dest_filepath)
         self.system.store.await_resource_deleted(NMM_PHOTO, dest_id)
         self.assertEqual(self.get_urn_count_by_url(dest_fileuri), 0)
@@ -200,7 +202,7 @@ class TrackerCameraPicturesApplicationTests (TrackerCameraTestSuite):
         self.assertEqual(self.get_urn_count_by_url(dest_fileuri), 1)
 
         # Clean the new file so the test directory is as before
-        log("Remove and wait")
+        log.debug("Remove and wait")
         os.remove(dest_filepath)
         self.system.store.await_resource_deleted(NMM_PHOTO, dest_id)
         self.assertEqual(self.get_urn_count_by_url(dest_fileuri), 0)
@@ -232,7 +234,7 @@ class TrackerCameraVideosApplicationTests (TrackerCameraTestSuite):
         self.assertEqual(self.get_urn_count_by_url(dest_fileuri), 1)
 
         # Clean the new file so the test directory is as before
-        log("Remove and wait")
+        log.debug("Remove and wait")
         os.remove(dest_filepath)
         self.system.store.await_resource_deleted(NMM_PHOTO, dest_id)
         self.assertEqual(self.get_urn_count_by_url(dest_fileuri), 0)
@@ -278,7 +280,7 @@ class TrackerCameraVideosApplicationTests (TrackerCameraTestSuite):
         self.assertEqual(self.get_urn_count_by_url(dest_fileuri), 1)
 
         # Clean the new file so the test directory is as before
-        log("Remove and wait")
+        log.debug("Remove and wait")
         os.remove(dest_filepath)
         self.system.store.await_resource_deleted(NMM_VIDEO, dest_id)
         self.assertEqual(self.get_urn_count_by_url(dest_fileuri), 0)
diff --git a/tests/functional-tests/601-applications-sync.py b/tests/functional-tests/601-applications-sync.py
index bc6527197..c0000deca 100755
--- a/tests/functional-tests/601-applications-sync.py
+++ b/tests/functional-tests/601-applications-sync.py
@@ -22,22 +22,17 @@
 Tests trying to simulate the behaviour of applications working with tracker
 """
 
-import sys
+import logging
 import os
-import unittest
-import time
 import random
-import string
-import datetime
 import shutil
-import fcntl
 
-from common.utils import configuration as cfg
 import unittest as ut
 from common.utils.applicationstest import CommonTrackerApplicationTest as CommonTrackerApplicationTest
-from common.utils.helpers import log
 
 
+log = logging.getLogger(__name__)
+
 NMM_MUSICPIECE = 'http://www.tracker-project.org/temp/nmm#MusicPiece'
 
 
@@ -72,7 +67,7 @@ class TrackerSyncApplicationTests (CommonTrackerApplicationTest):
         dest_filepath = os.path.join(self.get_dest_dir(), self.get_test_music())
         dest_fileuri = "file://" + dest_filepath
 
-        log("Synchronizing audio file in '%s'..." % (dest_filepath))
+        log.debug("Synchronizing audio file in '%s'...", dest_filepath)
 
         # Insert new resource in the store
         insert = """
@@ -120,7 +115,7 @@ class TrackerSyncApplicationTests (CommonTrackerApplicationTest):
         self.assertEqual(self.get_urn_count_by_url(dest_fileuri), 1)
 
         # Clean the new file so the test directory is as before
-        log("Remove and wait")
+        log.debug("Remove and wait")
         os.remove(dest_filepath)
         self.tracker.await_resource_deleted(NMM_MUSICPIECE, resource_id)
         self.assertEqual(self.get_urn_count_by_url(dest_fileuri), 0)
diff --git a/tests/functional-tests/common/utils/applicationstest.py 
b/tests/functional-tests/common/utils/applicationstest.py
index f6f72a12f..acdb6f015 100644
--- a/tests/functional-tests/common/utils/applicationstest.py
+++ b/tests/functional-tests/common/utils/applicationstest.py
@@ -19,18 +19,20 @@
 #
 from common.utils import configuration as cfg
 from common.utils.system import TrackerSystemAbstraction
-from common.utils.helpers import log
 import unittest as ut
 
 from gi.repository import GLib
 
-import shutil
+import logging
 import os
+import shutil
 import time
 
 # Copy rate, 10KBps (1024b/100ms)
 SLOWCOPY_RATE = 1024
 
+log = logging.getLogger(__name__)
+
 
 class CommonTrackerApplicationTest (ut.TestCase):
 
@@ -62,7 +64,7 @@ class CommonTrackerApplicationTest (ut.TestCase):
         """
         @rate: bytes per 100ms
         """
-        log("Copying slowly\n '%s' to\n '%s'" % (src, fdest.name))
+        log.debug("Copying slowly\n '%s' to\n '%s'", src, fdest.name)
         fsrc = open(src, 'rb')
         buffer_ = fsrc.read(rate)
         while (buffer_ != b""):
diff --git a/tests/functional-tests/common/utils/configuration.py 
b/tests/functional-tests/common/utils/configuration.py
index f94305f28..28a006e10 100644
--- a/tests/functional-tests/common/utils/configuration.py
+++ b/tests/functional-tests/common/utils/configuration.py
@@ -22,8 +22,12 @@
 
 import errno
 import json
+import logging
 import os
 import tempfile
+import sys
+
+from . import options
 
 
 if 'TRACKER_FUNCTIONAL_TEST_CONFIG' not in os.environ:
@@ -134,3 +138,7 @@ def remove_monitored_test_dir(path):
     except OSError as e:
         if e.errno == errno.ENOTEMPTY:
             pass
+
+
+if options.get_environment_boolean('TRACKER_TESTS_VERBOSE'):
+    logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
diff --git a/tests/functional-tests/common/utils/dconf.py b/tests/functional-tests/common/utils/dconf.py
index d4b42dfe9..328f9b845 100644
--- a/tests/functional-tests/common/utils/dconf.py
+++ b/tests/functional-tests/common/utils/dconf.py
@@ -1,9 +1,10 @@
 from gi.repository import GLib
 from gi.repository import Gio
 
+import logging
 import os
 
-from common.utils.helpers import log
+log = logging.getLogger(__name__)
 
 
 class DConfClient(object):
@@ -75,5 +76,5 @@ class DConfClient(object):
                                 "dconf",
                                 "trackertest")
         if os.path.exists(dconf_db):
-            log("[Conf] Removing dconf database: " + dconf_db)
+            log.debug("[Conf] Removing dconf database: %s", dconf_db)
             os.remove(dconf_db)
diff --git a/tests/functional-tests/common/utils/extractor.py 
b/tests/functional-tests/common/utils/extractor.py
index 500df0927..5a66c6117 100644
--- a/tests/functional-tests/common/utils/extractor.py
+++ b/tests/functional-tests/common/utils/extractor.py
@@ -20,9 +20,9 @@
 #
 
 from common.utils import configuration as cfg
-from common.utils.helpers import log
 import errno
 import json
+import logging
 import math
 import os
 import re
@@ -33,6 +33,8 @@ import gi
 gi.require_version('Gst', '1.0')
 from gi.repository import GLib, Gst
 
+log = logging.getLogger(__name__)
+
 
 def get_tracker_extract_jsonld_output(filename, mime_type=None):
     """
@@ -50,7 +52,7 @@ def get_tracker_extract_jsonld_output(filename, mime_type=None):
     # Tell GStreamer not to fork to create the registry
     env['GST_REGISTRY_FORK'] = 'no'
 
-    log('Running: %s' % ' '.join(command))
+    log.debug('Running: %s', ' '.join(command))
     try:
         p = subprocess.Popen(command, env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
     except OSError as e:
@@ -67,7 +69,7 @@ def get_tracker_extract_jsonld_output(filename, mime_type=None):
 
     if len(stderr) > 0:
         error_output = stderr.decode('unicode-escape').strip()
-        log("Error output from tracker-extract:\n%s" % error_output)
+        log.debug("Error output from tracker-extract:\n%s", error_output)
 
     try:
         output = stdout.decode('utf-8')
@@ -203,7 +205,7 @@ def create_test_flac(path, duration, timeout=10):
         'filesink location=%s' % path,
     ])
 
-    log("Running pipeline: %s" % pipeline_src)
+    log.debug("Running pipeline: %s", pipeline_src)
     pipeline = Gst.parse_launch(pipeline_src)
     ret = pipeline.set_state(Gst.State.PLAYING)
 
diff --git a/tests/functional-tests/common/utils/helpers.py b/tests/functional-tests/common/utils/helpers.py
index a85b6b3b9..21c0a0394 100644
--- a/tests/functional-tests/common/utils/helpers.py
+++ b/tests/functional-tests/common/utils/helpers.py
@@ -21,6 +21,7 @@ from gi.repository import Gio
 from gi.repository import GLib
 from gi.repository import GObject
 import atexit
+import logging
 import os
 import sys
 import subprocess
@@ -31,6 +32,8 @@ from common.utils import configuration as cfg
 from common.utils import mainloop
 from common.utils import options
 
+log = logging.getLogger(__name__)
+
 
 class NoMetadataException (Exception):
     pass
@@ -39,17 +42,12 @@ class NoMetadataException (Exception):
 REASONABLE_TIMEOUT = 30
 
 
-def log(message):
-    if options.is_verbose():
-        print (message)
-
-
 _process_list = []
 
 
 def _cleanup_processes():
     for process in _process_list:
-        log("helpers._cleanup_processes: stopping %s" % process)
+        log.debug("helpers._cleanup_processes: stopping %s", process)
         process.stop()
 
 
@@ -99,19 +97,19 @@ class Helper:
             kws = {'stdout': FNULL, 'stderr': subprocess.PIPE}
 
         command = [path] + flags
-        log("Starting %s" % ' '.join(command))
+        log.debug("Starting %s", ' '.join(command))
         try:
             return subprocess.Popen([path] + flags, **kws)
         except OSError as e:
             raise RuntimeError("Error starting %s: %s" % (path, e))
 
     def _bus_name_appeared(self, name, owner, data):
-        log("[%s] appeared in the bus as %s" % (self.PROCESS_NAME, owner))
+        log.debug("[%s] appeared in the bus as %s", self.PROCESS_NAME, owner)
         self.available = True
         self.loop.quit()
 
     def _bus_name_vanished(self, name, data):
-        log("[%s] disappeared from the bus" % self.PROCESS_NAME)
+        log.debug("[%s] disappeared from the bus", self.PROCESS_NAME)
         self.available = False
         self.loop.quit()
 
@@ -136,7 +134,7 @@ class Helper:
             raise RuntimeError("%s exited with status: %i\n%s" % (self.PROCESS_NAME, status, error))
 
     def _timeout_on_idle_cb(self):
-        log("[%s] Timeout waiting... asumming idle." % self.PROCESS_NAME)
+        log.debug("[%s] Timeout waiting... asumming idle.", self.PROCESS_NAME)
         self.loop.quit()
         self.timeout_id = None
         return False
@@ -163,7 +161,7 @@ class Helper:
                                 "already running " % self.PROCESS_NAME)
 
             self.process = self._start_process()
-            log('[%s] Started process %i' % (self.PROCESS_NAME, self.process.pid))
+            log.debug('[%s] Started process %i', self.PROCESS_NAME, self.process.pid)
             self.process_watch_timeout = GLib.timeout_add(200, self._process_watch_cb)
 
         self.abort_if_process_exits_with_status_0 = True
@@ -191,11 +189,11 @@ class Helper:
                 time.sleep(0.1)
 
                 if time.time() > (start + REASONABLE_TIMEOUT):
-                    log("[%s] Failed to terminate, sending kill!" % self.PROCESS_NAME)
+                    log.debug("[%s] Failed to terminate, sending kill!", self.PROCESS_NAME)
                     self.process.kill()
                     self.process.wait()
 
-            log("[%s] stopped." % self.PROCESS_NAME)
+            log.debug("[%s] stopped.", self.PROCESS_NAME)
 
             # Run the loop until the bus name disappears, or the process dies.
             self.loop.run_checked()
@@ -208,7 +206,7 @@ class Helper:
         global _process_list
 
         if options.is_manual_start():
-            log("kill(): ignoring, because process was started manually.")
+            log.debug("kill(): ignoring, because process was started manually.")
             return
 
         self.process.kill()
@@ -220,7 +218,7 @@ class Helper:
         self.process = None
         _process_list.remove(self)
 
-        log("[%s] killed." % self.PROCESS_NAME)
+        log.debug("[%s] killed.", self.PROCESS_NAME)
 
 
 class GraphUpdateTimeoutException(RuntimeError):
@@ -258,9 +256,9 @@ class StoreHelper (Helper):
             self.bus, Gio.DBusProxyFlags.DO_NOT_AUTO_START, None,
             cfg.TRACKER_BUSNAME, cfg.TRACKER_STATUS_OBJ_PATH, cfg.STATUS_IFACE)
 
-        log("[%s] booting..." % self.PROCESS_NAME)
+        log.debug("[%s] booting...", self.PROCESS_NAME)
         self.status_iface.Wait()
-        log("[%s] ready." % self.PROCESS_NAME)
+        log.debug("[%s] ready.", self.PROCESS_NAME)
 
         self.reset_graph_updates_tracking()
 
@@ -300,7 +298,7 @@ class StoreHelper (Helper):
         exit_loop = False
 
         if class_name == self.class_to_track:
-            log("GraphUpdated for %s: %i deletes, %i inserts" % (class_name, len(deletes_list), 
len(inserts_list)))
+            log.debug("GraphUpdated for %s: %i deletes, %i inserts", class_name, len(deletes_list), 
len(inserts_list))
 
             if inserts_list is not None:
                 if self.inserts_match_function is not None:
@@ -318,7 +316,7 @@ class StoreHelper (Helper):
                 self.graph_updated_timeout_id = 0
                 self.loop.quit()
         else:
-            log("Ignoring GraphUpdated for class %s, currently tracking %s" % (class_name, 
self.class_to_track))
+            log.debug("Ignoring GraphUpdated for class %s, currently tracking %s", class_name, 
self.class_to_track)
 
     def _enable_await_timeout(self):
         self.graph_updated_timeout_id = GLib.timeout_add_seconds(REASONABLE_TIMEOUT,
@@ -336,11 +334,11 @@ class StoreHelper (Helper):
         self.matched_resource_urn = None
         self.matched_resource_id = None
 
-        log("Await new %s (%i existing inserts)" % (rdf_class, len(self.inserts_list)))
+        log.debug("Await new %s (%i existing inserts)", rdf_class, len(self.inserts_list))
 
         if required_property is not None:
             required_property_id = self.get_resource_id_by_uri(required_property)
-            log("Required property %s id %i" % (required_property, required_property_id))
+            log.debug("Required property %s id %i", required_property, required_property_id)
 
         def find_resource_insertion(inserts_list):
             matched_creation = (self.matched_resource_id is not None)
@@ -369,17 +367,17 @@ class StoreHelper (Helper):
                         matched_creation = True
                         self.matched_resource_urn = result_set[0][0]
                         self.matched_resource_id = insert[1]
-                        log("Matched creation of resource %s (%i)" %
-                            (self.matched_resource_urn,
-                             self.matched_resource_id))
+                        log.debug("Matched creation of resource %s (%i)",
+                            self.matched_resource_urn,
+                             self.matched_resource_id)
                         if required_property is not None:
-                            log("Waiting for property %s (%i) to be set" %
-                                (required_property, required_property_id))
+                            log.debug("Waiting for property %s (%i) to be set",
+                                required_property, required_property_id)
 
                 if required_property is not None and matched_creation and not matched_required_property:
                     if id == self.matched_resource_id and insert[2] == required_property_id:
                         matched_required_property = True
-                        log("Matched %s %s" % (self.matched_resource_urn, required_property))
+                        log.debug("Matched %s %s", self.matched_resource_urn, required_property)
 
                 if not matched_creation or id != self.matched_resource_id:
                     remaining_events += [insert]
@@ -416,7 +414,7 @@ class StoreHelper (Helper):
         assert (self.class_to_track == None)
 
         def find_resource_deletion(deletes_list):
-            log("find_resource_deletion: looking for %i in %s" % (id, deletes_list))
+            log.debug("find_resource_deletion: looking for %i in %s", id, deletes_list)
 
             matched = False
             remaining_events = []
@@ -434,7 +432,7 @@ class StoreHelper (Helper):
             exit_loop = matched
             return exit_loop, remaining_events
 
-        log("Await deletion of %i (%i existing)" % (id, len(self.deletes_list)))
+        log.debug("Await deletion of %i (%i existing)", id, len(self.deletes_list))
 
         (existing_match, self.deletes_list) = find_resource_deletion(self.deletes_list)
 
@@ -460,7 +458,7 @@ class StoreHelper (Helper):
         assert (self.deletes_match_function == None)
         assert (self.class_to_track == None)
 
-        log("Await change to %i %s (%i, %i existing)" % (subject_id, property_uri, len(self.inserts_list), 
len(self.deletes_list)))
+        log.debug("Await change to %i %s (%i, %i existing)", subject_id, property_uri, 
len(self.inserts_list), len(self.deletes_list))
 
         self.class_to_track = rdf_class
 
@@ -472,7 +470,7 @@ class StoreHelper (Helper):
 
             for event in event_list:
                 if event[1] == subject_id and event[2] == property_id:
-                    log("Matched property change: %s" % str(event))
+                    log.debug("Matched property change: %s", str(event))
                     matched = True
                 else:
                     remaining_events += [event]
@@ -659,13 +657,13 @@ class MinerFsHelper (Helper):
         assert self._target_wakeup_count is None
 
         if self._wakeup_count >= target_wakeup_count:
-            log("miner-fs wakeup count is at %s (target is %s). No need to wait" % (self._wakeup_count, 
target_wakeup_count))
+            log.debug("miner-fs wakeup count is at %s (target is %s). No need to wait", self._wakeup_count, 
target_wakeup_count)
         else:
             def _timeout_cb():
                 raise WakeupCycleTimeoutException()
             timeout_id = GLib.timeout_add_seconds(timeout, _timeout_cb)
 
-            log("Waiting for miner-fs wakeup count of %s (currently %s)" % (target_wakeup_count, 
self._wakeup_count))
+            log.debug("Waiting for miner-fs wakeup count of %s (currently %s)", target_wakeup_count, 
self._wakeup_count)
             self._target_wakeup_count = target_wakeup_count
             self.loop.run_checked()
 
diff --git a/tests/functional-tests/common/utils/minertest.py 
b/tests/functional-tests/common/utils/minertest.py
index 92d81fb5f..650c03eb1 100644
--- a/tests/functional-tests/common/utils/minertest.py
+++ b/tests/functional-tests/common/utils/minertest.py
@@ -19,12 +19,12 @@
 # 02110-1301, USA.
 #
 from common.utils import configuration as cfg
-from common.utils.helpers import log
 from common.utils.system import TrackerSystemAbstraction
 import unittest as ut
 
 from gi.repository import GLib
 
+import logging
 import os
 import shutil
 import tempfile
@@ -35,6 +35,8 @@ DEFAULT_TEXT = "Some stupid content, to have a test file"
 
 NFO_DOCUMENT = 'http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#Document'
 
+log = logging.getLogger(__name__)
+
 
 def ensure_dir_exists(dirname):
     if not os.path.exists(dirname):
@@ -121,7 +123,7 @@ class CommonTrackerMinerTest (ut.TestCase):
             shutil.rmtree(os.path.join(self.workdir, 'test-monitored'))
             shutil.rmtree(os.path.join(self.workdir, 'test-no-monitored'))
         except Exception as e:
-            log("Failed to remove temporary data dir: %s" % e)
+            log.warning("Failed to remove temporary data dir: %s", e)
 
     def assertResourceExists(self, urn):
         if self.tracker.ask("ASK { <%s> a rdfs:Resource }" % urn) == False:
@@ -168,7 +170,7 @@ class CommonTrackerMinerFTSTest (CommonTrackerMinerTest):
         """
         Return list of URIs with the word in them
         """
-        log("Search for: %s" % word)
+        log.info("Search for: %s", word)
         results = self.tracker.query("""
                 SELECT ?url WHERE {
                   ?u a nfo:TextDocument ;
diff --git a/tests/functional-tests/common/utils/system.py b/tests/functional-tests/common/utils/system.py
index c86e36efb..b9f36b119 100644
--- a/tests/functional-tests/common/utils/system.py
+++ b/tests/functional-tests/common/utils/system.py
@@ -1,4 +1,5 @@
 #!/usr/bin/env python3
+import logging
 import os
 import subprocess
 import shutil
@@ -17,6 +18,8 @@ TEST_ENV_VARS = {"LC_COLLATE": "en_GB.utf8"}
 
 REASONABLE_TIMEOUT = 5
 
+log = logging.getLogger(__name__)
+
 
 class UnableToBootException (Exception):
     pass
@@ -95,7 +98,7 @@ class TrackerSystemAbstraction (object):
     def tracker_store_restart_with_new_ontologies(self, ontodir):
         self.store.stop()
         if ontodir:
-            helpers.log("[Conf] Setting %s - %s" % ("TRACKER_DB_ONTOLOGIES_DIR", ontodir))
+            log.debug("[Conf] Setting %s - %s", "TRACKER_DB_ONTOLOGIES_DIR", ontodir)
             os.environ["TRACKER_DB_ONTOLOGIES_DIR"] = ontodir
         try:
             self.store.start()
diff --git a/tests/functional-tests/common/utils/writebacktest.py 
b/tests/functional-tests/common/utils/writebacktest.py
index 397ea16db..0a31b44ff 100644
--- a/tests/functional-tests/common/utils/writebacktest.py
+++ b/tests/functional-tests/common/utils/writebacktest.py
@@ -20,19 +20,22 @@
 
 from gi.repository import GLib
 
-from common.utils.system import TrackerSystemAbstraction
-import shutil
-import unittest as ut
+import logging
 import os
 import pathlib
-from common.utils import configuration as cfg
-from common.utils.helpers import log
+import shutil
 import time
+import unittest as ut
+
+from common.utils.system import TrackerSystemAbstraction
+from common.utils import configuration as cfg
 
 TEST_FILE_JPEG = "writeback-test-1.jpeg"
 TEST_FILE_TIFF = "writeback-test-2.tif"
 TEST_FILE_PNG = "writeback-test-4.png"
 
+log = logging.getLogger(__name__)
+
 
 class CommonTrackerWritebackTest (ut.TestCase):
     """
@@ -82,7 +85,7 @@ class CommonTrackerWritebackTest (ut.TestCase):
         miner before returning.
 
         """
-        log("Copying %s -> %s" % (path, self.workdir))
+        log.debug("Copying %s -> %s", path, self.workdir)
         shutil.copy(path, self.workdir)
 
         output_path = pathlib.Path(os.path.join(self.workdir, os.path.basename(path)))


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