Пример #1
0
    def test_extracttags_no_srcvar(self):
        tc_helper = TrackerConfigHelper()

        setvarifs = []
        setvarifs.append(
            ExtractTags.SetVarIf("name", "^(some|tags)$", None, None))
        setvarifs.append(
            ExtractTags.SetVarIf("name", None, "avalue", "newvalue"))
        extracttags = ExtractTags("srcvar", "-", setvarifs)

        variables = {}

        extracttags.process(tc_helper, variables)
        self.assertTrue("name" not in variables)
Пример #2
0
    def test_extracttags_match_only_regex(self):
        tc_helper = TrackerConfigHelper()

        setvarifs = []
        setvarifs.append(
            ExtractTags.SetVarIf("name", "^(some|tags)$", None, None))
        setvarifs.append(ExtractTags.SetVarIf("name", None, "Name",
                                              "newvalue"))
        extracttags = ExtractTags("srcvar", "-", setvarifs)

        variables = {
            "srcvar": "some - oldvalue",
        }
        extracttags.process(tc_helper, variables)
        self.assertEqual(variables["name"], "some")
Пример #3
0
    def test_extracttags_match_regex_newvalue(self):
        tc_helper = TrackerConfigHelper()

        setvarifs = []
        setvarifs.append(
            ExtractTags.SetVarIf("name", "^(some|tags)$", None, None))
        setvarifs.append(ExtractTags.SetVarIf("two", None, "avaluE", "True"))
        extracttags = ExtractTags("srcvar", "-", setvarifs)

        variables = {
            "srcvar": "tags - Avalue",
        }

        extracttags.process(tc_helper, variables)
        self.assertEqual(variables["name"], "tags")
        self.assertEqual(variables["two"], "True")
Пример #4
0
    def test_extracttags_regex_new_value(self):
        tc_helper = TrackerConfigHelper()

        setvarifs = []
        setvarifs.append(ExtractTags.SetVarIf("name1", "^asdf$", None, "eurT"))
        extracttags = ExtractTags("srcvar", ":", setvarifs)

        variables = {
            "srcvar": "asdf : other tings",
        }

        extracttags.process(tc_helper, variables)
        self.assertEqual(variables["name1"], "eurT")
Пример #5
0
    def test_extracttags_regex_part_of_tag(self):
        tc_helper = TrackerConfigHelper()

        setvarifs = []
        setvarifs.append(ExtractTags.SetVarIf("name1", "stuff$", None, None))
        extracttags = ExtractTags("srcvar", ":", setvarifs)

        variables = {
            "srcvar": "some stuff : other tings",
        }

        extracttags.process(tc_helper, variables)
        self.assertEqual(variables["name1"], "some stuff")
Пример #6
0
    def test_extracttags_match_two_each(self):
        tc_helper = TrackerConfigHelper()

        setvarifs = []
        setvarifs.append(ExtractTags.SetVarIf("name1", "^(n1|m1)$", None,
                                              None))
        setvarifs.append(ExtractTags.SetVarIf("name2", "^(n2|m2)$", None,
                                              None))
        setvarifs.append(ExtractTags.SetVarIf("name3", None, "Value1", "True"))
        setvarifs.append(ExtractTags.SetVarIf("name4", None, "Value2",
                                              "False"))
        extracttags = ExtractTags("srcvar", "-|/|:", setvarifs)

        variables = {
            "srcvar": "n1 : valuE2 / m2 - vAlUe1",
        }

        extracttags.process(tc_helper, variables)
        self.assertEqual(variables["name1"], "n1")
        self.assertEqual(variables["name2"], "m2")
        self.assertEqual(variables["name3"], "True")
        self.assertEqual(variables["name4"], "False")
Пример #7
0
    def test_if_process_all(self):
        tc_helper = TrackerConfigHelper()

        matches = []
        matches.append(
            Var(
                "first_var",
                [
                    HelperXml(x) for x in [
                        ["string", "value", "var stuff - here : "],
                        ["var", "name", "srcvar"],
                    ]
                ],
            ))
        matches.append(
            Extract("first_var", "(.*) - (.*) :", ["ext_g1", "ext_g2"], False))

        matches.append(
            ExtractOne([
                Extract("ext_g1", "(.*) stuff", ["extone_g1"], False),
                Extract("ext_g2", "here", ["extone_g2"], False),
            ]))

        matches.append(
            ExtractTags(
                "first_var",
                "[:-]",
                [
                    ExtractTags.SetVarIf("extract_tags_var", "^(some|here)$",
                                         None, None)
                ],
            ))

        matches.append(
            VarReplace("varreplace_var", "first_var", "[_:/-]", "<-->"))

        matches.append(
            SetRegex("varreplace_var", "> here <", "setregex_var",
                     "setregex_value"))

        matches.append(
            If(
                "setregex_var",
                "_value",
                [
                    SetRegex("extract_tags_var", "here", "setregex_var2",
                             "setregex_value2")
                ],
            ))

        iff = If("srcvar", "st[Uu]ff", matches)

        variables = {
            "srcvar": "stUff in here",
            "srcvar2": "0tter stUff in here",
        }

        iff.process(tc_helper, variables)
        self.assertEqual(variables["first_var"],
                         "var stuff - here : stUff in here")
        self.assertEqual(variables["ext_g1"], "var stuff")
        self.assertEqual(variables["ext_g2"], "here")
        self.assertEqual(variables["extone_g1"], "var")
        self.assertTrue("extone_g2" not in variables)
        self.assertEqual(variables["extract_tags_var"], "here")
        self.assertEqual(variables["varreplace_var"],
                         "var stuff <--> here <--> stUff in here")
        self.assertEqual(variables["setregex_var"], "setregex_value")
        self.assertEqual(variables["setregex_var2"], "setregex_value2")