Exemplo n.º 1
0
    def test_parser(self):
        txt = """
include(a/path/to\profile.txt)
VAR=2
include(other/path/to/file.txt)
OTHERVAR=thing

[settings]
os=2
"""
        a = ProfileParser(txt)
        self.assertEquals(a.vars, {"VAR": "2", "OTHERVAR": "thing"})
        self.assertEquals(a.includes, ["a/path/to\profile.txt", "other/path/to/file.txt"])
        self.assertEquals(a.profile_text, """[settings]
os=2""")

        txt = ""
        a = ProfileParser(txt)
        self.assertEquals(a.vars, {})
        self.assertEquals(a.includes, [])
        self.assertEquals(a.profile_text, "")

        txt = """
include(a/path/to\profile.txt)
VAR=$REPLACE_VAR
include(other/path/to/$FILE)
OTHERVAR=thing

[settings]
os=$OTHERVAR
"""
        a = ProfileParser(txt)
        a.apply_vars({"REPLACE_VAR": "22", "FILE": "MyFile", "OTHERVAR": "thing"})
        self.assertEquals(a.vars, {"VAR": "22", "OTHERVAR": "thing"})
        self.assertEquals(a.includes, ["a/path/to\profile.txt", "other/path/to/MyFile"])
        self.assertEquals(a.profile_text, """[settings]
os=thing""")
Exemplo n.º 2
0
    def test_parser(self):
        txt = """
include(a/path/to\profile.txt)
VAR=2
include(other/path/to/file.txt)
OTHERVAR=thing

[settings]
os=2
"""
        a = ProfileParser(txt)
        self.assertEquals(a.vars, {"VAR": "2", "OTHERVAR": "thing"})
        self.assertEquals(a.includes,
                          ["a/path/to\profile.txt", "other/path/to/file.txt"])
        self.assertEquals(a.profile_text, """[settings]
os=2""")

        txt = ""
        a = ProfileParser(txt)
        self.assertEquals(a.vars, {})
        self.assertEquals(a.includes, [])
        self.assertEquals(a.profile_text, "")

        txt = """
include(a/path/to\profile.txt)
VAR=$REPLACE_VAR
include(other/path/to/$FILE)
OTHERVAR=thing

[settings]
os=$OTHERVAR
"""
        a = ProfileParser(txt)
        a.apply_vars({
            "REPLACE_VAR": "22",
            "FILE": "MyFile",
            "OTHERVAR": "thing"
        })
        self.assertEquals(a.vars, {"VAR": "22", "OTHERVAR": "thing"})
        self.assertEquals(a.includes,
                          ["a/path/to\profile.txt", "other/path/to/MyFile"])
        self.assertEquals(a.profile_text, """[settings]
os=thing""")
Exemplo n.º 3
0
def test_profile_parser():
    txt = textwrap.dedent("""
        include(a/path/to\profile.txt)
        VAR=2
        include(other/path/to/file.txt)
        OTHERVAR=thing

        [settings]
        os=2
        """)
    a = ProfileParser(txt)
    assert a.vars == {"VAR": "2", "OTHERVAR": "thing"}
    assert a.includes == ["a/path/to\profile.txt", "other/path/to/file.txt"]
    assert a.profile_text == textwrap.dedent("""[settings]
os=2""")

    txt = ""
    a = ProfileParser(txt)
    assert a.vars == {}
    assert a.includes == []
    assert a.profile_text == ""

    txt = textwrap.dedent("""
        include(a/path/to\profile.txt)
        VAR=$REPLACE_VAR
        include(other/path/to/$FILE)
        OTHERVAR=thing

        [settings]
        os=$OTHERVAR
        """)

    a = ProfileParser(txt)
    a.update_vars({"REPLACE_VAR": "22", "FILE": "MyFile", "OTHERVAR": "thing"})
    a.apply_vars()
    assert a.vars == {"VAR": "22", "OTHERVAR": "thing",
                      "REPLACE_VAR": "22", "FILE": "MyFile",}
    assert [i for i in a.get_includes()] == ["a/path/to\profile.txt", "other/path/to/MyFile"]
    assert a.profile_text == textwrap.dedent("""[settings]
os=thing""")

    txt = textwrap.dedent("""
        includes(a/path/to\profile.txt)
        """)

    with pytest.raises(ConanException):
        try:
            ProfileParser(txt)
        except Exception as error:
            assert "Error while parsing line 1" in error.args[0]
            raise
Exemplo n.º 4
0
    def test_parser(self):
        txt = """
include(a/path/to\profile.txt)
VAR=2
include(other/path/to/file.txt)
OTHERVAR=thing

[settings]
os=2
"""
        a = ProfileParser(txt)
        self.assertEqual(a.vars, {"VAR": "2", "OTHERVAR": "thing"})
        self.assertEqual(a.includes,
                         ["a/path/to\profile.txt", "other/path/to/file.txt"])
        self.assertEqual(a.profile_text, """[settings]
os=2""")

        txt = ""
        a = ProfileParser(txt)
        self.assertEqual(a.vars, {})
        self.assertEqual(a.includes, [])
        self.assertEqual(a.profile_text, "")

        txt = """
include(a/path/to\profile.txt)
VAR=$REPLACE_VAR
include(other/path/to/$FILE)
OTHERVAR=thing

[settings]
os=$OTHERVAR
"""
        a = ProfileParser(txt)
        a.update_vars({
            "REPLACE_VAR": "22",
            "FILE": "MyFile",
            "OTHERVAR": "thing"
        })
        a.apply_vars()
        self.assertEqual(
            a.vars, {
                "VAR": "22",
                "OTHERVAR": "thing",
                "REPLACE_VAR": "22",
                "FILE": "MyFile",
            })
        self.assertEqual([i for i in a.get_includes()],
                         ["a/path/to\profile.txt", "other/path/to/MyFile"])
        self.assertEqual(a.profile_text, """[settings]
os=thing""")

        txt = """
includes(a/path/to\profile.txt)
"""
        with self.assertRaises(ConanException):
            try:
                ProfileParser(txt)
            except Exception as error:
                self.assertIn("Error while parsing line 1", error.args[0])
                raise