Пример #1
0
def test_list_files_recursively():
    a = list_files_recursively("tests", 'model', suffix='foobar')
    b = list_files_recursively("tests/", 'model', suffix='foobar')
    c = list_files_recursively(os.path.abspath("tests"),
                               'model',
                               suffix='foobar')
    assert a == b
    assert a == c
    assert len(a) == 3
    assert a[0] in [
        'test_foo/bar/model.foobar',
        'test_foo/foo/bar/model.foobar',
        'test_foo/foobar/model.foobar',
    ]
    assert a[1] in [
        'test_foo/bar/model.foobar',
        'test_foo/foo/bar/model.foobar',
        'test_foo/foobar/model.foobar',
    ]
    assert a[2] in [
        'test_foo/bar/model.foobar',
        'test_foo/foo/bar/model.foobar',
        'test_foo/foobar/model.foobar',
    ]
    assert a[0] != a[1]
    assert a[1] != a[2]
    assert a[0] != a[2]
    assert all([x.endswith("model.foobar") for x in a])
    assert all([os.path.exists(os.path.join("tests", x)) for x in a])
Пример #2
0
def test_list_files_recursively():
    a = list_files_recursively("example", 'model')
    b = list_files_recursively("example/", 'model')
    c = list_files_recursively(os.path.abspath("example"), 'model')
    assert a == b
    assert a == c
    assert a[0].startswith("models/")
    assert all([x.endswith("model.yaml") for x in a])
    assert all([os.path.exists(os.path.join("example", x)) for x in a])
Пример #3
0
def all_models_to_test(src):
    """Returns a list of models to test

    By default, this method returns all the model. In case a model group has a
    `test_subset.txt` file present in the group directory, then testing is only
    performed for models listed in `test_subset.txt`.

    Args:
      src: Model source
    """
    txt_files = list_files_recursively(src.local_path, "test_subset", "txt")

    exclude = []
    include = []
    for x in txt_files:
        d = os.path.dirname(x)
        exclude += [d]
        include += [
            os.path.join(d, l)
            for l in read_txt(os.path.join(src.local_path, x))
        ]

    # try to load every model extra included -- will get tested downstream
    # for m in include:
    #     src.get_model_descr(m)

    models = src.list_models().model
    for excl in exclude:
        models = models[~models.str.startswith(excl)]
    return list(models) + include
Пример #4
0
def list_yamls_recursively(root_dir, basename):
    return [os.path.dirname(x) for x in list_files_recursively(root_dir, basename, suffix='y?ml')]