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(",")
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
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")
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
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")
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
def test_ConfigReaderBase_init_exceptions(inputConfig): with pytest.raises(TypeError): config = ConfigReaderBase(inputConfig)