[Notes] [Git][BuildStream/buildstream][lachlan/pickle-yaml-test-list-composite] 2 commits: Add yaml cache test 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,9 @@ from collections import Mapping
    4 4
     
    
    5 5
     from buildstream import _yaml
    
    6 6
     from buildstream._exceptions import LoadError, LoadErrorReason
    
    7
    +from tests.frontend.yamlcache import yamlcache_key
    
    8
    +from buildstream._context import Context
    
    9
    +from buildstream._yamlcache import YamlCache
    
    7 10
     
    
    8 11
     DATA_DIR = os.path.join(
    
    9 12
         os.path.dirname(os.path.realpath(__file__)),
    
    ... ... @@ -165,6 +168,7 @@ def test_composite_preserve_originals(datafiles):
    165 168
     #    prov_col: The expected provenance column of "mood"
    
    166 169
     #
    
    167 170
     @pytest.mark.datafiles(os.path.join(DATA_DIR))
    
    171
    +@pytest.mark.parametrize('caching', [('raw'), ('cached')])
    
    168 172
     @pytest.mark.parametrize("filename,index,length,mood,prov_file,prov_line,prov_col", [
    
    169 173
     
    
    170 174
         # Test results of compositing with the (<) prepend directive
    
    ... ... @@ -197,20 +201,54 @@ def test_composite_preserve_originals(datafiles):
    197 201
     ])
    
    198 202
     def test_list_composition(datafiles, filename,
    
    199 203
                               index, length, mood,
    
    200
    -                          prov_file, prov_line, prov_col):
    
    204
    +                          prov_file, prov_line, prov_col, caching):
    
    205
    +
    
    201 206
         base = os.path.join(datafiles.dirname, datafiles.basename, 'basics.yaml')
    
    202 207
         overlay = os.path.join(datafiles.dirname, datafiles.basename, filename)
    
    203 208
     
    
    204
    -    base = _yaml.load(base, shortname='basics.yaml')
    
    205
    -    overlay = _yaml.load(overlay, shortname=filename)
    
    206
    -    _yaml.composite_dict(base, overlay)
    
    209
    +    if caching == 'raw':
    
    210
    +        base = _yaml.load(base, shortname='basics.yaml')
    
    211
    +        overlay = _yaml.load(overlay, shortname=filename)
    
    212
    +        _yaml.composite_dict(base, overlay)
    
    207 213
     
    
    208
    -    children = _yaml.node_get(base, list, 'children')
    
    209
    -    assert len(children) == length
    
    210
    -    child = children[index]
    
    214
    +        children = _yaml.node_get(base, list, 'children')
    
    215
    +        assert len(children) == length
    
    216
    +        child = children[index]
    
    217
    +
    
    218
    +        assert child['mood'] == mood
    
    219
    +        assert_provenance(prov_file, prov_line, prov_col, child, 'mood')
    
    211 220
     
    
    212
    -    assert child['mood'] == mood
    
    213
    -    assert_provenance(prov_file, prov_line, prov_col, child, 'mood')
    
    221
    +    elif caching == 'cached':
    
    222
    +        context = Context()
    
    223
    +        with YamlCache.open(context) as yc:
    
    224
    +            # Load files - original and put key and contents in cache
    
    225
    +            base_contents = _yaml.load(base, shortname='basics.yaml', copy_tree=False, project=None)
    
    226
    +            key = yamlcache_key(yc, base)
    
    227
    +            yc.put("", base, key, base_contents)
    
    228
    +            # Check that file is cached
    
    229
    +            assert yc.is_cached("", filepath=base)
    
    230
    +
    
    231
    +            overlay_contents = _yaml.load(overlay, shortname=filename, copy_tree=False, project=None)
    
    232
    +            key = yamlcache_key(yc, overlay)
    
    233
    +            yc.put("", overlay, key, overlay_contents)
    
    234
    +            # Check that file is cached
    
    235
    +            assert yc.is_cached("", filepath=overlay)
    
    236
    +
    
    237
    +            # Load files - cache variants
    
    238
    +            base_cache = _yaml.load(base, shortname='basics.yaml', yaml_cache=yc)
    
    239
    +            overlay_cache = _yaml.load(overlay, shortname=filename, yaml_cache=yc)
    
    240
    +
    
    241
    +            _yaml.composite_dict(base_cache, overlay_cache)
    
    242
    +
    
    243
    +            children = _yaml.node_get(base_cache, list, 'children')
    
    244
    +            assert len(children) == length
    
    245
    +            child = children[index]
    
    246
    +
    
    247
    +            assert child['mood'] == mood
    
    248
    +            assert_provenance(prov_file, prov_line, prov_col, child, 'mood')
    
    249
    +
    
    250
    +    else:
    
    251
    +        assert False
    
    214 252
     
    
    215 253
     
    
    216 254
     # Test that overwriting a list with an empty list works as expected.
    
    ... ... @@ -254,6 +292,7 @@ def test_list_deletion(datafiles):
    254 292
     #    prov_col: The expected provenance column of "mood"
    
    255 293
     #
    
    256 294
     @pytest.mark.datafiles(os.path.join(DATA_DIR))
    
    295
    +@pytest.mark.parametrize('caching', [('raw'), ('cached')])
    
    257 296
     @pytest.mark.parametrize("filename1,filename2,index,length,mood,prov_file,prov_line,prov_col", [
    
    258 297
     
    
    259 298
         # Test results of compositing literal list with (>) and then (<)
    
    ... ... @@ -312,44 +351,124 @@ def test_list_deletion(datafiles):
    312 351
     ])
    
    313 352
     def test_list_composition_twice(datafiles, filename1, filename2,
    
    314 353
                                     index, length, mood,
    
    315
    -                                prov_file, prov_line, prov_col):
    
    354
    +                                prov_file, prov_line, prov_col, caching):
    
    316 355
         file_base = os.path.join(datafiles.dirname, datafiles.basename, 'basics.yaml')
    
    317 356
         file1 = os.path.join(datafiles.dirname, datafiles.basename, filename1)
    
    318 357
         file2 = os.path.join(datafiles.dirname, datafiles.basename, filename2)
    
    319 358
     
    
    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]
    
    359
    +    if caching == 'raw':
    
    360
    +        #####################
    
    361
    +        # Round 1 - Fight !
    
    362
    +        #####################
    
    363
    +        base = _yaml.load(file_base, shortname='basics.yaml')
    
    364
    +        overlay1 = _yaml.load(file1, shortname=filename1)
    
    365
    +        overlay2 = _yaml.load(file2, shortname=filename2)
    
    366
    +
    
    367
    +        _yaml.composite_dict(base, overlay1)
    
    368
    +        _yaml.composite_dict(base, overlay2)
    
    369
    +
    
    370
    +        children = _yaml.node_get(base, list, 'children')
    
    371
    +        assert len(children) == length
    
    372
    +        child = children[index]
    
    373
    +
    
    374
    +        assert child['mood'] == mood
    
    375
    +        assert_provenance(prov_file, prov_line, prov_col, child, 'mood')
    
    376
    +
    
    377
    +        #####################
    
    378
    +        # Round 2 - Fight !
    
    379
    +        #####################
    
    380
    +        base = _yaml.load(file_base, shortname='basics.yaml')
    
    381
    +        overlay1 = _yaml.load(file1, shortname=filename1)
    
    382
    +        overlay2 = _yaml.load(file2, shortname=filename2)
    
    383
    +
    
    384
    +        _yaml.composite_dict(overlay1, overlay2)
    
    385
    +        _yaml.composite_dict(base, overlay1)
    
    386
    +
    
    387
    +        children = _yaml.node_get(base, list, 'children')
    
    388
    +        assert len(children) == length
    
    389
    +        child = children[index]
    
    390
    +
    
    391
    +        assert child['mood'] == mood
    
    392
    +        assert_provenance(prov_file, prov_line, prov_col, child, 'mood')
    
    393
    +    elif caching == 'cached':
    
    394
    +        context = Context()
    
    395
    +        #####################
    
    396
    +        # Round 1 - Fight !
    
    397
    +        #####################
    
    398
    +        with YamlCache.open(context) as yc:
    
    399
    +            base = _yaml.load(file_base, shortname='basics.yaml')
    
    400
    +
    
    401
    +            key = yamlcache_key(yc, file_base)
    
    402
    +            yc.put("", file_base, key, base)
    
    403
    +            # Check that file is cached
    
    404
    +            assert yc.is_cached("", filepath=file_base)
    
    405
    +
    
    406
    +            overlay1 = _yaml.load(file1, shortname=filename1)
    
    407
    +
    
    408
    +            key = yamlcache_key(yc, file1)
    
    409
    +            yc.put("", file1, key, overlay1)
    
    410
    +            # Check that file is cached
    
    411
    +            assert yc.is_cached("", filepath=file1)
    
    412
    +
    
    413
    +            overlay2 = _yaml.load(file2, shortname=filename2)
    
    414
    +
    
    415
    +            key = yamlcache_key(yc, file2)
    
    416
    +            yc.put("", file2, key, overlay2)
    
    417
    +            # Check that file is cached
    
    418
    +            assert yc.is_cached("", filepath=file2)
    
    419
    +
    
    420
    +            base_cache = _yaml.load(file_base, shortname='basics.yaml', yaml_cache=yc)
    
    421
    +            overlay1_cache = _yaml.load(file1, shortname=filename1, yaml_cache=yc)
    
    422
    +            overlay2_cache = _yaml.load(file2, shortname=filename2, yaml_cache=yc)
    
    423
    +
    
    424
    +            _yaml.composite_dict(base_cache, overlay1_cache)
    
    425
    +            _yaml.composite_dict(base_cache, overlay2_cache)
    
    426
    +
    
    427
    +            children = _yaml.node_get(base_cache, list, 'children')
    
    428
    +            assert len(children) == length
    
    429
    +            child = children[index]
    
    430
    +
    
    431
    +            assert child['mood'] == mood
    
    432
    +            assert_provenance(prov_file, prov_line, prov_col, child, 'mood')
    
    433
    +
    
    434
    +        #####################
    
    435
    +        # Round 2 - Fight !
    
    436
    +        #####################
    
    437
    +        with YamlCache.open(context) as yc:
    
    438
    +            base = _yaml.load(file_base, shortname='basics.yaml')
    
    439
    +
    
    440
    +            key = yamlcache_key(yc, file_base)
    
    441
    +            yc.put("", file_base, key, base)
    
    442
    +            # Check that file is cached
    
    443
    +            assert yc.is_cached("", filepath=file_base)
    
    444
    +
    
    445
    +            overlay1 = _yaml.load(file1, shortname=filename1)
    
    446
    +
    
    447
    +            key = yamlcache_key(yc, file1)
    
    448
    +            yc.put("", file1, key, overlay1)
    
    449
    +            # Check that file is cached
    
    450
    +            assert yc.is_cached("", filepath=file1)
    
    451
    +
    
    452
    +            overlay2 = _yaml.load(file2, shortname=filename2)
    
    453
    +
    
    454
    +            key = yamlcache_key(yc, file2)
    
    455
    +            yc.put("", file2, key, overlay2)
    
    456
    +            # Check that file is cached
    
    457
    +            assert yc.is_cached("", filepath=file2)
    
    458
    +
    
    459
    +            base_cache = _yaml.load(file_base, shortname='basics.yaml', yaml_cache=yc)
    
    460
    +            overlay1_cache = _yaml.load(file1, shortname=filename1, yaml_cache=yc)
    
    461
    +            overlay2_cache = _yaml.load(file2, shortname=filename2, yaml_cache=yc)
    
    462
    +
    
    463
    +            _yaml.composite_dict(overlay1_cache, overlay2_cache)
    
    464
    +            _yaml.composite_dict(base_cache, overlay1_cache)
    
    333 465
     
    
    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]
    
    466
    +            children = _yaml.node_get(base_cache, list, 'children')
    
    467
    +            assert len(children) == length
    
    468
    +            child = children[index]
    
    350 469
     
    
    351
    -    assert child['mood'] == mood
    
    352
    -    assert_provenance(prov_file, prov_line, prov_col, child, 'mood')
    
    470
    +            assert child['mood'] == mood
    
    471
    +            assert_provenance(prov_file, prov_line, prov_col, child, 'mood')
    
    353 472
     
    
    354 473
     
    
    355 474
     @pytest.mark.datafiles(os.path.join(DATA_DIR))
    



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