[tracker-miners/wip/carlosg/tap-tests: 2/3] tests: Add build-time option to use TAP protocol in tests




commit 8e7140878fc8dc8049785be21936d98165cb1dcd
Author: Carlos Garnacho <carlosg gnome org>
Date:   Mon Mar 22 11:56:22 2021 +0100

    tests: Add build-time option to use TAP protocol in tests
    
    This makes it easy to use the TAP protocol on all tests (incl.
    python ones) on CI, without dragging the dependency on tap.py on
    developer setups.

 meson.build                                       |  6 ++++++
 meson_options.txt                                 |  2 ++
 tests/functional-tests/configuration.json.in      |  1 +
 tests/functional-tests/configuration.py           |  5 +++++
 tests/functional-tests/extractor-generic.py       | 21 +++++++++++++++++----
 tests/functional-tests/fixtures.py                | 13 ++++++++++++-
 tests/functional-tests/meson.build                |  3 +++
 tests/functional-tests/writeback-audio.py         |  2 +-
 tests/functional-tests/writeback-image-details.py |  2 +-
 tests/functional-tests/writeback-images.py        |  2 +-
 tests/libtracker-extract/meson.build              |  8 ++++++--
 tests/libtracker-miner/meson.build                |  2 ++
 tests/libtracker-miners-common/meson.build        |  4 +++-
 13 files changed, 60 insertions(+), 11 deletions(-)
---
diff --git a/meson.build b/meson.build
index 4b0500b4c..5574809a1 100644
--- a/meson.build
+++ b/meson.build
@@ -448,6 +448,12 @@ test_c_args = tracker_c_args + [
   '-DTOP_SRCDIR="@0@/"'.format(meson.source_root()),
 ]
 
+if get_option('tap_tests')
+  test_protocol = 'tap'
+else
+  test_protocol = 'exitcode'
+endif
+
 subdir('tests')
 
 run_uninstalled_conf = configuration_data()
diff --git a/meson_options.txt b/meson_options.txt
index e117c0d5e..1483b1ec5 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -89,3 +89,5 @@ option('systemd_user_services', type: 'boolean', value: true,
        description: 'Whether to install systemd user .service files')
 option('systemd_user_services_dir', type: 'string',
        description: 'Directory to install systemd user .service files (value from systemd.pc is used by 
default)')
+option('tap_tests', type: 'boolean', value: false,
+       description: 'Whether to enable TAP protocol on tests')
diff --git a/tests/functional-tests/configuration.json.in b/tests/functional-tests/configuration.json.in
index 6a3187cfb..b77ca1d50 100644
--- a/tests/functional-tests/configuration.json.in
+++ b/tests/functional-tests/configuration.json.in
@@ -9,5 +9,6 @@
     "TEST_GSETTINGS_SCHEMA_DIR": "@TEST_GSETTINGS_SCHEMA_DIR@",
     "TEST_LANGUAGE_STOP_WORDS_DIR": "@TEST_LANGUAGE_STOP_WORDS_DIR@",
     "TEST_WRITEBACK_MODULES_DIR": "@TEST_WRITEBACK_MODULES_DIR@",
+    "TEST_TAP_ENABLED": "@TEST_TAP_ENABLED@",
     "TRACKER_EXTRACT_PATH": "@TRACKER_EXTRACT_PATH@"
 }
diff --git a/tests/functional-tests/configuration.py b/tests/functional-tests/configuration.py
index 22ad30102..59dfb015d 100644
--- a/tests/functional-tests/configuration.py
+++ b/tests/functional-tests/configuration.py
@@ -66,6 +66,11 @@ def cli_subcommands_dir():
     return config['TEST_CLI_SUBCOMMANDS_DIR']
 
 
+def tap_tests_enabled():
+    return True
+    return config['TEST_TAP_ENABLED']
+
+
 def nepomuk_path():
     parser = configparser.ConfigParser()
     parser.read(config['TEST_DOMAIN_ONTOLOGY_RULE'])
