[Notes] [Git][BuildStream/buildstream][lachlan/pickle-yaml-test-list-composite] 2 commits: Add yaml cache testing to yaml list composition test



Title: GitLab

Lachlan pushed to branch lachlan/pickle-yaml-test-list-composite at BuildStream / buildstream

Commits:

1 changed file:

Changes:

  • tests/yaml/yaml.py
    ... ... @@ -4,6 +4,8 @@ from collections import Mapping
    4 4
     
    
    5 5
     from buildstream import _yaml
    
    6 6
     from buildstream._exceptions import LoadError, LoadErrorReason
    
    7
    +from buildstream._context import Context
    
    8
    +from buildstream._yamlcache import YamlCache
    
    7 9
     
    
    8 10
     DATA_DIR = os.path.join(
    
    9 11
         os.path.dirname(os.path.realpath(__file__)),
    
    ... ... @@ -165,6 +167,7 @@ def test_composite_preserve_originals(datafiles):
    165 167
     #    prov_col: The expected provenance column of "mood"
    
    166 168
     #
    
    167 169
     @pytest.mark.datafiles(os.path.join(DATA_DIR))
    
    170
    +@pytest.mark.parametrize('caching', [('raw'), ('cached')])
    
    168 171
     @pytest.mark.parametrize("filename,index,length,mood,prov_file,prov_line,prov_col", [
    
    169 172
     
    
    170 173
         # Test results of compositing with the (<) prepend directive
    
    ... ... @@ -197,20 +200,41 @@ def test_composite_preserve_originals(datafiles):
    197 200
     ])
    
    198 201
     def test_list_composition(datafiles, filename,
    
    199 202
                               index, length, mood,
    
    200
    -                          prov_file, prov_line, prov_col):
    
    201
    -    base = os.path.join(datafiles.dirname, datafiles.basename, 'basics.yaml')
    
    202
    -    overlay = os.path.join(datafiles.dirname, datafiles.basename, filename)
    
    203
    +                          prov_file, prov_line, prov_col, caching):
    
    204
    +    base_file = os.path.join(datafiles.dirname, datafiles.basename, 'basics.yaml')
    
    205
    +    overlay_file = os.path.join(datafiles.dirname, datafiles.basename, filename)
    
    206
    +    # Load files
    
    207
    +    base = _yaml.load(base_file, shortname='basics.yaml')
    
    208
    +    overlay = _yaml.load(overlay_file, shortname=filename)
    
    203 209
     
    
    204
    -    base = _yaml.load(base, shortname='basics.yaml')
    
    205
    -    overlay = _yaml.load(overlay, shortname=filename)
    
    206
    -    _yaml.composite_dict(base, overlay)
    
    210
    +    if caching == 'raw':
    
    211
    +        _yaml.composite_dict(base, overlay)
    
    207 212
     
    
    208
    -    children = _yaml.node_get(base, list, 'children')
    
    209
    -    assert len(children) == length
    
    210
    -    child = children[index]
    
    213
    +        children = _yaml.node_get(base, list, 'children')
    
    214
    +        assert len(children) == length
    
    215
    +        child = children[index]
    
    216
    +
    
    217
    +        assert child['mood'] == mood
    
    218
    +        assert_provenance(prov_file, prov_line, prov_col, child, 'mood')
    
    211 219
     
    
    212
    -    assert child['mood'] == mood
    
    213
    -    assert_provenance(prov_file, prov_line, prov_col, child, 'mood')
    
    220
    +    elif caching == 'cached':
    
    221
    +        context = Context()
    
    222
    +        with YamlCache.open(context) as yc:
    
    223
    +            # Load files - use cache variants over original
    
    224
    +            base_cache = _yaml.load(base_file, shortname='basics.yaml', yaml_cache=yc)
    
    225
    +            overlay_cache = _yaml.load(overlay_file, shortname=filename, yaml_cache=yc)
    
    226
    +
    
    227
    +            _yaml.composite_dict(base_cache, overlay_cache)
    
    228
    +
    
    229
    +            children = _yaml.node_get(base_cache, list, 'children')
    
    230
    +            assert len(children) == length
    
    231
    +            child = children[index]
    
    232
    +
    
    233
    +            assert child['mood'] == mood
    
    234
    +            assert_provenance(prov_file, prov_line, prov_col, child, 'mood')
    
    235
    +
    
    236
    +    else:
    
    237
    +        assert False
    
    214 238
     
    
    215 239
     
    
    216 240
     # Test that overwriting a list with an empty list works as expected.
    
    ... ... @@ -254,6 +278,7 @@ def test_list_deletion(datafiles):
    254 278
     #    prov_col: The expected provenance column of "mood"
    
    255 279
     #
    
    256 280
     @pytest.mark.datafiles(os.path.join(DATA_DIR))
    
    281
    +@pytest.mark.parametrize('caching', [('raw'), ('cached')])
    
    257 282
     @pytest.mark.parametrize("filename1,filename2,index,length,mood,prov_file,prov_line,prov_col", [
    
    258 283
     
    
    259 284
         # Test results of compositing literal list with (>) and then (<)
    
    ... ... @@ -312,44 +337,92 @@ def test_list_deletion(datafiles):
    312 337
     ])
    
    313 338
     def test_list_composition_twice(datafiles, filename1, filename2,
    
    314 339
                                     index, length, mood,
    
    315
    -                                prov_file, prov_line, prov_col):
    
    340
    +                                prov_file, prov_line, prov_col, caching):
    
    316 341
         file_base = os.path.join(datafiles.dirname, datafiles.basename, 'basics.yaml')
    
    317 342
         file1 = os.path.join(datafiles.dirname, datafiles.basename, filename1)
    
    318 343
         file2 = os.path.join(datafiles.dirname, datafiles.basename, filename2)
    
    319 344
     
    
    320
    -    #####################
    
    321
    -    # Round 1 - Fight !
    
    322
    -    #####################
    
    323
    -    base = _yaml.load(file_base, shortname='basics.yaml')
    
    324
    -    overlay1 = _yaml.load(file1, shortname=filename1)
    
    325
    -    overlay2 = _yaml.load(file2, shortname=filename2)
    
    326
    -
    
    327
    -    _yaml.composite_dict(base, overlay1)
    
    328
    -    _yaml.composite_dict(base, overlay2)
    
    329
    -
    
    330
    -    children = _yaml.node_get(base, list, 'children')
    
    331
    -    assert len(children) == length
    
    332
    -    child = children[index]
    
    333
    -
    
    334
    -    assert child['mood'] == mood
    
    335
    -    assert_provenance(prov_file, prov_line, prov_col, child, 'mood')
    
    336
    -
    
    337
    -    #####################
    
    338
    -    # Round 2 - Fight !
    
    339
    -    #####################
    
    340
    -    base = _yaml.load(file_base, shortname='basics.yaml')
    
    341
    -    overlay1 = _yaml.load(file1, shortname=filename1)
    
    342
    -    overlay2 = _yaml.load(file2, shortname=filename2)
    
    343
    -
    
    344
    -    _yaml.composite_dict(overlay1, overlay2)
    
    345
    -    _yaml.composite_dict(base, overlay1)
    
    346
    -
    
    347
    -    children = _yaml.node_get(base, list, 'children')
    
    348
    -    assert len(children) == length
    
    349
    -    child = children[index]
    
    350
    -
    
    351
    -    assert child['mood'] == mood
    
    352
    -    assert_provenance(prov_file, prov_line, prov_col, child, 'mood')
    
    345
    +    if caching == 'raw':
    
    346
    +        #####################
    
    347
    +        # Round 1 - Fight !
    
    348
    +        #####################
    
    349
    +        base = _yaml.load(file_base, shortname='basics.yaml')
    
    350
    +        overlay1 = _yaml.load(file1, shortname=filename1)
    
    351
    +        overlay2 = _yaml.load(file2, shortname=filename2)
    
    352
    +
    
    353
    +        _yaml.composite_dict(base, overlay1)
    
    354
    +        _yaml.composite_dict(base, overlay2)
    
    355
    +
    
    356
    +        children = _yaml.node_get(base, list, 'children')
    
    357
    +        assert len(children) == length
    
    358
    +        child = children[index]
    
    359
    +
    
    360
    +        assert child['mood'] == mood
    
    361
    +        assert_provenance(prov_file, prov_line, prov_col, child, 'mood')
    
    362
    +
    
    363
    +        #####################
    
    364
    +        # Round 2 - Fight !
    
    365
    +        #####################
    
    366
    +        base = _yaml.load(file_base, shortname='basics.yaml')
    
    367
    +        overlay1 = _yaml.load(file1, shortname=filename1)
    
    368
    +        overlay2 = _yaml.load(file2, shortname=filename2)
    
    369
    +
    
    370
    +        _yaml.composite_dict(overlay1, overlay2)
    
    371
    +        _yaml.composite_dict(base, overlay1)
    
    372
    +
    
    373
    +        children = _yaml.node_get(base, list, 'children')
    
    374
    +        assert len(children) == length
    
    375
    +        child = children[index]
    
    376
    +
    
    377
    +        assert child['mood'] == mood
    
    378
    +        assert_provenance(prov_file, prov_line, prov_col, child, 'mood')
    
    379
    +    elif caching == 'cached':
    
    380
    +        context = Context()
    
    381
    +        #####################
    
    382
    +        # Round 1 - Fight !
    
    383
    +        #####################
    
    384
    +        with YamlCache.open(context) as yc:
    
    385
    +            base = _yaml.load(file_base, shortname='basics.yaml')
    
    386
    +            overlay1 = _yaml.load(file1, shortname=filename1)
    
    387
    +            overlay2 = _yaml.load(file2, shortname=filename2)
    
    388
    +
    
    389
    +            # Get cache values
    
    390
    +            base_cache = _yaml.load(file_base, shortname='basics.yaml', yaml_cache=yc)
    
    391
    +            overlay1_cache = _yaml.load(file1, shortname=filename1, yaml_cache=yc)
    
    392
    +            overlay2_cache = _yaml.load(file2, shortname=filename2, yaml_cache=yc)
    
    393
    +
    
    394
    +            _yaml.composite_dict(base_cache, overlay1_cache)
    
    395
    +            _yaml.composite_dict(base_cache, overlay2_cache)
    
    396
    +
    
    397
    +            children = _yaml.node_get(base_cache, list, 'children')
    
    398
    +            assert len(children) == length
    
    399
    +            child = children[index]
    
    400
    +
    
    401
    +            assert child['mood'] == mood
    
    402
    +            assert_provenance(prov_file, prov_line, prov_col, child, 'mood')
    
    403
    +
    
    404
    +        #####################
    
    405
    +        # Round 2 - Fight !
    
    406
    +        #####################
    
    407
    +        with YamlCache.open(context) as yc:
    
    408
    +            base = _yaml.load(file_base, shortname='basics.yaml')
    
    409
    +            overlay1 = _yaml.load(file1, shortname=filename1)
    
    410
    +            overlay2 = _yaml.load(file2, shortname=filename2)
    
    411
    +
    
    412
    +            # Get cache values
    
    413
    +            base_cache = _yaml.load(file_base, shortname='basics.yaml', yaml_cache=yc)
    
    414
    +            overlay1_cache = _yaml.load(file1, shortname=filename1, yaml_cache=yc)
    
    415
    +            overlay2_cache = _yaml.load(file2, shortname=filename2, yaml_cache=yc)
    
    416
    +
    
    417
    +            _yaml.composite_dict(overlay1_cache, overlay2_cache)
    
    418
    +            _yaml.composite_dict(base_cache, overlay1_cache)
    
    419
    +
    
    420
    +            children = _yaml.node_get(base_cache, list, 'children')
    
    421
    +            assert len(children) == length
    
    422
    +            child = children[index]
    
    423
    +
    
    424
    +            assert child['mood'] == mood
    
    425
    +            assert_provenance(prov_file, prov_line, prov_col, child, 'mood')
    
    353 426
     
    
    354 427
     
    
    355 428
     @pytest.mark.datafiles(os.path.join(DATA_DIR))
    



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