示例#1
0
 def test_it_supports_fstring_urls(self):
     url = "http://abc.{tld}"
     r = LocustRequest(method=HttpMethod.GET, url=f"f'{url}'", headers={"a": "b"})
     assert lreq_to_expr(r) == py.FunctionCall(
         name="self.client.get",
         named_args={
             "url": py.FString(url),
             "name": py.FString(url),
             "headers": py.Literal({"a": "b"}),
             "timeout": py.Literal(TIMEOUT),
             "allow_redirects": py.Literal(False),
         },
     )
示例#2
0
def _peel_off_repr(s: str) -> py.Literal:
    """
    Reverse the effect of LocustRequest's repr() calls on url and name.
    """
    if s.startswith("f"):
        return py.FString(eval(s[1:], {}, {}))
    return py.Literal(eval(s, {}, {}))
 def test_format_template_is_not_replaced(self):
     a = 2
     assert str(py.FString("a {a} {} {a!r}")) == "f'a {a} {} {a!r}'"
 def test_non_strings_raise_error(self):
     with pytest.raises(TypeError):
         assert str(py.FString(24))
 def test_strings_appear_as_fstrings(self):
     assert str(py.FString("")) == "f''"
     assert str(py.FString("ab")) == "f'ab'"
     assert str(py.FString("a'b")) == """ f"a'b" """.strip()
     assert str(py.FString('a"b')) == """ f'a"b' """.strip()