[Notes] [Git][BuildStream/buildstream][master] 3 commits: tests/loader/junctions.py: Use Result checking APIs instead of manually



Title: GitLab

Tristan Van Berkom pushed to branch master at BuildStream / buildstream

Commits:

2 changed files:

Changes:

  • tests/loader/junctions.py
    ... ... @@ -3,7 +3,7 @@ import pytest
    3 3
     import shutil
    
    4 4
     
    
    5 5
     from buildstream import _yaml, ElementError
    
    6
    -from buildstream._exceptions import LoadError, LoadErrorReason
    
    6
    +from buildstream._exceptions import ErrorDomain, LoadErrorReason
    
    7 7
     from tests.testutils import cli, create_repo
    
    8 8
     from tests.testutils.site import HAVE_GIT
    
    9 9
     
    
    ... ... @@ -38,9 +38,9 @@ def test_simple_build(cli, tmpdir, datafiles):
    38 38
     
    
    39 39
         # Build, checkout
    
    40 40
         result = cli.run(project=project, args=['build', 'target.bst'])
    
    41
    -    assert result.exit_code == 0
    
    41
    +    result.assert_success()
    
    42 42
         result = cli.run(project=project, args=['checkout', 'target.bst', checkoutdir])
    
    43
    -    assert result.exit_code == 0
    
    43
    +    result.assert_success()
    
    44 44
     
    
    45 45
         # Check that the checkout contains the expected files from both projects
    
    46 46
         assert(os.path.exists(os.path.join(checkoutdir, 'base.txt')))
    
    ... ... @@ -54,7 +54,7 @@ def test_build_of_same_junction_used_twice(cli, tmpdir, datafiles):
    54 54
         # Check we can build a project that contains the same junction
    
    55 55
         # that is used twice, but named differently
    
    56 56
         result = cli.run(project=project, args=['build', 'target.bst'])
    
    57
    -    assert result.exit_code == 0
    
    57
    +    result.assert_success()
    
    58 58
     
    
    59 59
     
    
    60 60
     @pytest.mark.datafiles(DATA_DIR)
    
    ... ... @@ -69,9 +69,9 @@ def test_nested_simple(cli, tmpdir, datafiles):
    69 69
     
    
    70 70
         # Build, checkout
    
    71 71
         result = cli.run(project=project, args=['build', 'target.bst'])
    
    72
    -    assert result.exit_code == 0
    
    72
    +    result.assert_success()
    
    73 73
         result = cli.run(project=project, args=['checkout', 'target.bst', checkoutdir])
    
    74
    -    assert result.exit_code == 0
    
    74
    +    result.assert_success()
    
    75 75
     
    
    76 76
         # Check that the checkout contains the expected files from all subprojects
    
    77 77
         assert(os.path.exists(os.path.join(checkoutdir, 'base.txt')))
    
    ... ... @@ -93,9 +93,9 @@ def test_nested_double(cli, tmpdir, datafiles):
    93 93
     
    
    94 94
         # Build, checkout
    
    95 95
         result = cli.run(project=project, args=['build', 'target.bst'])
    
    96
    -    assert result.exit_code == 0
    
    96
    +    result.assert_success()
    
    97 97
         result = cli.run(project=project, args=['checkout', 'target.bst', checkoutdir])
    
    98
    -    assert result.exit_code == 0
    
    98
    +    result.assert_success()
    
    99 99
     
    
    100 100
         # Check that the checkout contains the expected files from all subprojects
    
    101 101
         assert(os.path.exists(os.path.join(checkoutdir, 'base.txt')))
    
    ... ... @@ -115,45 +115,46 @@ def test_nested_conflict(cli, datafiles):
    115 115
         copy_subprojects(project, datafiles, ['foo', 'bar'])
    
    116 116
     
    
    117 117
         result = cli.run(project=project, args=['build', 'target.bst'])
    
    118
    -    assert result.exit_code != 0
    
    119
    -    assert result.exception
    
    120
    -    assert isinstance(result.exception, LoadError)
    
    121
    -    assert result.exception.reason == LoadErrorReason.CONFLICTING_JUNCTION
    
    118
    +    result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.CONFLICTING_JUNCTION)
    
    122 119
     
    
    123 120
     
    
    121
    +# Test that we error correctly when the junction element itself is missing
    
    124 122
     @pytest.mark.datafiles(DATA_DIR)
    
    125
    -def test_invalid_missing(cli, datafiles):
    
    123
    +def test_missing_junction(cli, datafiles):
    
    126 124
         project = os.path.join(str(datafiles), 'invalid')
    
    127 125
     
    
    128 126
         result = cli.run(project=project, args=['build', 'missing.bst'])
    
    129
    -    assert result.exit_code != 0
    
    130
    -    assert result.exception
    
    131
    -    assert isinstance(result.exception, LoadError)
    
    132
    -    assert result.exception.reason == LoadErrorReason.MISSING_FILE
    
    127
    +    result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.MISSING_FILE)
    
    133 128
     
    
    134 129
     
    
    130
    +# Test that we error correctly when an element is not found in the subproject
    
    131
    +@pytest.mark.datafiles(DATA_DIR)
    
    132
    +def test_missing_subproject_element(cli, datafiles):
    
    133
    +    project = os.path.join(str(datafiles), 'invalid')
    
    134
    +    copy_subprojects(project, datafiles, ['base'])
    
    135
    +
    
    136
    +    result = cli.run(project=project, args=['build', 'missing-element.bst'])
    
    137
    +    result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.MISSING_FILE)
    
    138
    +
    
    139
    +
    
    140
    +# Test that we error correctly when a junction itself has dependencies
    
    135 141
     @pytest.mark.datafiles(DATA_DIR)
    
    136 142
     def test_invalid_with_deps(cli, datafiles):
    
    137 143
         project = os.path.join(str(datafiles), 'invalid')
    
    138 144
         copy_subprojects(project, datafiles, ['base'])
    
    139 145
     
    
    140 146
         result = cli.run(project=project, args=['build', 'junction-with-deps.bst'])
    
    141
    -    assert result.exit_code != 0
    
    142
    -    assert result.exception
    
    143
    -    assert isinstance(result.exception, ElementError)
    
    144
    -    assert result.exception.reason == 'element-forbidden-depends'
    
    147
    +    result.assert_main_error(ErrorDomain.ELEMENT, 'element-forbidden-depends')
    
    145 148
     
    
    146 149
     
    
    150
    +# Test that we error correctly when a junction is directly depended on
    
    147 151
     @pytest.mark.datafiles(DATA_DIR)
    
    148 152
     def test_invalid_junction_dep(cli, datafiles):
    
    149 153
         project = os.path.join(str(datafiles), 'invalid')
    
    150 154
         copy_subprojects(project, datafiles, ['base'])
    
    151 155
     
    
    152 156
         result = cli.run(project=project, args=['build', 'junction-dep.bst'])
    
    153
    -    assert result.exit_code != 0
    
    154
    -    assert result.exception
    
    155
    -    assert isinstance(result.exception, LoadError)
    
    156
    -    assert result.exception.reason == LoadErrorReason.INVALID_DATA
    
    157
    +    result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.INVALID_DATA)
    
    157 158
     
    
    158 159
     
    
    159 160
     @pytest.mark.datafiles(DATA_DIR)
    
    ... ... @@ -165,9 +166,9 @@ def test_options_default(cli, tmpdir, datafiles):
    165 166
     
    
    166 167
         # Build, checkout
    
    167 168
         result = cli.run(project=project, args=['build', 'target.bst'])
    
    168
    -    assert result.exit_code == 0
    
    169
    +    result.assert_success()
    
    169 170
         result = cli.run(project=project, args=['checkout', 'target.bst', checkoutdir])
    
    170
    -    assert result.exit_code == 0
    
    171
    +    result.assert_success()
    
    171 172
     
    
    172 173
         assert(os.path.exists(os.path.join(checkoutdir, 'pony.txt')))
    
    173 174
         assert(not os.path.exists(os.path.join(checkoutdir, 'horsy.txt')))
    
    ... ... @@ -182,9 +183,9 @@ def test_options(cli, tmpdir, datafiles):
    182 183
     
    
    183 184
         # Build, checkout
    
    184 185
         result = cli.run(project=project, args=['build', 'target.bst'])
    
    185
    -    assert result.exit_code == 0
    
    186
    +    result.assert_success()
    
    186 187
         result = cli.run(project=project, args=['checkout', 'target.bst', checkoutdir])
    
    187
    -    assert result.exit_code == 0
    
    188
    +    result.assert_success()
    
    188 189
     
    
    189 190
         assert(not os.path.exists(os.path.join(checkoutdir, 'pony.txt')))
    
    190 191
         assert(os.path.exists(os.path.join(checkoutdir, 'horsy.txt')))
    
    ... ... @@ -199,9 +200,9 @@ def test_options_inherit(cli, tmpdir, datafiles):
    199 200
     
    
    200 201
         # Build, checkout
    
    201 202
         result = cli.run(project=project, args=['build', 'target.bst'])
    
    202
    -    assert result.exit_code == 0
    
    203
    +    result.assert_success()
    
    203 204
         result = cli.run(project=project, args=['checkout', 'target.bst', checkoutdir])
    
    204
    -    assert result.exit_code == 0
    
    205
    +    result.assert_success()
    
    205 206
     
    
    206 207
         assert(not os.path.exists(os.path.join(checkoutdir, 'pony.txt')))
    
    207 208
         assert(os.path.exists(os.path.join(checkoutdir, 'horsy.txt')))
    
    ... ... @@ -228,14 +229,11 @@ def test_git_show(cli, tmpdir, datafiles):
    228 229
     
    
    229 230
         # Verify that bst show does not implicitly fetch subproject
    
    230 231
         result = cli.run(project=project, args=['show', 'target.bst'])
    
    231
    -    assert result.exit_code != 0
    
    232
    -    assert result.exception
    
    233
    -    assert isinstance(result.exception, LoadError)
    
    234
    -    assert result.exception.reason == LoadErrorReason.SUBPROJECT_FETCH_NEEDED
    
    232
    +    result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.SUBPROJECT_FETCH_NEEDED)
    
    235 233
     
    
    236 234
         # Explicitly fetch subproject
    
    237 235
         result = cli.run(project=project, args=['source', 'fetch', 'base.bst'])
    
    238
    -    assert result.exit_code == 0
    
    236
    +    result.assert_success()
    
    239 237
     
    
    240 238
         # Check that bst show succeeds now and the pipeline includes the subproject element
    
    241 239
         element_list = cli.get_pipeline(project, ['target.bst'])
    
    ... ... @@ -263,9 +261,9 @@ def test_git_build(cli, tmpdir, datafiles):
    263 261
     
    
    264 262
         # Build (with implicit fetch of subproject), checkout
    
    265 263
         result = cli.run(project=project, args=['build', 'target.bst'])
    
    266
    -    assert result.exit_code == 0
    
    264
    +    result.assert_success()
    
    267 265
         result = cli.run(project=project, args=['checkout', 'target.bst', checkoutdir])
    
    268
    -    assert result.exit_code == 0
    
    266
    +    result.assert_success()
    
    269 267
     
    
    270 268
         # Check that the checkout contains the expected files from both projects
    
    271 269
         assert(os.path.exists(os.path.join(checkoutdir, 'base.txt')))
    
    ... ... @@ -304,9 +302,9 @@ def test_build_git_cross_junction_names(cli, tmpdir, datafiles):
    304 302
     
    
    305 303
         # Build (with implicit fetch of subproject), checkout
    
    306 304
         result = cli.run(project=project, args=['build', 'base.bst:target.bst'])
    
    307
    -    assert result.exit_code == 0
    
    305
    +    result.assert_success()
    
    308 306
         result = cli.run(project=project, args=['checkout', 'base.bst:target.bst', checkoutdir])
    
    309
    -    assert result.exit_code == 0
    
    307
    +    result.assert_success()
    
    310 308
     
    
    311 309
         # Check that the checkout contains the expected files from both projects
    
    312 310
         assert(os.path.exists(os.path.join(checkoutdir, 'base.txt')))

  • tests/loader/junctions/invalid/missing-element.bst
    1
    +# This refers to the `foo.bst` element through
    
    2
    +# the `base.bst` junction. The `base.bst` junction
    
    3
    +# exists but the `foo.bst` element does not exist
    
    4
    +# in the subproject.
    
    5
    +#
    
    6
    +kind: stack
    
    7
    +depends:
    
    8
    +- junction: base.bst
    
    9
    +  filename: foo.bst



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