How to use the httprunner.parser.LazyString function in httprunner

To help you get started, we’ve selected a few httprunner examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github httprunner / httprunner / tests / test_parser.py View on Github external
def test_parse_func_var_duplicate(self):
        variables_mapping = {
            "var_1": "abc",
            "var_2": "def",
            "var_3": 123,
            "var_4": {"a": 1},
            "var_5": True,
            "var_6": None
        }
        check_variables_set = variables_mapping.keys()
        functions_mapping = {
            "func1": lambda x,y: str(x) + str(y)
        }
        var = parser.LazyString(
            "ABC${func1($var_1, $var_3)}--${func1($var_1, $var_3)}",
            functions_mapping,
            check_variables_set
        )
        self.assertEqual(var._string, "ABC{}--{}")
        self.assertEqual(var.to_value(variables_mapping), "ABCabc123--abc123")

        var = parser.LazyString("ABC${func1($var_1, $var_3)}$var_1", functions_mapping, check_variables_set)
        self.assertEqual(var._string, "ABC{}{}")
        self.assertEqual(var.to_value(variables_mapping), "ABCabc123abc")

        var = parser.LazyString(
            "ABC${func1($var_1, $var_3)}$var_1--${func1($var_1, $var_3)}$var_1",
            functions_mapping,
            check_variables_set
        )
github httprunner / httprunner / tests / test_parser.py View on Github external
def test_parse_variable(self):
        """ variable format ${var} and $var
        """
        variables_mapping = {
            "var_1": "abc",
            "var_2": "def",
            "var_3": 123,
            "var_4": {"a": 1},
            "var_5": True,
            "var_6": None
        }
        check_variables_set = variables_mapping.keys()
        functions_mapping = {}

        # format: $var
        var = parser.LazyString("ABC$var_1", functions_mapping, check_variables_set)
        self.assertEqual(var._string, "ABC{}")
        self.assertEqual(var._args, ["var_1"])
        self.assertEqual(var.to_value(variables_mapping), "ABCabc")

        var = parser.LazyString("ABC$var_1$var_3", functions_mapping, check_variables_set)
        self.assertEqual(var._string, "ABC{}{}")
        self.assertEqual(var._args, ["var_1", "var_3"])
        self.assertEqual(var.to_value(variables_mapping), "ABCabc123")

        var = parser.LazyString("ABC$var_1/$var_3", functions_mapping, check_variables_set)
        self.assertEqual(var._string, "ABC{}/{}")
        self.assertEqual(var._args, ["var_1", "var_3"])
        self.assertEqual(var.to_value(variables_mapping), "ABCabc/123")

        var = parser.LazyString("ABC$var_1/", functions_mapping, check_variables_set)
        self.assertEqual(var._string, "ABC{}/")
github httprunner / httprunner / tests / test_parser.py View on Github external
"var_5": True,
            "var_6": None
        }
        check_variables_set = variables_mapping.keys()
        functions_mapping = {
            "func1": lambda x,y: str(x) + str(y)
        }
        var = parser.LazyString(
            "ABC${func1($var_1, $var_3)}--${func1($var_1, $var_3)}",
            functions_mapping,
            check_variables_set
        )
        self.assertEqual(var._string, "ABC{}--{}")
        self.assertEqual(var.to_value(variables_mapping), "ABCabc123--abc123")

        var = parser.LazyString("ABC${func1($var_1, $var_3)}$var_1", functions_mapping, check_variables_set)
        self.assertEqual(var._string, "ABC{}{}")
        self.assertEqual(var.to_value(variables_mapping), "ABCabc123abc")

        var = parser.LazyString(
            "ABC${func1($var_1, $var_3)}$var_1--${func1($var_1, $var_3)}$var_1",
            functions_mapping,
            check_variables_set
        )
        self.assertEqual(var._string, "ABC{}{}--{}{}")
        self.assertEqual(var.to_value(variables_mapping), "ABCabc123abc--abc123abc")
