Ejemplo n.º 1
0
def test_typename():
    assert command.typename(str) == "str"
    assert command.typename(typing.Sequence[flow.Flow]) == "[flow]"

    assert command.typename(mitmproxy.types.Data) == "[data]"
    assert command.typename(mitmproxy.types.CutSpec) == "[cut]"

    assert command.typename(flow.Flow) == "flow"
    assert command.typename(typing.Sequence[str]) == "[str]"

    assert command.typename(mitmproxy.types.Choice("foo")) == "choice"
    assert command.typename(mitmproxy.types.Path) == "path"
    assert command.typename(mitmproxy.types.Cmd) == "cmd"
Ejemplo n.º 2
0
def test_typename():
    assert command.typename(str) == "str"
    assert command.typename(typing.Sequence[flow.Flow]) == "[flow]"

    assert command.typename(mitmproxy.types.Data) == "[data]"
    assert command.typename(mitmproxy.types.CutSpec) == "[cut]"

    assert command.typename(flow.Flow) == "flow"
    assert command.typename(typing.Sequence[str]) == "[str]"

    assert command.typename(mitmproxy.types.Choice("foo")) == "choice"
    assert command.typename(mitmproxy.types.Path) == "path"
    assert command.typename(mitmproxy.types.Cmd) == "cmd"
Ejemplo n.º 3
0
 def get(self) -> None:
     commands = {}
     for (name, cmd) in self.master.commands.commands.items():
         commands[name] = {
             "help": cmd.help,
             "parameters": [
                 {
                     "name": param.name,
                     "type": command.typename(param.type),
                     "kind": str(param.kind),
                 }
                 for param in cmd.parameters
             ],
             "return_type": command.typename(cmd.return_type) if cmd.return_type else None,
             "signature_help": cmd.signature_help(),
         }
     self.write(commands)
Ejemplo n.º 4
0
def test_typename():
    assert command.typename(str, True) == "str"
    assert command.typename(typing.Sequence[flow.Flow], True) == "[flow]"
    assert command.typename(typing.Sequence[flow.Flow], False) == "flowspec"

    assert command.typename(command.Cuts, False) == "cutspec"
    assert command.typename(command.Cuts, True) == "[cuts]"

    assert command.typename(flow.Flow, False) == "flow"
    assert command.typename(typing.Sequence[str], False) == "[str]"

    assert command.typename(TChoice, False) == "choice"
Ejemplo n.º 5
0
def test_typename():
    assert command.typename(str, True) == "str"
    assert command.typename(typing.Sequence[flow.Flow], True) == "[flow]"
    assert command.typename(typing.Sequence[flow.Flow], False) == "flowspec"

    assert command.typename(command.Cuts, False) == "cutspec"
    assert command.typename(command.Cuts, True) == "[cuts]"

    assert command.typename(flow.Flow, False) == "flow"
    assert command.typename(typing.Sequence[str], False) == "[str]"
Ejemplo n.º 6
0
    def get_widget(self):
        parts = [("focus", ">> " if self.focused else "   "),
                 ("title", self.cmd.name)]
        if self.cmd.parameters:
            parts += [
                ("text", " "),
                ("text", " ".join(str(param)
                                  for param in self.cmd.parameters)),
            ]
        if self.cmd.return_type:
            parts += [
                ("title", " -> "),
                ("text", command.typename(self.cmd.return_type)),
            ]

        return urwid.AttrMap(urwid.Padding(urwid.Text(parts)), "text")
Ejemplo n.º 7
0
def test_typename():
    assert command.typename(str) == "str"
    assert command.typename(typing.Sequence[flow.Flow]) == "[flow]"

    assert command.typename(mitmproxy.types.Data) == "[data]"
    assert command.typename(mitmproxy.types.CutSpec) == "[cut]"

    assert command.typename(flow.Flow) == "flow"
    assert command.typename(typing.Sequence[str]) == "[str]"

    assert command.typename(mitmproxy.types.Choice("foo")) == "choice"
    assert command.typename(mitmproxy.types.Path) == "path"
    assert command.typename(mitmproxy.types.Cmd) == "cmd"

    with pytest.raises(exceptions.CommandError, match="missing type annotation"):
        command.typename(inspect._empty)
    with pytest.raises(exceptions.CommandError, match="unsupported type"):
        command.typename(None)
Ejemplo n.º 8
0
def test_typename():
    assert command.typename(str) == "str"
    assert command.typename(typing.Sequence[flow.Flow]) == "flow[]"

    assert command.typename(mitmproxy.types.Data) == "data[][]"
    assert command.typename(mitmproxy.types.CutSpec) == "cut[]"

    assert command.typename(flow.Flow) == "flow"
    assert command.typename(typing.Sequence[str]) == "str[]"

    assert command.typename(mitmproxy.types.Choice("foo")) == "choice"
    assert command.typename(mitmproxy.types.Path) == "path"
    assert command.typename(mitmproxy.types.Cmd) == "cmd"

    with pytest.raises(exceptions.CommandError,
                       match="missing type annotation"):
        command.typename(inspect._empty)
    with pytest.raises(exceptions.CommandError, match="unsupported type"):
        command.typename(None)
Ejemplo n.º 9
0
def test_typename():
    assert command.typename(str, True) == "str"
    assert command.typename(typing.Sequence[flow.Flow], True) == "[flow]"
    assert command.typename(typing.Sequence[flow.Flow], False) == "flowspec"
    assert command.typename(flow.Flow, False) == "flow"