Example #1
0
def test_exception_no_model_to_load(images_dir):
    '''
    raises exception since the saveloc_ from where to load the model is empty.
    There are no Model.txt files that can be loaded
    '''
    try:
        os.remove(os.path.join(saveloc_, 'Model.json'))
    except:
        pass
    with raises(ValueError):
        load(os.path.join(saveloc_))
Example #2
0
def test_save_load_midrun_no_movers(images_dir, uncertain):
    """
    create model, save it after 1step, then load and check equality of original
    model and persisted model
    Remove all movers and ensure it still works as expected
    """

    model = make_model(images_dir, uncertain)

    for mover in model.movers:
        del model.movers[mover.id]

    model.step()
    print 'saving scenario ..'
    model.save(saveloc_)

    print 'loading scenario ..'
    model2 = load(saveloc_)

    for sc in zip(model.spills.items(), model2.spills.items()):
        # need to change both atol since reading persisted data
        sc[0]._array_allclose_atol = 1e-5
        sc[1]._array_allclose_atol = 1e-5

    assert model.spills == model2.spills
    assert model == model2
Example #3
0
def test_save_load_model(images_dir):
    '''
    create a model, save it, then load it back up and check it is equal to
    original model
    '''
    model = make_model(images_dir)
    model.save(saveloc_)
    model2 = load(saveloc_)
    assert model == model2
Example #4
0
def test_save_load_scenario(images_dir, uncertain):
    model = make_model(images_dir, uncertain)

    print 'saving scenario ..'
    model.save(saveloc_)

    print 'loading scenario ..'
    model2 = load(saveloc_)

    assert model == model2
Example #5
0
def test_load_midrun_ne_rewound_model(images_dir, uncertain):
    """
    Load the same model that was persisted previously after 1 step
    This time rewind the original model and test that the two are not equal.
    The data arrays in the spill container must not match
    """

    # data arrays in model.spills no longer equal

    model = make_model(images_dir, uncertain)

    model.step()
    print 'saving scenario ..'
    model.save(saveloc_)

    model.rewind()
    model2 = load(saveloc_)

    assert model.spills != model2.spills
    assert model != model2
Example #6
0
def test_save_load_midrun_scenario(images_dir, uncertain):
    """
    create model, save it after 1step, then load and check equality of original
    model and persisted model
    """

    model = make_model(images_dir, uncertain)

    model.step()
    print 'saving scnario ..'
    model.save(saveloc_)

    print 'loading scenario ..'
    model2 = load(saveloc_)

    for sc in zip(model.spills.items(), model2.spills.items()):
        sc[0]._array_allclose_atol = 1e-5  # need to change both atol
        sc[1]._array_allclose_atol = 1e-5

    assert model.spills == model2.spills
    assert model == model2