github httprunner / httprunner / tests / test_parser.py View on Github external
self.assertEqual(var._string, "ABC{}/{}/{}")
        self.assertEqual(var._args, ["var_1", "var_2", "var_1"])
        self.assertEqual(var.to_value(variables_mapping), "ABCabc/def/abc")

        var = parser.LazyString("func1($var_1, $var_3)", functions_mapping, check_variables_set)
        self.assertEqual(var._string, "func1({}, {})")
        self.assertEqual(var._args, ["var_1", "var_3"])
        self.assertEqual(var.to_value(variables_mapping), "func1(abc, 123)")

        # format: ${var}
        var = parser.LazyString("ABC${var_1}", functions_mapping, check_variables_set)
        self.assertEqual(var._string, "ABC{}")
        self.assertEqual(var._args, ["var_1"])
        self.assertEqual(var.to_value(variables_mapping), "ABCabc")

        var = parser.LazyString("ABC${var_1}${var_3}", functions_mapping, check_variables_set)
        self.assertEqual(var._string, "ABC{}{}")
        self.assertEqual(var._args, ["var_1", "var_3"])
        self.assertEqual(var.to_value(variables_mapping), "ABCabc123")

        var = parser.LazyString("ABC${var_1}/${var_3}", functions_mapping, check_variables_set)
        self.assertEqual(var._string, "ABC{}/{}")
        self.assertEqual(var._args, ["var_1", "var_3"])
        self.assertEqual(var.to_value(variables_mapping), "ABCabc/123")

        var = parser.LazyString("ABC${var_1}/", functions_mapping, check_variables_set)
        self.assertEqual(var._string, "ABC{}/")
        self.assertEqual(var._args, ["var_1"])
        self.assertEqual(var.to_value(variables_mapping), "ABCabc/")

        var = parser.LazyString("ABC${var_1}123", functions_mapping, check_variables_set)
        self.assertEqual(var._string, "ABC{}123")
github httprunner / httprunner / tests / test_parser.py View on Github external
}
        check_variables_set = variables_mapping.keys()
        functions_mapping = {}

        # format: $var
        var = parser.LazyString("ABC$var_1", functions_mapping, check_variables_set)
        self.assertEqual(var._string, "ABC{}")
        self.assertEqual(var._args, ["var_1"])
        self.assertEqual(var.to_value(variables_mapping), "ABCabc")

        var = parser.LazyString("ABC$var_1$var_3", functions_mapping, check_variables_set)
        self.assertEqual(var._string, "ABC{}{}")
        self.assertEqual(var._args, ["var_1", "var_3"])
        self.assertEqual(var.to_value(variables_mapping), "ABCabc123")

        var = parser.LazyString("ABC$var_1/$var_3", functions_mapping, check_variables_set)
        self.assertEqual(var._string, "ABC{}/{}")
        self.assertEqual(var._args, ["var_1", "var_3"])
        self.assertEqual(var.to_value(variables_mapping), "ABCabc/123")

        var = parser.LazyString("ABC$var_1/", functions_mapping, check_variables_set)
        self.assertEqual(var._string, "ABC{}/")
        self.assertEqual(var._args, ["var_1"])
        self.assertEqual(var.to_value(variables_mapping), "ABCabc/")

        var = parser.LazyString("ABC$var_1$", functions_mapping, check_variables_set)
        self.assertEqual(var._string, "ABC{}$")
        self.assertEqual(var._args, ["var_1"])
        self.assertEqual(var.to_value(variables_mapping), "ABCabc$")

        var = parser.LazyString("ABC$var_1/123$var_1/456", functions_mapping, check_variables_set)
        self.assertEqual(var._string, "ABC{}/123{}/456")
