Ejemplo n.º 1
0
 def test_getdefault_single(self, tmpdir, newconfig):
     config = newconfig("""
         [section]
         key=value
     """)
     reader = IniReader(config._cfg)
     x = reader.getdefault("section", "key")
     assert x == "value"
     assert not reader.getdefault("section", "hello")
     x = reader.getdefault("section", "hello", "world")
     assert x == "world"
Ejemplo n.º 2
0
 def test_getdefault_single(self, tmpdir, newconfig):
     config = newconfig("""
         [section]
         key=value
     """)
     reader = IniReader(config._cfg)
     x = reader.getdefault("section", "key")
     assert x == "value"
     assert not reader.getdefault("section", "hello")
     x = reader.getdefault("section", "hello", "world")
     assert x == "world"
Ejemplo n.º 3
0
 def test_getdefault_fallback_sections(self, tmpdir, newconfig):
     config = newconfig("""
         [mydefault]
         key2=value2
         [section]
         key=value
     """)
     reader = IniReader(config._cfg, fallbacksections=['mydefault'])
     x = reader.getdefault("section", "key2")
     assert x == "value2"
     x = reader.getdefault("section", "key3")
     assert not x
     x = reader.getdefault("section", "key3", "world")
     assert x == "world"
Ejemplo n.º 4
0
 def test_getdefault_fallback_sections(self, tmpdir, newconfig):
     config = newconfig("""
         [mydefault]
         key2=value2
         [section]
         key=value
     """)
     reader = IniReader(config._cfg, fallbacksections=['mydefault'])
     x = reader.getdefault("section", "key2")
     assert x == "value2"
     x = reader.getdefault("section", "key3")
     assert not x
     x = reader.getdefault("section", "key3", "world")
     assert x == "world"
Ejemplo n.º 5
0
 def test_getdefault_substitution(self, tmpdir, newconfig):
     config = newconfig("""
         [mydefault]
         key2={value2}
         [section]
         key={value}
     """)
     reader = IniReader(config._cfg, fallbacksections=['mydefault'])
     reader.addsubstitions(value="newvalue", value2="newvalue2")
     x = reader.getdefault("section", "key2")
     assert x == "newvalue2"
     x = reader.getdefault("section", "key3")
     assert not x
     x = reader.getdefault("section", "key3", "{value2}")
     assert x == "newvalue2"
Ejemplo n.º 6
0
 def test_getdefault_substitution(self, tmpdir, newconfig):
     config = newconfig("""
         [mydefault]
         key2={value2}
         [section]
         key={value}
     """)
     reader = IniReader(config._cfg, fallbacksections=['mydefault'])
     reader.addsubstitions(value="newvalue", value2="newvalue2")
     x = reader.getdefault("section", "key2")
     assert x == "newvalue2"
     x = reader.getdefault("section", "key3")
     assert not x
     x = reader.getdefault("section", "key3", "{value2}")
     assert x == "newvalue2"
Ejemplo n.º 7
0
 def test_getdefault_environment_substitution(self, monkeypatch, newconfig):
     monkeypatch.setenv("KEY1", "hello")
     config = newconfig("""
         [section]
         key1={env:KEY1}
         key2={env:KEY2}
     """)
     reader = IniReader(config._cfg)
     x = reader.getdefault("section", "key1")
     assert x == "hello"
     py.test.raises(tox.exception.ConfigError,
                    'reader.getdefault("section", "key2")')
Ejemplo n.º 8
0
 def test_getdefault_environment_substitution(self, monkeypatch, newconfig):
     monkeypatch.setenv("KEY1", "hello")
     config = newconfig("""
         [section]
         key1={env:KEY1}
         key2={env:KEY2}
     """)
     reader = IniReader(config._cfg)
     x = reader.getdefault("section", "key1")
     assert x == "hello"
     py.test.raises(tox.exception.ConfigError,
         'reader.getdefault("section", "key2")')