示例#1
0
    def test_argvlist_positional_substitution(self, tmpdir, newconfig):
        config = newconfig("""
            [section]
            key2=
                cmd1 []
                cmd2 {posargs:{item2} \
                     other}
        """)
        reader = IniReader(config._cfg)
        posargs = ['hello', 'world']
        reader.addsubstitions(posargs, item2="value2")
        #py.test.raises(tox.exception.ConfigError,
        #    "reader.getargvlist('section', 'key1')")
        assert reader.getargvlist('section', 'key1') == []
        argvlist = reader.getargvlist("section", "key2")
        assert argvlist[0] == ["cmd1"] + posargs
        assert argvlist[1] == ["cmd2"] + posargs

        reader = IniReader(config._cfg)
        reader.addsubstitions([], item2="value2")
        #py.test.raises(tox.exception.ConfigError,
        #    "reader.getargvlist('section', 'key1')")
        assert reader.getargvlist('section', 'key1') == []
        argvlist = reader.getargvlist("section", "key2")
        assert argvlist[0] == ["cmd1"]
        assert argvlist[1] == ["cmd2", "value2", "other"]
示例#2
0
    def test_argvlist_positional_substitution(self, tmpdir, newconfig):
        config = newconfig("""
            [section]
            key2=
                cmd1 []
                cmd2 {posargs:{item2} \
                     other}
        """)
        reader = IniReader(config._cfg)
        posargs = ['hello', 'world']
        reader.addsubstitions(posargs, item2="value2")
        #py.test.raises(tox.exception.ConfigError,
        #    "reader.getargvlist('section', 'key1')")
        assert reader.getargvlist('section', 'key1') == []
        argvlist = reader.getargvlist("section", "key2")
        assert argvlist[0] == ["cmd1"] + posargs
        assert argvlist[1] == ["cmd2"] + posargs

        reader = IniReader(config._cfg)
        reader.addsubstitions([], item2="value2")
        #py.test.raises(tox.exception.ConfigError,
        #    "reader.getargvlist('section', 'key1')")
        assert reader.getargvlist('section', 'key1') == []
        argvlist = reader.getargvlist("section", "key2")
        assert argvlist[0] == ["cmd1"]
        assert argvlist[1] == ["cmd2", "value2", "other"]
示例#3
0
 def test_getpath(self, tmpdir, newconfig):
     config = newconfig("""
         [section]
         path1={HELLO}
     """)
     reader = IniReader(config._cfg)
     reader.addsubstitions(toxinidir=tmpdir, HELLO="mypath")
     x = reader.getpath("section", "path1", tmpdir)
     assert x == tmpdir.join("mypath")
示例#4
0
 def test_getpath(self, tmpdir, newconfig):
     config = newconfig("""
         [section]
         path1={HELLO}
     """)
     reader = IniReader(config._cfg)
     reader.addsubstitions(toxinidir=tmpdir, HELLO="mypath")
     x = reader.getpath("section", "path1", tmpdir)
     assert x == tmpdir.join("mypath")
示例#5
0
 def test_getlist(self, tmpdir, newconfig):
     config = newconfig("""
         [section]
         key2=
             item1
             {item2}
     """)
     reader = IniReader(config._cfg)
     reader.addsubstitions(item1="not", item2="grr")
     x = reader.getlist("section", "key2")
     assert x == ['item1', 'grr']
示例#6
0
 def test_getlist(self, tmpdir, newconfig):
     config = newconfig("""
         [section]
         key2=
             item1
             {item2}
     """)
     reader = IniReader(config._cfg)
     reader.addsubstitions(item1="not", item2="grr")
     x = reader.getlist("section", "key2")
     assert x == ['item1', 'grr']
示例#7
0
    def test_substition_with_multiple_words(self, newconfig):
        inisource = """
            [section]
            key = py.test -n5 --junitxml={envlogdir}/junit-{envname}.xml []
            """
        config = newconfig(inisource)
        reader = IniReader(config._cfg)
        posargs = ['hello', 'world']
        reader.addsubstitions(posargs, envlogdir='ENV_LOG_DIR', envname='ENV_NAME')

        expected = ['py.test', '-n5', '--junitxml=ENV_LOG_DIR/junit-ENV_NAME.xml', 'hello', 'world']
        assert reader.getargvlist('section', 'key')[0] == expected