github httprunner / httprunner / tests / test_parser.py View on Github external
var = parser.LazyString("ABC${var_1}/", functions_mapping, check_variables_set)
        self.assertEqual(var._string, "ABC{}/")
        self.assertEqual(var._args, ["var_1"])
        self.assertEqual(var.to_value(variables_mapping), "ABCabc/")

        var = parser.LazyString("ABC${var_1}123", functions_mapping, check_variables_set)
        self.assertEqual(var._string, "ABC{}123")
        self.assertEqual(var._args, ["var_1"])
        self.assertEqual(var.to_value(variables_mapping), "ABCabc123")

        var = parser.LazyString("ABC${var_1}/123${var_1}/456", functions_mapping, check_variables_set)
        self.assertEqual(var._string, "ABC{}/123{}/456")
        self.assertEqual(var._args, ["var_1", "var_1"])
        self.assertEqual(var.to_value(variables_mapping), "ABCabc/123abc/456")

        var = parser.LazyString("ABC${var_1}/${var_2}/${var_1}", functions_mapping, check_variables_set)
        self.assertEqual(var._string, "ABC{}/{}/{}")
        self.assertEqual(var._args, ["var_1", "var_2", "var_1"])
        self.assertEqual(var.to_value(variables_mapping), "ABCabc/def/abc")

        var = parser.LazyString("func1(${var_1}, ${var_3})", functions_mapping, check_variables_set)
        self.assertEqual(var._string, "func1({}, {})")
        self.assertEqual(var._args, ["var_1", "var_3"])
        self.assertEqual(var.to_value(variables_mapping), "func1(abc, 123)")
github httprunner / httprunner / tests / test_parser.py View on Github external
def test_parse_func_var_abnormal(self):
        variables_mapping = {
            "var_1": "abc",
            "var_2": "def",
            "var_3": 123,
            "var_4": {"a": 1},
            "var_5": True,
            "var_6": None
        }
        check_variables_set = variables_mapping.keys()
        functions_mapping = {
            "func1": lambda x,y: str(x) + str(y)
        }

        # {
        var = parser.LazyString("ABC$var_1{", functions_mapping, check_variables_set)
        self.assertEqual(var._string, "ABC{}{{")
        self.assertEqual(var._args, ["var_1"])
        self.assertEqual(var.to_value(variables_mapping), "ABCabc{")

        var = parser.LazyString("{ABC$var_1{}a}", functions_mapping, check_variables_set)
        self.assertEqual(var._string, "{{ABC{}{{}}a}}")
        self.assertEqual(var._args, ["var_1"])
        self.assertEqual(var.to_value(variables_mapping), "{ABCabc{}a}")

        var = parser.LazyString("AB{C$var_1{}a}", functions_mapping, check_variables_set)
        self.assertEqual(var._string, "AB{{C{}{{}}a}}")
        self.assertEqual(var._args, ["var_1"])
        self.assertEqual(var.to_value(variables_mapping), "AB{Cabc{}a}")

        # }
        var = parser.LazyString("ABC$var_1}", functions_mapping, check_variables_set)
github httprunner / httprunner / tests / test_parser.py View on Github external
"var_2": "def",
            "var_3": 123,
            "var_4": {"a": 1},
            "var_5": True,
            "var_6": None
        }
        check_variables_set = variables_mapping.keys()
        functions_mapping = {}

        # format: $var
        var = parser.LazyString("ABC$var_1", functions_mapping, check_variables_set)
        self.assertEqual(var._string, "ABC{}")
        self.assertEqual(var._args, ["var_1"])
        self.assertEqual(var.to_value(variables_mapping), "ABCabc")

        var = parser.LazyString("ABC$var_1$var_3", functions_mapping, check_variables_set)
        self.assertEqual(var._string, "ABC{}{}")
        self.assertEqual(var._args, ["var_1", "var_3"])
        self.assertEqual(var.to_value(variables_mapping), "ABCabc123")

        var = parser.LazyString("ABC$var_1/$var_3", functions_mapping, check_variables_set)
        self.assertEqual(var._string, "ABC{}/{}")
        self.assertEqual(var._args, ["var_1", "var_3"])
        self.assertEqual(var.to_value(variables_mapping), "ABCabc/123")

        var = parser.LazyString("ABC$var_1/", functions_mapping, check_variables_set)
        self.assertEqual(var._string, "ABC{}/")
        self.assertEqual(var._args, ["var_1"])
        self.assertEqual(var.to_value(variables_mapping), "ABCabc/")

        var = parser.LazyString("ABC$var_1$", functions_mapping, check_variables_set)
        self.assertEqual(var._string, "ABC{}$")
