示例#1
0
def test_ConfigReaderBase_list(mocker, mockConfigAndExpectation):
    mockConfig, configExpectation = mockConfigAndExpectation
    mocker.patch.object(ConfigReaderBase, "readConfig", return_value=mockConfig)

    config = ConfigReaderBase("/path/to/config.cfg")

    assert config.getListOption("Section2", "ListOption") == configExpectation["Section2"]["ListOption"].split(",")
示例#2
0
def test_ConfigReaderBase_setOptionWithDefault_missing(mocker, mockConfigAndExpectation, getter, default, option):
    mockConfig, configExpectation = mockConfigAndExpectation
    mocker.patch.object(ConfigReaderBase, "readConfig", return_value=mockConfig)

    config = ConfigReaderBase("/path/to/config.cfg")

    assert config.setOptionWithDefault("Section4", option, default, getter) == default
示例#3
0
def test_ConfigReaderBase_multiline_exception(mocker, mockConfigAndExpectation):
    mockConfig, configExpectation = mockConfigAndExpectation
    mocker.patch.object(ConfigReaderBase, "readConfig", return_value=mockConfig)

    config = ConfigReaderBase("/path/to/config.cfg")

    with pytest.raises(RuntimeError):
        config.readMulitlineOption("Section3", "MultilineList", "blubb")
示例#4
0
def test_ConfigReaderBase_multiline(mocker, mockConfigAndExpectation):
    mockConfig, configExpectation = mockConfigAndExpectation
    mocker.patch.object(ConfigReaderBase, "readConfig", return_value=mockConfig)

    config = ConfigReaderBase("/path/to/config.cfg")

    expectedElems = {}
    for line in configExpectation["Section3"]["Multiline"].split("\n"):
        if line == "":
            continue
        else:
            name, val = line.split(" : ")
            expectedElems[name] = val

    assert config.readMulitlineOption("Section3", "Multiline", "Single") == expectedElems
示例#5
0
def test_ConfigReaderBase_init(mocker):
    mocker.patch.object(ConfigReaderBase, "readConfig")

    config = ConfigReaderBase("/path/to/config.cfg")

    assert config.path == "/path/to/config.cfg"
    ConfigReaderBase.readConfig.assert_called_once_with("/path/to/config.cfg")
示例#6
0
def test_ConfigReaderBase_initFromDict(mocker, mockConfigAndExpectation):
    mockConfig, configExpectation = mockConfigAndExpectation
    mocker.patch.object(configparser.ConfigParser, "read")
    
    config = ConfigReaderBase(configExpectation)

    configparser.ConfigParser.read.assert_not_called()
    assert mockConfig == config.readConfig
示例#7
0
def test_ConfigReaderBase_init_exceptions(inputConfig):
    with pytest.raises(TypeError):
        config = ConfigReaderBase(inputConfig)