Exemplo n.º 1
0
def test_discover_search(tmpdir, standard_paths, exists):
    tdir = tmpdir.join(str(uuid.uuid4())).strpath
    if exists:
        tz0 = os.path.join(tdir, "existing-file.zirkon")
        os.makedirs(tdir)
        with open(tz0, "w") as f_out:
            f_out.write("\n")
    else:
        tz0 = os.path.join(tdir, "non-existing-file.zirkon")
    found = False
    if exists:
        for filetype in discover(tdir, standard_paths=standard_paths):
            if os.path.samefile(filetype.filepath, tz0):
                found = True
                break
    assert found == exists
Exemplo n.º 2
0
def test_discover_search_files(tmpdir):
    tdata = os.path.join(tmpdir.strpath, "DISCOVER_files")
    tadd = os.path.join(tdata, "ADD")
    tconfig = os.path.join(tdata, "CONFIG")
    tschema = os.path.join(tdata, "SCHEMA")
    os.makedirs(tdata)
    os.makedirs(tadd)
    os.makedirs(tconfig)
    os.makedirs(tschema)
    files = []
    files.append(touch(tconfig, "a.zirkon"))
    files.append(touch(tconfig, "b.json"))
    touch(tconfig, "c.zirkon-schema")
    files.append(touch(tschema, "d.zirkon-schema"))
    touch(tschema, "c.configobj")
    files.append(touch(tdata, "d.pickle"))
    files.append(touch(tdata, "d.pickle-schema"))
    files.append(touch(tadd, "a.json-validation"))
    files.append(touch(tadd, "e.json-schema"))
    es_filepath = files[-1]
    ec_filepath = touch(tadd, "e.configobj")
    os.chdir(tdata)
    os.environ['ZIRKON_CONFIG_PATH'] = tconfig
    os.environ['ZIRKON_SCHEMA_PATH'] = tschema
    try:
        filetypes = list(discover((tadd, (Validation, Schema))))
        ft_e0_l = list(search_rootname(os.path.join("ADD", "e")))
        ft_e1_l = list(search_rootname(os.path.join("ADD", "e"), config_classes=(Schema,)))
        ft_e2_l = list(search_rootname(os.path.join("ADD", "e"), fmts=("zirkon", "json")))
        ft_e3_l = list(search_rootname(os.path.join("ADD", "e"), config_classes=(Schema, Validation), fmts=("zirkon", "configobj")))
        ft_e4_l = list(search_rootname(os.path.join("ADD", "e"), config_classes=(Schema, Validation), fmts=("zirkon", "json")))
        ftfp_e1_l = list(search_filetype(FileType(filepath=os.path.join("ADD", "e"), config_class=Schema, fmt=None)))
        ftfp_ex_l = list(search_filetype(FileType(filepath=os.path.join("ADD", "e"), config_class=Schema, fmt="pickle")))
    finally:
        del os.environ['ZIRKON_CONFIG_PATH']
        del os.environ['ZIRKON_SCHEMA_PATH']
    files.sort()
    found_files = [ft.filepath for ft in filetypes]
    found_files.sort()
    #for file in files:
    #    if file not in found_files:
    #        print("expected, not found:", file)
    #for file in found_files:
    #    if file not in files:
    #        print("found, not expected:", file)
    assert files == found_files

    filetypes_d = {filetype.filepath: filetype for filetype in filetypes}
    assert ec_filepath not in filetypes_d
    filetypes_d[ec_filepath] = FileType(filepath=ec_filepath, config_class=Config, fmt="configobj")

    assert len(ft_e0_l) == 2
    dd = {filetype.filepath: filetype for filetype in ft_e0_l}
    assert ec_filepath in dd
    assert dd[ec_filepath] == filetypes_d[ec_filepath]
    assert es_filepath in dd
    assert dd[es_filepath] == filetypes_d[es_filepath]

    assert len(ft_e1_l) == 1
    ft_e1 = ft_e1_l[0]
    assert ft_e1 == FileType(filepath=es_filepath, config_class=Schema, fmt="json")

    assert len(ft_e2_l) == 1
    ft_e2 = ft_e2_l[0]
    assert ft_e2 == ft_e1

    assert len(ft_e3_l) == 0

    assert len(ft_e4_l) == 1
    ft_e4 = ft_e4_l[0]
    assert ft_e4 == ft_e1

    assert len(ftfp_e1_l) == 1
    ftfp_e1 = ftfp_e1_l[0]
    assert ftfp_e1 == ft_e1

    assert len(ftfp_ex_l) == 0
Exemplo n.º 3
0
def test_discover_search_nodir(tmpdir):
    tdir = tmpdir.join(str(uuid.uuid4())).strpath
    with open(tdir, "w") as f_out:
        f_out.write("\n")
    for filetype in discover(tdir, standard_paths=standard_paths):
        pass