github httprunner / httprunner / tests / test_parser.py View on Github external
var = parser.LazyString("ABC$var_1$", functions_mapping, check_variables_set)
        self.assertEqual(var._string, "ABC{}$")
        self.assertEqual(var._args, ["var_1"])
        self.assertEqual(var.to_value(variables_mapping), "ABCabc$")

        var = parser.LazyString("ABC$var_1/123$var_1/456", functions_mapping, check_variables_set)
        self.assertEqual(var._string, "ABC{}/123{}/456")
        self.assertEqual(var._args, ["var_1", "var_1"])
        self.assertEqual(var.to_value(variables_mapping), "ABCabc/123abc/456")

        var = parser.LazyString("ABC$var_1/$var_2/$var_1", functions_mapping, check_variables_set)
        self.assertEqual(var._string, "ABC{}/{}/{}")
        self.assertEqual(var._args, ["var_1", "var_2", "var_1"])
        self.assertEqual(var.to_value(variables_mapping), "ABCabc/def/abc")

        var = parser.LazyString("func1($var_1, $var_3)", functions_mapping, check_variables_set)
        self.assertEqual(var._string, "func1({}, {})")
        self.assertEqual(var._args, ["var_1", "var_3"])
        self.assertEqual(var.to_value(variables_mapping), "func1(abc, 123)")

        # format: ${var}
        var = parser.LazyString("ABC${var_1}", functions_mapping, check_variables_set)
        self.assertEqual(var._string, "ABC{}")
        self.assertEqual(var._args, ["var_1"])
        self.assertEqual(var.to_value(variables_mapping), "ABCabc")

        var = parser.LazyString("ABC${var_1}${var_3}", functions_mapping, check_variables_set)
        self.assertEqual(var._string, "ABC{}{}")
        self.assertEqual(var._args, ["var_1", "var_3"])
        self.assertEqual(var.to_value(variables_mapping), "ABCabc123")

        var = parser.LazyString("ABC${var_1}/${var_3}", functions_mapping, check_variables_set)
github httprunner / httprunner / tests / test_parser.py View on Github external
self.assertEqual(var.to_value(variables_mapping), "ABC$var_1{")

        # $$$
        var = parser.LazyString("ABC$$$var_1{", functions_mapping, check_variables_set)
        self.assertEqual(var._string, "ABC${}{{")
        self.assertEqual(var._args, ["var_1"])
        self.assertEqual(var.to_value(variables_mapping), "ABC$abc{")

        # $$$$
        var = parser.LazyString("ABC$$$$var_1{", functions_mapping, check_variables_set)
        self.assertEqual(var._string, "ABC$$var_1{{")
        self.assertEqual(var._args, [])
        self.assertEqual(var.to_value(variables_mapping), "ABC$$var_1{")

        # ${
        var = parser.LazyString("ABC$var_1${", functions_mapping, check_variables_set)
        self.assertEqual(var._string, "ABC{}${{")
        self.assertEqual(var._args, ["var_1"])
        self.assertEqual(var.to_value(variables_mapping), "ABCabc${")

        var = parser.LazyString("ABC$var_1${a", functions_mapping, check_variables_set)
        self.assertEqual(var._string, "ABC{}${{a")
        self.assertEqual(var._args, ["var_1"])
        self.assertEqual(var.to_value(variables_mapping), "ABCabc${a")

        # $}
        var = parser.LazyString("ABC$var_1$}a", functions_mapping, check_variables_set)
        self.assertEqual(var._string, "ABC{}$}}a")
        self.assertEqual(var._args, ["var_1"])
        self.assertEqual(var.to_value(variables_mapping), "ABCabc$}a")

        # }{