示例#8
0
 def test_argvlist_multiline(self, tmpdir, newconfig):
     config = newconfig("""
         [section]
         key2=
             cmd1 {item1} \ # a comment
                  {item2}
     """)
     reader = IniReader(config._cfg)
     reader.addsubstitions(item1="with space", item2="grr")
     #py.test.raises(tox.exception.ConfigError,
     #    "reader.getargvlist('section', 'key1')")
     assert reader.getargvlist('section', 'key1') == []
     x = reader.getargvlist("section", "key2")
     assert x == [["cmd1", "with space", "grr"]]
示例#9
0
 def test_getdict(self, tmpdir, newconfig):
     config = newconfig("""
         [section]
         key2=
             key1=item1
             key2={item2}
     """)
     reader = IniReader(config._cfg)
     reader.addsubstitions(item1="not", item2="grr")
     x = reader.getdict("section", "key2")
     assert 'key1' in x
     assert 'key2' in x
     assert x['key1'] == 'item1'
     assert x['key2'] == 'grr'
示例#10
0
 def test_argvlist_multiline(self, tmpdir, newconfig):
     config = newconfig("""
         [section]
         key2=
             cmd1 {item1} \ # a comment
                  {item2}
     """)
     reader = IniReader(config._cfg)
     reader.addsubstitions(item1="with space", item2="grr")
     #py.test.raises(tox.exception.ConfigError,
     #    "reader.getargvlist('section', 'key1')")
     assert reader.getargvlist('section', 'key1') == []
     x = reader.getargvlist("section", "key2")
     assert x == [["cmd1", "with space", "grr"]]
示例#11
0
 def test_getdict(self, tmpdir, newconfig):
     config = newconfig("""
         [section]
         key2=
             key1=item1
             key2={item2}
     """)
     reader = IniReader(config._cfg)
     reader.addsubstitions(item1="not", item2="grr")
     x = reader.getdict("section", "key2")
     assert 'key1' in x
     assert 'key2' in x
     assert x['key1'] == 'item1'
     assert x['key2'] == 'grr'
示例#12
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"
示例#13
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"
示例#14
0
    def test_substition_with_multiple_words(self, newconfig):
        inisource = """
            [section]
            key = py.test -n5 --junitxml={envlogdir}/junit-{envname}.xml []
            """
        config = newconfig(inisource)
        reader = IniReader(config._cfg)
        posargs = ['hello', 'world']
        reader.addsubstitions(posargs,
                              envlogdir='ENV_LOG_DIR',
                              envname='ENV_NAME')

        expected = [
            'py.test', '-n5', '--junitxml=ENV_LOG_DIR/junit-ENV_NAME.xml',
            'hello', 'world'
        ]
        assert reader.getargvlist('section', 'key')[0] == expected
示例#15
0
    def test_positional_arguments_are_only_replaced_when_standing_alone(self, tmpdir, newconfig):
        config = newconfig("""
            [section]
            key=
                cmd0 []
                cmd1 -m '[abc]'
                cmd2 -m '\'something\'' []
                cmd3 something[]else
        """)
        reader = IniReader(config._cfg)
        posargs = ['hello', 'world']
        reader.addsubstitions(posargs)

        argvlist = reader.getargvlist('section', 'key')
        assert argvlist[0] == ['cmd0'] + posargs
        assert argvlist[1] == ['cmd1', '-m', '[abc]']
        assert argvlist[2] == ['cmd2', '-m', "something"] + posargs
        assert argvlist[3] == ['cmd3', 'something[]else']
示例#16
0
    def test_positional_arguments_are_only_replaced_when_standing_alone(
            self, tmpdir, newconfig):
        config = newconfig("""
            [section]
            key=
                cmd0 []
                cmd1 -m '[abc]'
                cmd2 -m '\'something\'' []
                cmd3 something[]else
        """)
        reader = IniReader(config._cfg)
        posargs = ['hello', 'world']
        reader.addsubstitions(posargs)

        argvlist = reader.getargvlist('section', 'key')
        assert argvlist[0] == ['cmd0'] + posargs
        assert argvlist[1] == ['cmd1', '-m', '[abc]']
        assert argvlist[2] == ['cmd2', '-m', "something"] + posargs
        assert argvlist[3] == ['cmd3', 'something[]else']