[Notes] [Git][BuildStream/buildstream][tlater/message-lines] 6 commits: tests/testutils/python_repo.py: Use subprocess to run sdist



Title: GitLab

Tristan Van Berkom pushed to branch tlater/message-lines at BuildStream / buildstream

Commits:

5 changed files:

Changes:

  • buildstream/_frontend/widget.py
    ... ... @@ -647,8 +647,9 @@ class LogLine(Widget):
    647 647
                 abbrev = False
    
    648 648
                 if message.message_type not in ERROR_MESSAGES \
    
    649 649
                    and not frontend_message and n_lines > self._message_lines:
    
    650
    -                abbrev = True
    
    651 650
                     lines = lines[0:self._message_lines]
    
    651
    +                if self._message_lines > 0:
    
    652
    +                    abbrev = True
    
    652 653
                 else:
    
    653 654
                     lines[n_lines - 1] = lines[n_lines - 1].rstrip('\n')
    
    654 655
     
    
    ... ... @@ -674,7 +675,7 @@ class LogLine(Widget):
    674 675
                 if self.context is not None and not self.context.log_verbose:
    
    675 676
                     text += self._indent + self._err_profile.fmt("Log file: ")
    
    676 677
                     text += self._indent + self._logfile_widget.render(message) + '\n'
    
    677
    -            else:
    
    678
    +            elif self._log_lines > 0:
    
    678 679
                     text += self._indent + self._err_profile.fmt("Printing the last {} lines from log file:"
    
    679 680
                                                                  .format(self._log_lines)) + '\n'
    
    680 681
                     text += self._indent + self._logfile_widget.render(message, abbrev=False) + '\n'
    

  • buildstream/plugins/elements/import.py
    ... ... @@ -28,17 +28,14 @@ some configuration data.
    28 28
     The empty configuration is as such:
    
    29 29
       .. literalinclude:: ../../../buildstream/plugins/elements/import.yaml
    
    30 30
          :language: yaml
    
    31
    -
    
    32
    -See :ref:`built-in functionality documentation <core_buildelement_builtins>` for
    
    33
    -details on common configuration options for build elements.
    
    34 31
     """
    
    35 32
     
    
    36 33
     import os
    
    37
    -from buildstream import Element, BuildElement, ElementError
    
    34
    +from buildstream import Element, ElementError
    
    38 35
     
    
    39 36
     
    
    40 37
     # Element implementation for the 'import' kind.
    
    41
    -class ImportElement(BuildElement):
    
    38
    +class ImportElement(Element):
    
    42 39
         # pylint: disable=attribute-defined-outside-init
    
    43 40
     
    
    44 41
         # This plugin has been modified to avoid the use of Sandbox.get_directory
    
    ... ... @@ -93,10 +90,6 @@ class ImportElement(BuildElement):
    93 90
             # And we're done
    
    94 91
             return '/output'
    
    95 92
     
    
    96
    -    def prepare(self, sandbox):
    
    97
    -        # We inherit a non-default prepare from BuildElement.
    
    98
    -        Element.prepare(self, sandbox)
    
    99
    -
    
    100 93
         def generate_script(self):
    
    101 94
             build_root = self.get_variable('build-root')
    
    102 95
             install_root = self.get_variable('install-root')
    

  • tests/integration/messages.py
    1
    +#
    
    2
    +#  Copyright (C) 2018 Codethink Limited
    
    3
    +#
    
    4
    +#  This program is free software; you can redistribute it and/or
    
    5
    +#  modify it under the terms of the GNU Lesser General Public
    
    6
    +#  License as published by the Free Software Foundation; either
    
    7
    +#  version 2 of the License, or (at your option) any later version.
    
    8
    +#
    
    9
    +#  This library is distributed in the hope that it will be useful,
    
    10
    +#  but WITHOUT ANY WARRANTY; without even the implied warranty of
    
    11
    +#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    
    12
    +#  Lesser General Public License for more details.
    
    13
    +#
    
    14
    +#  You should have received a copy of the GNU Lesser General Public
    
    15
    +#  License along with this library. If not, see <http://www.gnu.org/licenses/>.
    
    16
    +#
    
    17
    +#  Authors: Tristan Maat <tristan maat codethink co uk>
    
    18
    +#
    
    19
    +
    
    20
    +import os
    
    21
    +import pytest
    
    22
    +
    
    23
    +from buildstream import _yaml
    
    24
    +from buildstream._exceptions import ErrorDomain
    
    25
    +
    
    26
    +from tests.testutils import cli_integration as cli
    
    27
    +from tests.testutils.site import HAVE_BWRAP, IS_LINUX
    
    28
    +
    
    29
    +
    
    30
    +pytestmark = pytest.mark.integration
    
    31
    +
    
    32
    +
    
    33
    +# Project directory
    
    34
    +DATA_DIR = os.path.join(
    
    35
    +    os.path.dirname(os.path.realpath(__file__)),
    
    36
    +    "project",
    
    37
    +)
    
    38
    +
    
    39
    +
    
    40
    +@pytest.mark.integration
    
    41
    +@pytest.mark.datafiles(DATA_DIR)
    
    42
    +@pytest.mark.skipif(IS_LINUX and not HAVE_BWRAP, reason='Only available with bubblewrap on Linux')
    
    43
    +def test_disable_message_lines(cli, tmpdir, datafiles):
    
    44
    +    project = os.path.join(datafiles.dirname, datafiles.basename)
    
    45
    +    element_path = os.path.join(project, 'elements')
    
    46
    +    element_name = 'message.bst'
    
    47
    +
    
    48
    +    element = {
    
    49
    +        'kind': 'manual',
    
    50
    +        'depends': [{
    
    51
    +            'filename': 'base.bst'
    
    52
    +        }],
    
    53
    +        'config': {
    
    54
    +            'build-commands':
    
    55
    +            ['echo "Silly message"'],
    
    56
    +            'strip-commands': []
    
    57
    +        }
    
    58
    +    }
    
    59
    +
    
    60
    +    os.makedirs(os.path.dirname(os.path.join(element_path, element_name)), exist_ok=True)
    
    61
    +    _yaml.dump(element, os.path.join(element_path, element_name))
    
    62
    +
    
    63
    +    # First we check that we get the "Silly message"
    
    64
    +    result = cli.run(project=project, args=["build", element_name])
    
    65
    +    result.assert_success()
    
    66
    +    assert 'echo "Silly message"' in result.stderr
    
    67
    +
    
    68
    +    # Let's now build it again, but with --message-lines 0
    
    69
    +    cli.remove_artifact_from_cache(project, element_name)
    
    70
    +    result = cli.run(project=project, args=["--message-lines", "0",
    
    71
    +                                            "build", element_name])
    
    72
    +    result.assert_success()
    
    73
    +    assert "Message contains " not in result.stderr
    
    74
    +
    
    75
    +
    
    76
    +@pytest.mark.integration
    
    77
    +@pytest.mark.datafiles(DATA_DIR)
    
    78
    +@pytest.mark.skipif(IS_LINUX and not HAVE_BWRAP, reason='Only available with bubblewrap on Linux')
    
    79
    +def test_disable_error_lines(cli, tmpdir, datafiles):
    
    80
    +    project = os.path.join(datafiles.dirname, datafiles.basename)
    
    81
    +    element_path = os.path.join(project, 'elements')
    
    82
    +    element_name = 'message.bst'
    
    83
    +
    
    84
    +    element = {
    
    85
    +        'kind': 'manual',
    
    86
    +        'depends': [{
    
    87
    +            'filename': 'base.bst'
    
    88
    +        }],
    
    89
    +        'config': {
    
    90
    +            'build-commands':
    
    91
    +            ['This is a syntax error > >'],
    
    92
    +            'strip-commands': []
    
    93
    +        }
    
    94
    +    }
    
    95
    +
    
    96
    +    os.makedirs(os.path.dirname(os.path.join(element_path, element_name)), exist_ok=True)
    
    97
    +    _yaml.dump(element, os.path.join(element_path, element_name))
    
    98
    +
    
    99
    +    # First we check that we get the syntax error
    
    100
    +    result = cli.run(project=project, args=["--error-lines", "0",
    
    101
    +                                            "build", element_name])
    
    102
    +    result.assert_main_error(ErrorDomain.STREAM, None)
    
    103
    +    assert "This is a syntax error" in result.stderr
    
    104
    +
    
    105
    +    # Let's now build it again, but with --error-lines 0
    
    106
    +    cli.remove_artifact_from_cache(project, element_name)
    
    107
    +    result = cli.run(project=project, args=["--error-lines", "0",
    
    108
    +                                            "build", element_name])
    
    109
    +    result.assert_main_error(ErrorDomain.STREAM, None)
    
    110
    +    assert "Printing the last" not in result.stderr

  • tests/testutils/python_repo.py
    1
    -from setuptools.sandbox import run_setup
    
    2 1
     import os
    
    3 2
     import pytest
    
    4 3
     import re
    
    5 4
     import shutil
    
    5
    +import subprocess
    
    6 6
     
    
    7 7
     
    
    8 8
     SETUP_TEMPLATE = '''\
    
    ... ... @@ -88,7 +88,9 @@ def generate_pip_package(tmpdir, pypi, name, version='0.1'):
    88 88
             f.write(INIT_TEMPLATE.format(name=name))
    
    89 89
         os.chmod(main_file, 0o644)
    
    90 90
     
    
    91
    -    run_setup(setup_file, ['sdist'])
    
    91
    +    # Run sdist with a fresh process
    
    92
    +    p = subprocess.run(['python3', 'setup.py', 'sdist'], cwd=tmpdir)
    
    93
    +    assert p.returncode == 0
    
    92 94
     
    
    93 95
         # create directory for this package in pypi resulting in a directory
    
    94 96
         # tree resembling the following structure:
    

  • tests/testutils/runcli.py
    ... ... @@ -245,8 +245,14 @@ class Cli():
    245 245
     
    
    246 246
         def remove_artifact_from_cache(self, project, element_name,
    
    247 247
                                        *, cache_dir=None):
    
    248
    +        # Read configuration to figure out where artifacts are stored
    
    248 249
             if not cache_dir:
    
    249
    -            cache_dir = os.path.join(project, 'cache', 'artifacts')
    
    250
    +            default = os.path.join(project, 'cache', 'artifacts')
    
    251
    +
    
    252
    +            if self.config is not None:
    
    253
    +                cache_dir = self.config.get('artifactdir', default)
    
    254
    +            else:
    
    255
    +                cache_dir = default
    
    250 256
     
    
    251 257
             cache_dir = os.path.join(cache_dir, 'cas', 'refs', 'heads')
    
    252 258
     
    



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