You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by ro...@apache.org on 2020/12/29 13:29:24 UTC

[buildstream] 08/08: Adapting test cases to expect logs in stderr

This is an automated email from the ASF dual-hosted git repository.

root pushed a commit to branch early-logging
in repository https://gitbox.apache.org/repos/asf/buildstream.git

commit 44a49070c07433c99e6d9745f61479a21bbc31fd
Author: Tristan Van Berkom <tr...@codethink.co.uk>
AuthorDate: Wed Dec 13 11:49:39 2017 -0500

    Adapting test cases to expect logs in stderr
    
    And also adapted them to remove any occurrences of HAVE_ROOT.
---
 tests/context/context.py     |  4 ----
 tests/frontend/buildtrack.py |  6 +++---
 tests/frontend/overlaps.py   |  6 +++---
 tests/frontend/show.py       | 10 ++++------
 tests/plugins/pipeline.py    | 14 +++++---------
 tests/project/plugins.py     | 10 +++++-----
 tests/sources/tar.py         |  2 +-
 tests/sources/zip.py         |  2 +-
 tests/variables/variables.py | 11 +++++------
 9 files changed, 27 insertions(+), 38 deletions(-)

diff --git a/tests/context/context.py b/tests/context/context.py
index 0db589a..442069b 100644
--- a/tests/context/context.py
+++ b/tests/context/context.py
@@ -4,8 +4,6 @@ import pytest
 from buildstream._context import Context
 from buildstream._exceptions import LoadError, LoadErrorReason
 
