Пример #1
0
def test_read_config_file():
    with tempfile.NamedTemporaryFile() as config_file:
        config_file.write(b'[mysection]\nvalue=42')
        config_file.flush()
        parser = argparse.ArgumentParser()
        args = config.parse_args(parser, ['myscript', '--config', config_file.name])
    assert args['mysection']['value'] == '42'
Пример #2
0
def test_read_config_file():
    with tempfile.NamedTemporaryFile() as config_file:
        config_file.write(b'[mysection]\nvalue=42')
        config_file.flush()
        parser = argparse.ArgumentParser()
        args = config.parse_args(parser, ['myscript', '--config', config_file.name], config_file='zgres')
    assert args['mysection']['value'] == '42'
Пример #3
0
def test_error_with_no_config_file():
    with tempfile.NamedTemporaryFile() as config_file:
        name = config_file.name
    parser = argparse.ArgumentParser()
    with pytest.raises(FileNotFoundError) as exec:
        config.parse_args(parser, ['myscript', '--config', name])
Пример #4
0
def test_error_with_no_config_file():
    with tempfile.NamedTemporaryFile() as config_file:
        name = config_file.name
    parser = argparse.ArgumentParser()
    with pytest.raises(FileNotFoundError) as exec:
        config.parse_args(parser, ['myscript', '--config', name], config_file='zgres')