You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by tv...@apache.org on 2023/02/21 06:37:08 UTC
[buildstream] branch tristan/python3.11-bst1 updated (78505f175 -> dfb7bb4f3)
This is an automated email from the ASF dual-hosted git repository.
tvb pushed a change to branch tristan/python3.11-bst1
in repository https://gitbox.apache.org/repos/asf/buildstream.git
discard 78505f175 Run tests in subprocesses
new 394e4b07b tests/loader/junctions.py: Use Result.assert_main_error()
new 2da083059 tests/frontend/show.py: xfail a test which we cannot properly assert
new 8c01ec1c5 Run tests in subprocesses
new dfb7bb4f3 setup.py: Advertize support for Python 3.10 and 3.11
This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version. This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:
* -- * -- B -- O -- O -- O (78505f175)
\
N -- N -- N refs/heads/tristan/python3.11-bst1 (dfb7bb4f3)
You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.
Any revisions marked "omit" are not gone; other references still
refer to them. Any revisions marked "discard" are gone forever.
The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
setup.py | 2 ++
tests/frontend/show.py | 11 +++++++++--
tests/loader/junctions.py | 25 +++++--------------------
tests/testutils/runcli.py | 7 -------
4 files changed, 16 insertions(+), 29 deletions(-)
[buildstream] 02/04: tests/frontend/show.py: xfail a test which we cannot properly assert
Posted by tv...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
tvb pushed a commit to branch tristan/python3.11-bst1
in repository https://gitbox.apache.org/repos/asf/buildstream.git
commit 2da08305959b61cf52ff7f0c55c58147614c52af
Author: Tristan van Berkom <tr...@codethink.co.uk>
AuthorDate: Tue Feb 21 15:35:34 2023 +0900
tests/frontend/show.py: xfail a test which we cannot properly assert
We can no longer assert that the client has exited without throwing
an exception.
---
tests/frontend/show.py | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/tests/frontend/show.py b/tests/frontend/show.py
index 7df5b7679..204816bf1 100644
--- a/tests/frontend/show.py
+++ b/tests/frontend/show.py
@@ -269,6 +269,7 @@ def test_fetched_junction(cli, tmpdir, datafiles, element_name, workspaced):
###############################################################
# Testing recursion depth #
###############################################################
+@pytest.mark.xfail("dependency_depth", [100, 500, 1200])
@pytest.mark.parametrize("dependency_depth", [100, 500, 1200])
def test_exceed_max_recursion_depth(cli, tmpdir, dependency_depth):
project_name = "recursion-test"
@@ -314,8 +315,14 @@ def test_exceed_max_recursion_depth(cli, tmpdir, dependency_depth):
if dependency_depth <= recursion_limit:
result.assert_success()
else:
- # Assert exception is thown and handled
- assert not result.unhandled_exception
+ # XXX Assert exception is thown and handled
+ #
+ # We need to assert that the client has not thrown a stack trace for
+ # a recursion error, this should be done by creating a BstError instead
+ # of just handling it in app.py and doing sys.exit(), because we no longer
+ # have any way of detecting whether the client has thrown an exception
+ # otherwise
+ #
assert result.exit_code == -1
shutil.rmtree(project_path)
[buildstream] 01/04: tests/loader/junctions.py: Use Result.assert_main_error()
Posted by tv...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
tvb pushed a commit to branch tristan/python3.11-bst1
in repository https://gitbox.apache.org/repos/asf/buildstream.git
commit 394e4b07b5a5b42c24836976dc550e7ebe664122
Author: Tristan van Berkom <tr...@codethink.co.uk>
AuthorDate: Tue Feb 21 15:34:28 2023 +0900
tests/loader/junctions.py: Use Result.assert_main_error()
Instead of manually asserting Result members, this is required because
some of the Result attributes are being removed.
---
tests/loader/junctions.py | 25 +++++--------------------
1 file changed, 5 insertions(+), 20 deletions(-)
diff --git a/tests/loader/junctions.py b/tests/loader/junctions.py
index aee164396..2d87146ae 100644
--- a/tests/loader/junctions.py
+++ b/tests/loader/junctions.py
@@ -135,10 +135,7 @@ def test_nested_conflict(cli, datafiles):
copy_subprojects(project, datafiles, ['foo', 'bar'])
result = cli.run(project=project, args=['build', 'target.bst'])
- assert result.exit_code != 0
- assert result.exception
- assert isinstance(result.exception, LoadError)
- assert result.exception.reason == LoadErrorReason.CONFLICTING_JUNCTION
+ result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.CONFLICTING_JUNCTION)
@pytest.mark.datafiles(DATA_DIR)
@@ -146,10 +143,7 @@ def test_invalid_missing(cli, datafiles):
project = os.path.join(str(datafiles), 'invalid')
result = cli.run(project=project, args=['build', 'missing.bst'])
- assert result.exit_code != 0
- assert result.exception
- assert isinstance(result.exception, LoadError)
- assert result.exception.reason == LoadErrorReason.MISSING_FILE
+ result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.MISSING_FILE)
@pytest.mark.datafiles(DATA_DIR)
@@ -158,10 +152,7 @@ def test_invalid_with_deps(cli, datafiles):
copy_subprojects(project, datafiles, ['base'])
result = cli.run(project=project, args=['build', 'junction-with-deps.bst'])
- assert result.exit_code != 0
- assert result.exception
- assert isinstance(result.exception, ElementError)
- assert result.exception.reason == 'element-forbidden-depends'
+ result.assert_main_error(ErrorDomain.ELEMENT, 'element-forbidden-depends')
@pytest.mark.datafiles(DATA_DIR)
@@ -170,10 +161,7 @@ def test_invalid_junction_dep(cli, datafiles):
copy_subprojects(project, datafiles, ['base'])
result = cli.run(project=project, args=['build', 'junction-dep.bst'])
- assert result.exit_code != 0
- assert result.exception
- assert isinstance(result.exception, LoadError)
- assert result.exception.reason == LoadErrorReason.INVALID_DATA
+ result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.INVALID_DATA)
@pytest.mark.datafiles(DATA_DIR)
@@ -248,10 +236,7 @@ def test_git_show(cli, tmpdir, datafiles):
# Verify that bst show does not implicitly fetch subproject
result = cli.run(project=project, args=['show', 'target.bst'])
- assert result.exit_code != 0
- assert result.exception
- assert isinstance(result.exception, LoadError)
- assert result.exception.reason == LoadErrorReason.SUBPROJECT_FETCH_NEEDED
+ result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.SUBPROJECT_FETCH_NEEDED)
# Explicitly fetch subproject
result = cli.run(project=project, args=['fetch', 'base.bst'])
[buildstream] 04/04: setup.py: Advertize support for Python 3.10 and 3.11
Posted by tv...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
tvb pushed a commit to branch tristan/python3.11-bst1
in repository https://gitbox.apache.org/repos/asf/buildstream.git
commit dfb7bb4f34eea555ea062f94ca07d3d19fd2e957
Author: Tristan van Berkom <tr...@codethink.co.uk>
AuthorDate: Tue Feb 21 14:52:01 2023 +0900
setup.py: Advertize support for Python 3.10 and 3.11
---
setup.py | 2 ++
1 file changed, 2 insertions(+)
diff --git a/setup.py b/setup.py
index e174ee337..77d226f20 100755
--- a/setup.py
+++ b/setup.py
@@ -263,6 +263,8 @@ setup(name='BuildStream',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
+ 'Programming Language :: Python :: 3.10',
+ 'Programming Language :: Python :: 3.11',
'Topic :: Software Development :: Build Tools'
],
description='A framework for modelling build pipelines in YAML',
[buildstream] 03/04: Run tests in subprocesses
Posted by tv...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
tvb pushed a commit to branch tristan/python3.11-bst1
in repository https://gitbox.apache.org/repos/asf/buildstream.git
commit 8c01ec1c5a7345491429103ad646ed315c24e355
Author: Tristan van Berkom <tr...@codethink.co.uk>
AuthorDate: Tue Feb 21 14:36:11 2023 +0900
Run tests in subprocesses
This is based off of work started by Seppo Yli-Olli
We now run tests in subprocesses instead of using multiprocessing,
this patch adds serialization of machine readable error codes so that
tests can work.
We no longer provide the raw exceptions in the test Result
object returned by Cli.run(), which limits the tests in some ways.
---
buildstream/_exceptions.py | 19 -----
buildstream/_frontend/app.py | 18 ++++-
tests/format/assertion.py | 2 +-
tests/frontend/fetch.py | 3 +-
tests/testutils/runcli.py | 172 +++++++++++++++----------------------------
5 files changed, 77 insertions(+), 137 deletions(-)
diff --git a/buildstream/_exceptions.py b/buildstream/_exceptions.py
index 44d890ead..4cdbc0bf2 100644
--- a/buildstream/_exceptions.py
+++ b/buildstream/_exceptions.py
@@ -24,25 +24,10 @@ from enum import Enum
# pylint: disable=global-statement
# The last raised exception, this is used in test cases only
-_last_exception = None
_last_task_error_domain = None
_last_task_error_reason = None
-# get_last_exception()
-#
-# Fetches the last exception from the main process
-#
-# Used by regression tests
-#
-def get_last_exception():
- global _last_exception
-
- le = _last_exception
- _last_exception = None
- return le
-
-
# get_last_task_error()
#
# Fetches the last exception from a task
@@ -102,7 +87,6 @@ class ErrorDomain(Enum):
class BstError(Exception):
def __init__(self, message, *, detail=None, domain=None, reason=None, temporary=False):
- global _last_exception
super().__init__(message)
@@ -126,9 +110,6 @@ class BstError(Exception):
self.domain = domain
self.reason = reason
- # Hold on to the last raised exception for testing purposes
- _last_exception = self
-
# PluginError
#
diff --git a/buildstream/_frontend/app.py b/buildstream/_frontend/app.py
index e9c646fb4..05fb296cb 100644
--- a/buildstream/_frontend/app.py
+++ b/buildstream/_frontend/app.py
@@ -22,9 +22,11 @@ import sys
import resource
import traceback
import datetime
+from enum import Enum
from textwrap import TextWrapper
from contextlib import contextmanager
+import ujson
import click
from click import UsageError
@@ -35,7 +37,7 @@ from .. import Scope
from .._context import Context
from .._platform import Platform
from .._project import Project
-from .._exceptions import BstError, StreamError, LoadError, LoadErrorReason, AppError
+from .._exceptions import BstError, StreamError, LoadError, LoadErrorReason, AppError, get_last_task_error
from .._message import Message, MessageType, unconditional_messages
from .._stream import Stream
from .._versions import BST_FORMAT_VERSION
@@ -682,6 +684,20 @@ class App():
detail = '\n' + indent + indent.join(error.detail.splitlines(True))
click.echo("{}".format(detail), err=True)
+ # Record machine readable errors in a tempfile for the test harness to read back
+ if 'BST_TEST_ERROR_CODES' in os.environ:
+ task_error_domain, task_error_reason = get_last_task_error ()
+ error_codes = ujson.dumps ({
+ 'main_error_domain': error.domain.value if error.domain else None,
+ 'main_error_reason': error.reason.value if isinstance (error.reason, Enum) else error.reason,
+ 'task_error_domain': task_error_domain.value if task_error_domain else None,
+ 'task_error_reason': (
+ task_error_reason.value if isinstance (task_error_reason, Enum) else task_error_reason
+ )
+ })
+ with open (os.environ['BST_TEST_ERROR_CODES'], "w", encoding="utf-8") as f:
+ f.write (error_codes)
+
sys.exit(-1)
#
diff --git a/tests/format/assertion.py b/tests/format/assertion.py
index 42f69b759..d82fa3226 100644
--- a/tests/format/assertion.py
+++ b/tests/format/assertion.py
@@ -32,4 +32,4 @@ def test_assertion_cli(cli, datafiles, target, opt_pony, opt_horsy, assertion):
# Assert that the assertion text provided by the user
# is found in the exception text
- assert assertion in str(result.exception)
+ assert assertion in str(result.stderr)
diff --git a/tests/frontend/fetch.py b/tests/frontend/fetch.py
index e896f4a67..5351ee8fe 100644
--- a/tests/frontend/fetch.py
+++ b/tests/frontend/fetch.py
@@ -71,8 +71,7 @@ def test_fetch_consistency_bug(cli, tmpdir, datafiles):
# more gracefully as a BUG message.
#
result = cli.run(project=project, args=['fetch', 'bug.bst'])
- assert result.exc is not None
- assert str(result.exc) == "Something went terribly wrong"
+ assert "Something went terribly wrong" in result.stderr
@pytest.mark.datafiles(DATA_DIR)
diff --git a/tests/testutils/runcli.py b/tests/testutils/runcli.py
index 29a2ec1e9..77912bbce 100644
--- a/tests/testutils/runcli.py
+++ b/tests/testutils/runcli.py
@@ -7,6 +7,8 @@ import itertools
import traceback
import subprocess
from contextlib import contextmanager, ExitStack
+from enum import Enum
+import ujson
import pytest
# XXX Using pytest private internals here
@@ -22,50 +24,21 @@ from _pytest.capture import MultiCapture, FDCapture
from buildstream._frontend import cli as bst_cli
from buildstream import _yaml
-# Special private exception accessor, for test case purposes
-from buildstream._exceptions import BstError, get_last_exception, get_last_task_error
-
# Wrapper for the click.testing result
class Result():
def __init__(self,
exit_code=None,
- exception=None,
- exc_info=None,
output=None,
stderr=None):
self.exit_code = exit_code
- self.exc = exception
- self.exc_info = exc_info
self.output = output
self.stderr = stderr
- self.unhandled_exception = False
-
- # The last exception/error state is stored at exception
- # creation time in BstError(), but this breaks down with
- # recoverable errors where code blocks ignore some errors
- # and fallback to alternative branches.
- #
- # For this reason, we just ignore the exception and errors
- # in the case that the exit code reported is 0 (success).
- #
- if self.exit_code != 0:
-
- # Check if buildstream failed to handle an
- # exception, topevel CLI exit should always
- # be a SystemExit exception.
- #
- if not isinstance(exception, SystemExit):
- self.unhandled_exception = True
-
- self.exception = get_last_exception()
- self.task_error_domain, \
- self.task_error_reason = get_last_task_error()
- else:
- self.exception = None
- self.task_error_domain = None
- self.task_error_reason = None
+ self.main_error_domain = None
+ self.main_error_reason = None
+ self.task_error_domain = None
+ self.task_error_reason = None
# assert_success()
#
@@ -79,9 +52,6 @@ class Result():
#
def assert_success(self, fail_message=''):
assert self.exit_code == 0, fail_message
- assert self.exc is None, fail_message
- assert self.exception is None, fail_message
- assert self.unhandled_exception is False
# assert_main_error()
#
@@ -106,23 +76,20 @@ class Result():
print(
"""
Exit code: {}
- Exception: {}
Domain: {}
Reason: {}
""".format(
self.exit_code,
- self.exception,
- self.exception.domain,
- self.exception.reason
+ self.main_error_domain,
+ self.main_error_reason
))
- assert self.exit_code == -1, fail_message
- assert self.exc is not None, fail_message
- assert self.exception is not None, fail_message
- assert isinstance(self.exception, BstError), fail_message
- assert self.unhandled_exception is False
+ assert self.exit_code != 0, fail_message
+
+ test_domain = error_domain.value if isinstance (error_domain, Enum) else error_domain
+ test_reason = error_reason.value if isinstance (error_reason, Enum) else error_reason
- assert self.exception.domain == error_domain, fail_message
- assert self.exception.reason == error_reason, fail_message
+ assert self.main_error_domain == test_domain, fail_message
+ assert self.main_error_reason == test_reason, fail_message
# assert_task_error()
#
@@ -143,14 +110,12 @@ class Result():
error_reason,
fail_message=''):
- assert self.exit_code == -1, fail_message
- assert self.exc is not None, fail_message
- assert self.exception is not None, fail_message
- assert isinstance(self.exception, BstError), fail_message
- assert self.unhandled_exception is False
+ test_domain = error_domain.value if isinstance (error_domain, Enum) else error_domain
+ test_reason = error_reason.value if isinstance (error_reason, Enum) else error_reason
- assert self.task_error_domain == error_domain, fail_message
- assert self.task_error_reason == error_reason, fail_message
+ assert self.exit_code != 0, fail_message
+ assert self.task_error_domain == test_domain, fail_message
+ assert self.task_error_reason == test_reason, fail_message
# get_tracked_elements()
#
@@ -241,9 +206,21 @@ class Cli():
if options is None:
options = []
+ if env is None:
+ env = os.environ.copy()
+ else:
+ orig_env = os.environ.copy()
+ orig_env.update (env)
+ env = orig_env
+
options = self.default_options + options
with ExitStack() as stack:
+
+ # Prepare a tempfile for buildstream to record machine readable error codes
+ error_codes = stack.enter_context (tempfile.NamedTemporaryFile())
+ env['BST_TEST_ERROR_CODES'] = error_codes.name
+
bst_args = ['--no-colors']
if silent:
@@ -263,21 +240,34 @@ class Cli():
bst_args += args
- if cwd is not None:
- stack.enter_context(chdir(cwd))
-
- if env is not None:
- stack.enter_context(environment(env))
+ cmd = ["bst"] + bst_args
+ process = subprocess.Popen(
+ cmd,
+ env=env,
+ cwd=cwd,
+ stdin=subprocess.DEVNULL,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE,
+ )
+ out, err = process.communicate()
+ result = Result(
+ exit_code=process.poll(),
+ output=out.decode('utf-8'),
+ stderr=err.decode('utf-8')
+ )
- # Ensure we have a working stdout - required to work
- # around a bug that appears to cause AIX to close
- # sys.__stdout__ after setup.py
- try:
- sys.__stdout__.fileno()
- except ValueError:
- sys.__stdout__ = open('/dev/stdout', 'w')
-
- result = self.invoke(bst_cli, bst_args)
+ #
+ # Collect machine readable error codes from the tmpfile
+ #
+ result_error_codes_string = error_codes.read()
+ result_error_codes = {}
+ if result_error_codes_string:
+ result_error_codes = ujson.loads (result_error_codes_string)
+ if result_error_codes:
+ result.main_error_domain = result_error_codes['main_error_domain']
+ result.main_error_reason = result_error_codes['main_error_reason']
+ result.task_error_domain = result_error_codes['task_error_domain']
+ result.task_error_reason = result_error_codes['task_error_reason']
# Some informative stdout we can observe when anything fails
if self.verbose:
@@ -289,54 +279,8 @@ class Cli():
if result.stderr:
print("Program stderr was:\n{}".format(result.stderr))
- if result.exc_info and result.exc_info[0] != SystemExit:
- traceback.print_exception(*result.exc_info)
-
return result
- def invoke(self, cli, args=None, color=False, **extra):
- exc_info = None
- exception = None
- exit_code = 0
-
- # Temporarily redirect sys.stdin to /dev/null to ensure that
- # Popen doesn't attempt to read pytest's dummy stdin.
- old_stdin = sys.stdin
- with open(os.devnull) as devnull:
- sys.stdin = devnull
- capture = MultiCapture(out=FDCapture(1), err=FDCapture(2), in_=None)
- capture.start_capturing()
-
- try:
- cli.main(args=args or (), prog_name=cli.name, **extra)
- except SystemExit as e:
- if e.code != 0:
- exception = e
-
- exc_info = sys.exc_info()
-
- exit_code = e.code
- if not isinstance(exit_code, int):
- sys.stdout.write('Program exit code was not an integer: ')
- sys.stdout.write(str(exit_code))
- sys.stdout.write('\n')
- exit_code = 1
- except Exception as e:
- exception = e
- exit_code = -1
- exc_info = sys.exc_info()
- finally:
- sys.stdout.flush()
-
- sys.stdin = old_stdin
- out, err = capture.readouterr()
- capture.stop_capturing()
-
- return Result(exit_code=exit_code,
- exception=exception,
- exc_info=exc_info,
- output=out,
- stderr=err)
# Fetch an element state by name by
# invoking bst show on the project with the CLI