-from tests.testutils.site import HAVE_ROOT
-
 DATA_DIR = os.path.join(
     os.path.dirname(os.path.realpath(__file__)),
     'data',
@@ -37,7 +35,6 @@ def test_context_create(context_fixture):
 #######################################
 #     Test configuration loading      #
 #######################################
-@pytest.mark.skipif(not HAVE_ROOT, reason="requires root permissions")
 def test_context_load(context_fixture):
     context = context_fixture['context']
     cache_home = context_fixture['xdg-cache']
@@ -52,7 +49,6 @@ def test_context_load(context_fixture):
 
 # Test that values in a user specified config file
 # override the defaults
-@pytest.mark.skipif(not HAVE_ROOT, reason="requires root permissions")
 @pytest.mark.datafiles(os.path.join(DATA_DIR))
 def test_context_load_user_config(context_fixture, datafiles):
     context = context_fixture['context']
diff --git a/tests/frontend/buildtrack.py b/tests/frontend/buildtrack.py
index e91274a..45dd30d 100644
--- a/tests/frontend/buildtrack.py
+++ b/tests/frontend/buildtrack.py
@@ -300,12 +300,12 @@ def test_build_track_track_first(cli, datafiles, tmpdir, strict):
     assert result.exit_code == 0
 
     # Assert that 1.bst successfully tracks before 0.bst builds
-    track_messages = re.finditer(r'\[track:1.bst\s*]', result.output)
-    build_0 = re.search(r'\[build:0.bst\s*] START', result.output).start()
+    track_messages = re.finditer(r'\[track:1.bst\s*]', result.stderr)
+    build_0 = re.search(r'\[build:0.bst\s*] START', result.stderr).start()
     assert all(track_message.start() < build_0 for track_message in track_messages)
 
     # Assert that 2.bst is *only* rebuilt if we are in strict mode
-    build_2 = re.search(r'\[build:2.bst\s*] START', result.output)
+    build_2 = re.search(r'\[build:2.bst\s*] START', result.stderr)
     if strict == '--strict':
         assert build_2 is not None
     else:
diff --git a/tests/frontend/overlaps.py b/tests/frontend/overlaps.py
index cc7c08f..4ef5657 100644
--- a/tests/frontend/overlaps.py
+++ b/tests/frontend/overlaps.py
@@ -17,6 +17,6 @@ def test_overlaps(cli, datafiles):
 
     assert result.exit_code == 0
     print(result.output)
-    assert "/file1: three.bst above one.bst" in result.output
-    assert "/file2: two.bst above three.bst above one.bst" in result.output
-    assert "/file3: two.bst above three.bst" in result.output
+    assert "/file1: three.bst above one.bst" in result.stderr
+    assert "/file2: two.bst above three.bst above one.bst" in result.stderr
+    assert "/file3: two.bst above three.bst" in result.stderr
diff --git a/tests/frontend/show.py b/tests/frontend/show.py
index fde6201..2c2f03d 100644
--- a/tests/frontend/show.py
+++ b/tests/frontend/show.py
@@ -70,9 +70,8 @@ def test_parallel_order(cli, tmpdir, datafiles):
 
     assert result.exit_code == 0
 
-    # Get the planned order, excepting the 'Loading' messages before
-    # the pipeline is printed
-    names = result.output.splitlines()[3:]
+    # Get the planned order
+    names = result.output.splitlines()
     names = [name[len('multiple_targets/order/'):] for name in names]
 
     # Create all possible 'correct' topological orderings
@@ -100,9 +99,8 @@ def test_target_is_dependency(cli, tmpdir, datafiles):
 
     assert result.exit_code == 0
 
-    # Get the planned order, excepting the 'Loading' messages before
-    # the pipeline is printed
-    names = result.output.splitlines()[3:]
+    # Get the planned order
+    names = result.output.splitlines()
     names = [name[len('multiple_targets/dependency/'):] for name in names]
 
     assert names == ['pony.bst', 'horsey.bst', 'zebry.bst']
diff --git a/tests/plugins/pipeline.py b/tests/plugins/pipeline.py
index c659aa3..a77dcd1 100644
--- a/tests/plugins/pipeline.py
+++ b/tests/plugins/pipeline.py
@@ -5,9 +5,6 @@ from buildstream._context import Context
 from buildstream._project import Project
 from buildstream._exceptions import PluginError
 from buildstream._pipeline import Pipeline
-from buildstream._platform import Platform
-
-from tests.testutils.site import HAVE_ROOT
 
 DATA_DIR = os.path.join(
     os.path.dirname(os.path.realpath(__file__)),
@@ -18,15 +15,17 @@ DATA_DIR = os.path.join(
 def create_pipeline(tmpdir, basedir, target):
     context = Context([])
     project = Project(basedir, context)
-
     context.deploydir = os.path.join(str(tmpdir), 'deploy')
     context.artifactdir = os.path.join(str(tmpdir), 'artifact')
-    context._platform = Platform.get_platform()
+
+    def dummy_handler(message, context):
+        pass
+
+    context._set_message_handler(dummy_handler)
 
     return Pipeline(context, project, [target], [])
 
 
-@pytest.mark.skipif(not HAVE_ROOT, reason="requires root permissions")
 @pytest.mark.datafiles(os.path.join(DATA_DIR, 'customsource'))
 def test_customsource(datafiles, tmpdir):
 
@@ -35,7 +34,6 @@ def test_customsource(datafiles, tmpdir):
     assert(pipeline.targets[0].get_kind() == "autotools")
 
 
-@pytest.mark.skipif(not HAVE_ROOT, reason="requires root permissions")
 @pytest.mark.datafiles(os.path.join(DATA_DIR, 'customelement'))
 def test_customelement(datafiles, tmpdir):
 
@@ -44,7 +42,6 @@ def test_customelement(datafiles, tmpdir):
     assert(pipeline.targets[0].get_kind() == "foo")
 
 
-@pytest.mark.skipif(not HAVE_ROOT, reason="requires root permissions")
 @pytest.mark.datafiles(os.path.join(DATA_DIR, 'badversionsource'))
 def test_badversionsource(datafiles, tmpdir):
     basedir = os.path.join(datafiles.dirname, datafiles.basename)
@@ -53,7 +50,6 @@ def test_badversionsource(datafiles, tmpdir):
         pipeline = create_pipeline(tmpdir, basedir, 'simple.bst')
 
 
-@pytest.mark.skipif(not HAVE_ROOT, reason="requires root permissions")
 @pytest.mark.datafiles(os.path.join(DATA_DIR, 'badversionelement'))
 def test_badversionelement(datafiles, tmpdir):
     basedir = os.path.join(datafiles.dirname, datafiles.basename)
diff --git a/tests/project/plugins.py b/tests/project/plugins.py
index 7932fcd..4040137 100644
--- a/tests/project/plugins.py
+++ b/tests/project/plugins.py
@@ -4,9 +4,6 @@ import pytest
 from buildstream._context import Context
 from buildstream._project import Project
 from buildstream._pipeline import Pipeline
-from buildstream._platform import Platform
-
-from tests.testutils.site import HAVE_ROOT
 
 DATA_DIR = os.path.join(
     os.path.dirname(os.path.realpath(__file__)),
@@ -18,7 +15,11 @@ def create_pipeline(tmpdir, basedir, target):
     context = Context([])
     project = Project(basedir, context)
     context.artifactdir = os.path.join(str(tmpdir), 'artifact')
-    context._platform = Platform.get_platform()
+
+    def dummy_handler(message, context):
+        pass
+
+    context._set_message_handler(dummy_handler)
 
     return Pipeline(context, project, [target], [])
 
@@ -29,7 +30,6 @@ def create_pipeline(tmpdir, basedir, target):
 # also test that the project's configuration of plugin
 # paths is actually working.
 #
-@pytest.mark.skipif(not HAVE_ROOT, reason="requires root permissions")
 @pytest.mark.datafiles(os.path.join(DATA_DIR, 'plugins'))
 def test_custom_element(datafiles, tmpdir):
 
diff --git a/tests/sources/tar.py b/tests/sources/tar.py
index b1859a8..ca1bef7 100644
--- a/tests/sources/tar.py
+++ b/tests/sources/tar.py
@@ -104,7 +104,7 @@ def test_track_warning(cli, tmpdir, datafiles):
         'track', 'target.bst'
     ])
     assert result.exit_code == 0
-    assert "Potential man-in-the-middle attack!" in result.output
+    assert "Potential man-in-the-middle attack!" in result.stderr
 
 
 def _list_dir_contents(srcdir):
diff --git a/tests/sources/zip.py b/tests/sources/zip.py
index 2fd0c04..70ad491 100644
--- a/tests/sources/zip.py
+++ b/tests/sources/zip.py
@@ -91,7 +91,7 @@ def test_track_warning(cli, tmpdir, datafiles):
         'track', 'target.bst'
     ])
     assert result.exit_code == 0
