[tracker-miners/sam/index-file-sync: 12/18] functional-tests: Add tracker_test_main()
- From: Sam Thursfield <sthursfield src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker-miners/sam/index-file-sync: 12/18] functional-tests: Add tracker_test_main()
- Date: Mon, 23 Mar 2020 01:30:08 +0000 (UTC)
commit cb765a5b765d4886ea7ea2444fe861b84592838f
Author: Sam Thursfield <sam afuera me uk>
Date: Sat Mar 21 17:00:36 2020 +0100
functional-tests: Add tracker_test_main()
This wraps unittest.main() but also sets up logging correctly.
Previously the logging setup happened as a sideeffect of importing
the 'configuration' module, which was not a good approach.
tests/functional-tests/configuration.py | 16 ++--------------
tests/functional-tests/extractor-decorator.py | 2 +-
tests/functional-tests/extractor-flac-cuesheet.py | 2 +-
tests/functional-tests/fixtures.py | 21 +++++++++++++++++++++
tests/functional-tests/fts-basic.py | 2 +-
tests/functional-tests/fts-file-operations.py | 2 +-
tests/functional-tests/fts-stopwords.py | 2 +-
tests/functional-tests/miner-basic.py | 2 +-
tests/functional-tests/miner-resource-removal.py | 8 +++-----
9 files changed, 32 insertions(+), 25 deletions(-)
---
diff --git a/tests/functional-tests/configuration.py b/tests/functional-tests/configuration.py
index 8a2d5b2b1..b8b955f77 100644
--- a/tests/functional-tests/configuration.py
+++ b/tests/functional-tests/configuration.py
@@ -115,17 +115,5 @@ def get_environment_int(variable, default=0):
return default
-if get_environment_boolean('TRACKER_TESTS_VERBOSE'):
- # Output all logs to stderr
- logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
-else:
- # Output some messages from D-Bus daemon to stderr by default. In practice,
- # only errors and warnings should be output here unless the environment
- # contains G_MESSAGES_DEBUG= and/or TRACKER_VERBOSITY=1 or more.
- handler_stderr = logging.StreamHandler(stream=sys.stderr)
- handler_stderr.addFilter(logging.Filter('trackertestutils.dbusdaemon.stderr'))
- handler_stdout = logging.StreamHandler(stream=sys.stderr)
- handler_stdout.addFilter(logging.Filter('trackertestutils.dbusdaemon.stdout'))
- logging.basicConfig(level=logging.INFO,
- handlers=[handler_stderr, handler_stdout],
- format='%(message)s')
+def tests_verbose():
+ return get_environment_boolean('TRACKER_TESTS_VERBOSE')
diff --git a/tests/functional-tests/extractor-decorator.py b/tests/functional-tests/extractor-decorator.py
index d77c035c9..752ed109e 100755
--- a/tests/functional-tests/extractor-decorator.py
+++ b/tests/functional-tests/extractor-decorator.py
@@ -71,4 +71,4 @@ class ExtractorDecoratorTest(fixtures.TrackerMinerTest):
if __name__ == '__main__':
- ut.main(verbosity=2)
+ fixtures.tracker_test_main()
diff --git a/tests/functional-tests/extractor-flac-cuesheet.py
b/tests/functional-tests/extractor-flac-cuesheet.py
index 2497ae0de..2d0bf461b 100755
--- a/tests/functional-tests/extractor-flac-cuesheet.py
+++ b/tests/functional-tests/extractor-flac-cuesheet.py
@@ -97,4 +97,4 @@ class FlacCuesheetTest(fixtures.TrackerExtractTestCase):
if __name__ == '__main__':
- ut.main(verbosity=2)
+ fixtures.tracker_test_main()
diff --git a/tests/functional-tests/fixtures.py b/tests/functional-tests/fixtures.py
index 9cd0001a7..55c7f1b35 100644
--- a/tests/functional-tests/fixtures.py
+++ b/tests/functional-tests/fixtures.py
@@ -35,6 +35,7 @@ import os
import pathlib
import shutil
import subprocess
+import sys
import time
import unittest as ut
@@ -46,6 +47,26 @@ from minerfshelper import MinerFsHelper
log = logging.getLogger(__name__)
+def tracker_test_main():
+ """Entry point which must be called by all functional test modules."""
+ if cfg.tests_verbose():
+ # Output all logs to stderr
+ logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
+ else:
+ # Output some messages from D-Bus daemon to stderr by default. In practice,
+ # only errors and warnings should be output here unless the environment
+ # contains G_MESSAGES_DEBUG= and/or TRACKER_VERBOSITY=1 or more.
+ handler_stderr = logging.StreamHandler(stream=sys.stderr)
+ handler_stderr.addFilter(logging.Filter('trackertestutils.dbusdaemon.stderr'))
+ handler_stdout = logging.StreamHandler(stream=sys.stderr)
+ handler_stdout.addFilter(logging.Filter('trackertestutils.dbusdaemon.stdout'))
+ logging.basicConfig(level=logging.INFO,
+ handlers=[handler_stderr, handler_stdout],
+ format='%(message)s')
+
+ ut.main(failfast=True, verbosity=2)
+
+
class TrackerMinerTest(ut.TestCase):
def __init__(self, *args, **kwargs):
super(TrackerMinerTest, self).__init__(*args, **kwargs)
diff --git a/tests/functional-tests/fts-basic.py b/tests/functional-tests/fts-basic.py
index 4358b69dc..6f360bf75 100755
--- a/tests/functional-tests/fts-basic.py
+++ b/tests/functional-tests/fts-basic.py
@@ -102,4 +102,4 @@ class MinerFTSBasicTest(fixtures.TrackerMinerFTSTest):
if __name__ == "__main__":
- ut.main(failfast=True, verbosity=2)
+ fixtures.tracker_test_main()
diff --git a/tests/functional-tests/fts-file-operations.py b/tests/functional-tests/fts-file-operations.py
index 2a4d2b14b..b9393b2cc 100755
--- a/tests/functional-tests/fts-file-operations.py
+++ b/tests/functional-tests/fts-file-operations.py
@@ -135,4 +135,4 @@ class MinerFTSFileOperationsTest(fixtures.TrackerMinerFTSTest):
if __name__ == "__main__":
- ut.main(failfast=True, verbosity=2)
+ fixtures.tracker_test_main()
diff --git a/tests/functional-tests/fts-stopwords.py b/tests/functional-tests/fts-stopwords.py
index 95fa29397..e02805c3d 100755
--- a/tests/functional-tests/fts-stopwords.py
+++ b/tests/functional-tests/fts-stopwords.py
@@ -83,4 +83,4 @@ class MinerFTSStopwordsTest(fixtures.TrackerMinerFTSTest):
if __name__ == "__main__":
- ut.main(failfast=True, verbosity=2)
+ fixtures.tracker_test_main()
diff --git a/tests/functional-tests/miner-basic.py b/tests/functional-tests/miner-basic.py
index 5a4fb9559..e47b4b158 100755
--- a/tests/functional-tests/miner-basic.py
+++ b/tests/functional-tests/miner-basic.py
@@ -353,4 +353,4 @@ class MinerCrawlTest(fixtures.TrackerMinerTest):
if __name__ == "__main__":
- ut.main(failfast=True, verbosity=2)
+ fixtures.tracker_test_main()
diff --git a/tests/functional-tests/miner-resource-removal.py
b/tests/functional-tests/miner-resource-removal.py
index 91a08f1f1..2077d452b 100755
--- a/tests/functional-tests/miner-resource-removal.py
+++ b/tests/functional-tests/miner-resource-removal.py
@@ -25,13 +25,11 @@ import os
import pathlib
import unittest as ut
-# We must import this to set up logging.
-import configuration
-from fixtures import TrackerMinerTest
+import fixtures
TRACKER_OWN_GRAPH_URN = "urn:uuid:472ed0cc-40ff-4e37-9c0c-062d78656540"
-class MinerResourceRemovalTest(TrackerMinerTest):
+class MinerResourceRemovalTest(fixtures.TrackerMinerTest):
def prepare_directories(self):
# Override content from the base class
@@ -104,4 +102,4 @@ class MinerResourceRemovalTest(TrackerMinerTest):
if __name__ == "__main__":
- ut.main(failfast=True, verbosity=2)
+ fixtures.tracker_test_main()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]