diff --git a/tests/functional-tests/extractor-generic.py b/tests/functional-tests/extractor-generic.py
index 59c964a79..9c0802e03 100755
--- a/tests/functional-tests/extractor-generic.py
+++ b/tests/functional-tests/extractor-generic.py
@@ -124,6 +124,20 @@ class GenericExtractionTestCase(fixtures.TrackerExtractTestCase):
             print("\ntracker-extract returned: %s" % json.dumps(result, indent=4))
             raise
 
+def run_suite(suite):
+    if cfg.tap_tests_enabled():
+        try:
+            from tap import TAPTestRunner
+            runner = TAPTestRunner()
+            runner.set_stream(True)
+        except ImportError as e:
+            log.error('No TAP test runner found: %s', e)
+            raise
+    else:
+        runner = ut.TextTestRunner(verbosity=1)
+
+    result = runner.run(suite)
+    sys.exit(not result.wasSuccessful())
 
 def run_all():
     ##
@@ -146,8 +160,8 @@ def run_all():
         for descfile in descriptions:
             tc = GenericExtractionTestCase(descfile=descfile)
             extractionTestSuite.addTest(tc)
-    result = ut.TextTestRunner(verbosity=1).run(extractionTestSuite)
-    sys.exit(not result.wasSuccessful())
+
+    run_suite(extractionTestSuite)
 
 
 def run_one(filename):
@@ -160,8 +174,7 @@ def run_one(filename):
     tc = GenericExtractionTestCase(descfile=description)
     extractionTestSuite.addTest(tc)
 
-    result = ut.TextTestRunner(verbosity=2).run(extractionTestSuite)
-    sys.exit(not result.wasSuccessful())
+    run_suite(extractionTestSuite)
 
 
 try:
diff --git a/tests/functional-tests/fixtures.py b/tests/functional-tests/fixtures.py
index 4e3a66bd5..ace1a65ce 100644
--- a/tests/functional-tests/fixtures.py
+++ b/tests/functional-tests/fixtures.py
@@ -69,7 +69,18 @@ def tracker_test_main():
                             handlers=[handler_stderr, handler_stdout],
                             format='%(message)s')
 
-    ut.main(failfast=True, verbosity=2)
+    runner = None
+
+    if cfg.tap_tests_enabled():
+        try:
+            from tap import TAPTestRunner
+            runner = TAPTestRunner()
+            runner.set_stream(True)
+        except ImportError as e:
+            log.error('No TAP test runner found: %s', e)
+            raise
+
+    ut.main(testRunner=runner, failfast=True, verbosity=2)
 
 
 class TrackerMinerTest(ut.TestCase):
