def test_wrapper_resolve():
    model = init_model()
    wrapped_model = MyWrapper(model)

    assert Wrapper.resolve(wrapped_model.name) == MyWrapper

    class SubWrapper(MyWrapper):
        pass

    wrapped_model_b = SubWrapper(model)
    assert Wrapper.resolve(wrapped_model_b.name) == SubWrapper
def test_resolve_uses_latest_wrapper():
    """
    This is mostly in place to support interactive use within Jupyter.
    We want to resolve the version of the wrapper that the user can
    actually _see_ - the latest version they wrote
    """
    global MyWrapper
    TestWrapperGlobal = MyWrapper

    class MyWrapper(Wrapper):
        pass

    model = models.Sequential([], name = 'model_name')
    wrapped_model = TestWrapperGlobal(model)

    assert Wrapper.resolve(wrapped_model.name) == MyWrapper
    assert Wrapper.resolve(wrapped_model.name) != TestWrapperGlobal
def load(file_path):
    file_base_name = path.splitext(path.basename(file_path))[0]
    model = load_model(file_path)
    model.name = file_base_name.split('-')[-1]
    return Wrapper.resolve(file_base_name)(model)
def test_wrapper_resolve_throws_if_model_is_untagged():
    model = init_model()

    with pytest.raises(Exception):
        Wrapper.resolve(model)