Пример #1
0
def test_Config_on_shelf(tmpdir):
    with shelve.open(os.path.join(tmpdir.strpath, 'x.shelve')) as shelf:
        flatshelf = FlatMap(dictionary=shelf)
        config = Config(dictionary=flatshelf)
        config['x'] = 10
        config['y'] = {}
        config['y']['a'] = 'aaa'
        config['y']['b'] = 111
        config['y']['c'] = {'v': 10}
        config['y']['c']['w'] = 20
        config['y']['d'] = 888
        config['z'] = 999
        config_stream = string_io()
        config.dump(stream=config_stream)
        config_dump = config_stream.getvalue()
        assert config_dump == """\
z = 999
x = 10
[y]
    b = 111
    [c]
        v = 10
        w = 20
    a = 'aaa'
    d = 888
"""
    with shelve.open(os.path.join(tmpdir.strpath, 'x.shelve')) as shelf2:
        flatshelf2 = FlatMap(dictionary=shelf2)
        config2 = Config(dictionary=flatshelf2)
        config2_stream = string_io()
        config2.dump(stream=config2_stream)
        config2_dump = config2_stream.getvalue()
        assert config2_dump == config_dump
Пример #2
0
def run(args, log_stream=None, out_stream=None):
    if log_stream is None:
        log_stream = string_io()
    if out_stream is None:
        out_stream = string_io()
    print(args)
    main(
        log_stream=log_stream,
        out_stream=out_stream,
        argv=args,
    )
    return log_stream, out_stream
Пример #3
0
def test_Section_2(content):
    section = Section(dictionary=FlatMap(collections.OrderedDict()), init=content)
    section2 = Section(dictionary=FlatMap(collections.OrderedDict()), init=content)
    s_io = string_io()
    section.dump(stream=s_io)
    assert s_io.getvalue() == SECTION_DUMP
    section['sub']['y']['yfilename'] = 'y.dat'
    s_io1 = string_io()
    section.dump(stream=s_io1)
    assert s_io1.getvalue() != SECTION_DUMP
    s_io2 = string_io()
    section2.dump(stream=s_io2)
    assert s_io2.getvalue() == SECTION_DUMP
Пример #4
0
def test_main_verbose_level(verbose_level):
    args = ["read"]
    if verbose_level == 0:
        args.append('-q')
    elif verbose_level > 1:
        args.append('-' + ('v' * (verbose_level - 1)))
    args.extend(('-i', "non-existent-path.zirkon"))
    log_stream=string_io()
    out_stream=string_io()
    with pytest.raises(SystemExit) as exc_info:
        run(args, log_stream=log_stream, out_stream=out_stream)
    assert str(exc_info.value) == "1"
    assert log_stream.getvalue() == "ERROR    invalid value non-existent-path.zirkon: input file not found\n"
    assert out_stream.getvalue() == ""
Пример #5
0
def test_Section_2(content):
    section = Section(dictionary=FlatMap(collections.OrderedDict()),
                      init=content)
    section2 = Section(dictionary=FlatMap(collections.OrderedDict()),
                       init=content)
    s_io = string_io()
    section.dump(stream=s_io)
    assert s_io.getvalue() == SECTION_DUMP
    section['sub']['y']['yfilename'] = 'y.dat'
    s_io1 = string_io()
    section.dump(stream=s_io1)
    assert s_io1.getvalue() != SECTION_DUMP
    s_io2 = string_io()
    section2.dump(stream=s_io2)
    assert s_io2.getvalue() == SECTION_DUMP
Пример #6
0
def test_Config_on_shelf(tmpdir):
    with shelve.open(os.path.join(tmpdir.strpath, "x.shelve")) as shelf:
        flatshelf = FlatMap(dictionary=shelf)
        config = Config(dictionary=flatshelf)
        config["x"] = 10
        config["y"] = {}
        config["y"]["a"] = "aaa"
        config["y"]["b"] = 111
        config["y"]["c"] = {"v": 10}
        config["y"]["c"]["w"] = 20
        config["y"]["d"] = 888
        config["z"] = 999
        config_stream = string_io()
        config.dump(stream=config_stream)
        config_dump = config_stream.getvalue()
        assert (
            config_dump
            == """\
z = 999
x = 10
[y]
    b = 111
    [c]
        v = 10
        w = 20
    a = 'aaa'
    d = 888
"""
        )
    with shelve.open(os.path.join(tmpdir.strpath, "x.shelve")) as shelf2:
        flatshelf2 = FlatMap(dictionary=shelf2)
        config2 = Config(dictionary=flatshelf2)
        config2_stream = string_io()
        config2.dump(stream=config2_stream)
        config2_dump = config2_stream.getvalue()
        assert config2_dump == config_dump