예제 #1
0
def test_classify_iter(tmpdir):
    troot = tmpdir.join("xclassify", str(uuid.uuid4())).strpath
    os.makedirs(troot)
    tf1 = os.path.join(troot, "a.zirkon")
    tf2 = os.path.join(troot, "b.schema")
    tfset = {tf1, tf2}
    for fn in tfset:
        with open(fn, "w") as f_out:
            f_out.write("\n")
    filetypes = set(classify(troot))
    fnset = set(ft.filepath for ft in filetypes)
    assert fnset == tfset
예제 #2
0
def test_classify(tmpdir):
    config_classes = get_config_classes()
    protocols = get_protocols()
    ref_filetypes = {}
    for rootname in 'x', 'xy':
        for config_class in config_classes:
            for protocol in protocols:
                filename = standard_filepath(rootname=rootname, config=config_class, protocol=protocol)
                filepath = os.path.join(tmpdir.strpath, filename)
                with open(filepath, "w") as f_out:
                    pass
                ref_filetype = FileType(filepath=filepath, config_class=config_class, protocol=protocol)
                ref_filetypes[filepath] = ref_filetype
    
    for filetype in classify(tmpdir.strpath):
        assert filetype.filepath in ref_filetypes
        ref_filetype = ref_filetypes.pop(filetype.filepath)
        assert filetype == ref_filetype
        os.remove(filetype.filepath)
    assert len(ref_filetypes) == 0
예제 #3
0
def test_classify(tmpdir):
    config_classes = get_config_classes()
    fmts = get_fmts()
    ref_filetypes = {}
    rootnames = ('x', 'xy')
    for rootname in rootnames:
        for config_class in config_classes:
            config_class_name = get_config_class_name(config_class)
            for fmt in fmts:
                filename = standard_filepath(rootname=rootname, config=config_class_name, fmt=fmt)
                filepath = os.path.join(tmpdir.strpath, filename)
                with open(filepath, "w") as f_out:
                    pass
                ref_filetype = FileType(filepath=filepath, config_class=config_class, fmt=fmt)
                ref_filetypes[filepath] = ref_filetype
    assert len(ref_filetypes) == len(rootnames) * len(config_classes) * len(fmts)

    for filetype in classify(tmpdir.strpath):
        assert filetype.filepath in ref_filetypes
        ref_filetype = ref_filetypes.pop(filetype.filepath)
        assert filetype == ref_filetype
        os.remove(filetype.filepath)
    assert len(ref_filetypes) == 0
예제 #4
0
def test_classify_protocol_error(tmpdir):
    with pytest.raises(ValueError) as exc_info:
        for x in classify(tmpdir.strpath, protocols=("json", "yaml")):
            pass
    assert str(exc_info.value) == "unsupported protocol 'yaml'"
예제 #5
0
def test_classify_class_type_error(tmpdir):
    with pytest.raises(ValueError) as exc_info:
        for x in classify(tmpdir.strpath, config_classes=(Config, 0.3)):
            pass
    assert str(exc_info.value) == "invalid object 0.3 of type float: not a config[_class]"
예제 #6
0
def test_classify_class_name_error(tmpdir):
    with pytest.raises(ValueError) as exc_info:
        for x in classify(tmpdir.strpath, config_classes=(Config, "Skema")):
            pass
    assert str(exc_info.value) == "unsupported config_class name 'Skema'"
예제 #7
0
def test_classify_class_error(tmpdir):
    with pytest.raises(TypeError) as exc_info:
        for x in classify(tmpdir.strpath, config_classes=(Config, Schema, ConfigBase)):
            pass
    assert str(exc_info.value) == "unsupported config_class <class 'zirkon.config_base.ConfigBase'>"
예제 #8
0
def test_classify_class(tmpdir):
    for filetype in classify(tmpdir.strpath, config_classes=(Config, Schema), protocols=("zirkon", "json")):
        pass
예제 #9
0
def test_classify_fmt_error(tmpdir):
    with pytest.raises(ValueError) as exc_info:
        for x in classify(tmpdir.strpath, fmts=("json", "yaml")):
            pass
    assert str(exc_info.value) == "unsupported format 'yaml'"
예제 #10
0
def test_classify_config_classes_fmts(tmpdir):
    for filetype in classify(tmpdir.strpath, config_classes=("Config", "Schema"), fmts=("zirkon", "json")):
        pass