diff --git a/tests/functional-tests/meson.build b/tests/functional-tests/meson.build
index f449b4c98..f3303cf01 100644
--- a/tests/functional-tests/meson.build
+++ b/tests/functional-tests/meson.build
@@ -18,6 +18,7 @@ testconf.set('TEST_GSETTINGS_SCHEMA_DIR', tracker_miners_uninstalled_gsettings_s
 testconf.set('TEST_LANGUAGE_STOP_WORDS_DIR', tracker_uninstalled_stop_words_dir)
 testconf.set('TEST_ONTOLOGIES_DIR', tracker_uninstalled_nepomuk_ontologies_dir)
 testconf.set('TEST_WRITEBACK_MODULES_DIR', tracker_uninstalled_writeback_modules_dir)
+testconf.set('TEST_TAP_ENABLED', get_option('tap_tests'))
 testconf.set('TRACKER_EXTRACT_PATH', uninstalled_tracker_extract_path)
 
 test_domain_rule = configure_file(
@@ -176,6 +177,7 @@ foreach t: extractor_tests
   test(test_name, python,
     args: ['extractor-generic.py', data],
     env: test_env,
+    protocol: test_protocol,
     suite: ['extractor'] + test_suite,
     workdir: meson.current_source_dir())
 endforeach
@@ -185,6 +187,7 @@ foreach t: functional_tests
   test(t, python,
     args: [file],
     env: test_env,
+    protocol: test_protocol,
     suite: ['functional'],
     timeout: 120)
 endforeach
diff --git a/tests/functional-tests/writeback-audio.py b/tests/functional-tests/writeback-audio.py
index 93616d386..a4555afdf 100755
--- a/tests/functional-tests/writeback-audio.py
+++ b/tests/functional-tests/writeback-audio.py
@@ -56,4 +56,4 @@ class WritebackAudioTest(fixtures.TrackerWritebackTest):
         self._writeback_test(self.datadir_path('writeback-test-8.mp4'))
 
 if __name__ == "__main__":
-    unittest.main(failfast=True, verbosity=2)
+    fixtures.tracker_test_main()
diff --git a/tests/functional-tests/writeback-image-details.py 
b/tests/functional-tests/writeback-image-details.py
index 3597e63e0..0b73a4136 100755
--- a/tests/functional-tests/writeback-image-details.py
+++ b/tests/functional-tests/writeback-image-details.py
@@ -107,4 +107,4 @@ class WritebackKeepDateTest (fixtures.TrackerWritebackTest):
 
 
 if __name__ == "__main__":
-    ut.main(verbosity=2)
+    fixtures.tracker_test_main()
diff --git a/tests/functional-tests/writeback-images.py b/tests/functional-tests/writeback-images.py
index d1182d2c2..05c744076 100755
--- a/tests/functional-tests/writeback-images.py
+++ b/tests/functional-tests/writeback-images.py
@@ -142,4 +142,4 @@ class WritebackImagesTest(fixtures.TrackerWritebackTest):
 
 
 if __name__ == "__main__":
-    ut.main(failfast=True, verbosity=2)
+    fixtures.tracker_test_main()
diff --git a/tests/libtracker-extract/meson.build b/tests/libtracker-extract/meson.build
index 90042ccd4..5e3ac60a8 100644
--- a/tests/libtracker-extract/meson.build
+++ b/tests/libtracker-extract/meson.build
@@ -26,7 +26,9 @@ foreach base_name: libtracker_extract_tests
       dependencies: libtracker_extract_test_deps,
       c_args: test_c_args)
 
-    test(base_name, binary, suite: 'extract')
+    test(base_name, binary,
+      protocol: test_protocol,
+      suite: 'extract')
 endforeach
 
 if libiptcdata.found() and libjpeg.found()
@@ -35,5 +37,7 @@ if libiptcdata.found() and libjpeg.found()
     dependencies: libtracker_extract_test_deps + [libjpeg],
     c_args: test_c_args,
   )
-  test('extract-iptc', iptc_test, suite: 'extract')
+  test('extract-iptc', iptc_test,
+    protocol: test_protocol,
+    suite: 'extract')
 endif
diff --git a/tests/libtracker-miner/meson.build b/tests/libtracker-miner/meson.build
index 57075f14b..ed88f104d 100644
--- a/tests/libtracker-miner/meson.build
+++ b/tests/libtracker-miner/meson.build
@@ -38,6 +38,7 @@ foreach base_name: libtracker_miner_tests
 
     test(test_name, binary,
       env: libtracker_miner_test_environment,
+      protocol: test_protocol,
       suite: 'miner')
 endforeach
 
@@ -54,5 +55,6 @@ foreach base_name: libtracker_miner_slow_tests
     test(test_name, binary,
       env: libtracker_miner_test_environment,
       timeout: 180,
+      protocol: test_protocol,
       suite: ['miner', 'slow'])
 endforeach
diff --git a/tests/libtracker-miners-common/meson.build b/tests/libtracker-miners-common/meson.build
index d284a66a1..e1173634f 100644
--- a/tests/libtracker-miners-common/meson.build
+++ b/tests/libtracker-miners-common/meson.build
@@ -19,5 +19,7 @@ foreach base_name: libtracker_common_tests
       dependencies: libtracker_miners_common_test_deps,
       c_args: test_c_args)
 
-    test(base_name, binary, suite: 'miners-common')
+    test(base_name, binary,
+      protocol: test_protocol,
+      suite: 'miners-common')
 endforeach


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