-    assert "Potential man-in-the-middle attack!" in result.output
+    assert "Potential man-in-the-middle attack!" in result.stderr
 
 
 def _list_dir_contents(srcdir):
diff --git a/tests/variables/variables.py b/tests/variables/variables.py
index 47b1ff9..24f323c 100644
--- a/tests/variables/variables.py
+++ b/tests/variables/variables.py
@@ -5,9 +5,6 @@ from buildstream import BuildElement
 from buildstream._context import Context
 from buildstream._project import Project
 from buildstream._pipeline import Pipeline
-from buildstream._platform import Platform
-
-from tests.testutils.site import HAVE_ROOT
 
 DATA_DIR = os.path.join(
     os.path.dirname(os.path.realpath(__file__)),
@@ -18,7 +15,11 @@ def create_pipeline(tmpdir, basedir, target):
     context = Context([])
     project = Project(basedir, context)
     context.artifactdir = os.path.join(str(tmpdir), 'artifact')
-    context._platform = Platform.get_platform()
+
+    def dummy_handler(message, context):
+        pass
+
+    context._set_message_handler(dummy_handler)
 
     return Pipeline(context, project, [target], [])
 
@@ -41,7 +42,6 @@ def assert_command(datafiles, tmpdir, target, command, expected):
 ###############################################################
 #  Test proper loading of some default commands from plugins  #
 ###############################################################
-@pytest.mark.skipif(not HAVE_ROOT, reason="requires root permissions")
 @pytest.mark.parametrize("target,command,expected", [
     ('autotools.bst', 'install-commands', "make -j1 DESTDIR=\"/buildstream/install\" install"),
     ('cmake.bst', 'configure-commands',
@@ -62,7 +62,6 @@ def test_defaults(datafiles, tmpdir, target, command, expected):
 ################################################################
 #  Test overriding of variables to produce different commands  #
 ################################################################
-@pytest.mark.skipif(not HAVE_ROOT, reason="requires root permissions")
 @pytest.mark.parametrize("target,command,expected", [
     ('autotools.bst', 'install-commands', "make -j1 DESTDIR=\"/custom/install/root\" install"),
     ('cmake.bst', 'configure-commands',