[tracker-miners/sam/file-processed-signal: 8/10] functional-tests: Add tracker_test_main()
- From: Sam Thursfield <sthursfield src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker-miners/sam/file-processed-signal: 8/10] functional-tests: Add tracker_test_main()
- Date: Fri, 1 May 2020 11:43:12 +0000 (UTC)
commit 2a5843ce457eed6547a43371e30ab437a7a6261b
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 1afb7f5db..24d8d17ba 100755
--- a/tests/functional-tests/extractor-decorator.py
+++ b/tests/functional-tests/extractor-decorator.py
@@ -73,4 +73,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 37a2a6902..9ea446ad5 100755
--- a/tests/functional-tests/extractor-flac-cuesheet.py
+++ b/tests/functional-tests/extractor-flac-cuesheet.py
@@ -93,4 +93,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 b199bb58d..a907a87e8 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 d0178f69d..f9b65d24d 100755
--- a/tests/functional-tests/fts-file-operations.py
+++ b/tests/functional-tests/fts-file-operations.py
@@ -141,4 +141,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 220e9fb4b..edd7414ea 100755
--- a/tests/functional-tests/miner-basic.py
+++ b/tests/functional-tests/miner-basic.py
@@ -354,4 +354,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 555ae774e..da27c2eea 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_TEST_GRAPH = "tracker:Documents"
-class MinerResourceRemovalTest(TrackerMinerTest):
+class MinerResourceRemovalTest(fixtures.TrackerMinerTest):
def prepare_directories(self):
# Override content from the base class
@@ -103,4 +101,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]