• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python tutils.raises函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中mitmproxy.test.tutils.raises函数的典型用法代码示例。如果您正苦于以下问题:Python raises函数的具体用法?Python raises怎么用?Python raises使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了raises函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_always_bytes

def test_always_bytes():
    assert strutils.always_bytes(bytes(range(256))) == bytes(range(256))
    assert strutils.always_bytes("foo") == b"foo"
    with tutils.raises(ValueError):
        strutils.always_bytes(u"\u2605", "ascii")
    with tutils.raises(TypeError):
        strutils.always_bytes(42, "ascii")
开发者ID:MatthewShao,项目名称:mitmproxy,代码行数:7,代码来源:test_strutils.py


示例2: test_options

def test_options():
    o = TO(two="three")
    assert o.keys() == set(["one", "two"])

    assert o.one is None
    assert o.two == "three"
    o.one = "one"
    assert o.one == "one"

    with tutils.raises(TypeError):
        TO(nonexistent = "value")
    with tutils.raises("no such option"):
        o.nonexistent = "value"
    with tutils.raises("no such option"):
        o.update(nonexistent = "value")

    rec = []

    def sub(opts, updated):
        rec.append(copy.copy(opts))

    o.changed.connect(sub)

    o.one = "ninety"
    assert len(rec) == 1
    assert rec[-1].one == "ninety"

    o.update(one="oink")
    assert len(rec) == 2
    assert rec[-1].one == "oink"
开发者ID:dwfreed,项目名称:mitmproxy,代码行数:30,代码来源:test_optmanager.py


示例3: test_writer_flush_error

 def test_writer_flush_error(self):
     s = BytesIO()
     s = tcp.Writer(s)
     o = mock.MagicMock()
     o.flush = mock.MagicMock(side_effect=socket.error)
     s.o = o
     tutils.raises(exceptions.TcpDisconnect, s.flush)
开发者ID:dwfreed,项目名称:mitmproxy,代码行数:7,代码来源:test_tcp.py


示例4: test_bidi

def test_bidi():
    b = bidi.BiDi(a=1, b=2)
    assert b.a == 1
    assert b.get_name(1) == "a"
    assert b.get_name(5) is None
    tutils.raises(AttributeError, getattr, b, "c")
    tutils.raises(ValueError, bidi.BiDi, one=1, two=1)
开发者ID:MatthewShao,项目名称:mitmproxy,代码行数:7,代码来源:test_types_bidi.py


示例5: test_connect_err

 def test_connect_err(self):
     tutils.raises(
         exceptions.HttpException,
         self.pathoc,
         [r"get:'http://foo.com/p/202':da"],
         connect_to=("localhost", self.d.port)
     )
开发者ID:dwfreed,项目名称:mitmproxy,代码行数:7,代码来源:test_pathod.py


示例6: test_timeout

 def test_timeout(self):
     # FIXME: Add float values to spec language, reduce test timeout to
     # increase test performance
     # This is a bodge - we have some platform difference that causes
     # different exceptions to be raised here.
     tutils.raises(Exception, self.pathoc, ["get:/:p1,1"])
     assert self.d.last_log()["type"] == "timeout"
开发者ID:dwfreed,项目名称:mitmproxy,代码行数:7,代码来源:test_pathod.py


示例7: test_replay

    def test_replay(self):
        o = dump.Options(server_replay=["nonexistent"], replay_kill_extra=True)
        tutils.raises(exceptions.OptionsError, dump.DumpMaster, o, proxy.DummyServer())

        with tutils.tmpdir() as t:
            p = os.path.join(t, "rep")
            self.flowfile(p)

            o = dump.Options(server_replay=[p], replay_kill_extra=True)
            o.verbosity = 0
            o.flow_detail = 0
            m = dump.DumpMaster(o, proxy.DummyServer())

            self.cycle(m, b"content")
            self.cycle(m, b"content")

            o = dump.Options(server_replay=[p], replay_kill_extra=False)
            o.verbosity = 0
            o.flow_detail = 0
            m = dump.DumpMaster(o, proxy.DummyServer())
            self.cycle(m, b"nonexistent")

            o = dump.Options(client_replay=[p], replay_kill_extra=False)
            o.verbosity = 0
            o.flow_detail = 0
            m = dump.DumpMaster(o, proxy.DummyServer())
开发者ID:YangjunZ,项目名称:mitmproxy,代码行数:26,代码来源:test_dump.py


示例8: test_config

 def test_config(self):
     sc = stickycookie.StickyCookie()
     o = options.Options(stickycookie = "~b")
     tutils.raises(
         "invalid filter",
         sc.configure, o, o.keys()
     )
开发者ID:YangjunZ,项目名称:mitmproxy,代码行数:7,代码来源:test_stickycookie.py


示例9: test_read_chunked

def test_read_chunked():
    req = treq(content=None)
    req.headers["Transfer-Encoding"] = "chunked"

    data = b"1\r\na\r\n0\r\n"
    with raises(exceptions.HttpSyntaxException):
        b"".join(_read_chunked(BytesIO(data)))

    data = b"1\r\na\r\n0\r\n\r\n"
    assert b"".join(_read_chunked(BytesIO(data))) == b"a"

    data = b"\r\n\r\n1\r\na\r\n1\r\nb\r\n0\r\n\r\n"
    assert b"".join(_read_chunked(BytesIO(data))) == b"ab"

    data = b"\r\n"
    with raises("closed prematurely"):
        b"".join(_read_chunked(BytesIO(data)))

    data = b"1\r\nfoo"
    with raises("malformed chunked body"):
        b"".join(_read_chunked(BytesIO(data)))

    data = b"foo\r\nfoo"
    with raises(exceptions.HttpSyntaxException):
        b"".join(_read_chunked(BytesIO(data)))

    data = b"5\r\naaaaa\r\n0\r\n\r\n"
    with raises("too large"):
        b"".join(_read_chunked(BytesIO(data), limit=2))
开发者ID:MatthewShao,项目名称:mitmproxy,代码行数:29,代码来源:test_read.py


示例10: test_configure

def test_configure():
    up = proxyauth.ProxyAuth()
    with taddons.context() as ctx:
        tutils.raises(
            exceptions.OptionsError,
            ctx.configure, up, auth_singleuser="foo"
        )

        ctx.configure(up, auth_singleuser="foo:bar")
        assert up.singleuser == ["foo", "bar"]

        ctx.configure(up, auth_singleuser=None)
        assert up.singleuser is None

        ctx.configure(up, auth_nonanonymous=True)
        assert up.nonanonymous
        ctx.configure(up, auth_nonanonymous=False)
        assert not up.nonanonymous

        tutils.raises(
            exceptions.OptionsError,
            ctx.configure,
            up,
            auth_htpasswd = tutils.test_data.path(
                "mitmproxy/net/data/server.crt"
            )
        )
        tutils.raises(
            exceptions.OptionsError,
            ctx.configure,
            up,
            auth_htpasswd = "nonexistent"
        )

        ctx.configure(
            up,
            auth_htpasswd = tutils.test_data.path(
                "mitmproxy/net/data/htpasswd"
            )
        )
        assert up.htpasswd
        assert up.htpasswd.check_password("test", "test")
        assert not up.htpasswd.check_password("test", "foo")
        ctx.configure(up, auth_htpasswd = None)
        assert not up.htpasswd

        tutils.raises(
            exceptions.OptionsError,
            ctx.configure,
            up,
            auth_nonanonymous = True,
            mode = "transparent"
        )
        tutils.raises(
            exceptions.OptionsError,
            ctx.configure,
            up,
            auth_nonanonymous = True,
            mode = "socks5"
        )
开发者ID:YangjunZ,项目名称:mitmproxy,代码行数:60,代码来源:test_proxyauth.py


示例11: test_no_script_file

    def test_no_script_file(self):
        with tutils.raises("not found"):
            script.parse_command("notfound")

        with tutils.tmpdir() as dir:
            with tutils.raises("not a file"):
                script.parse_command(dir)
开发者ID:f0r34chb3t4,项目名称:mitmproxy,代码行数:7,代码来源:test_script.py


示例12: test_serialize

def test_serialize():
    o = TD2()
    o.three = "set"
    assert "dfour" in o.serialize(None, defaults=True)

    data = o.serialize(None)
    assert "dfour" not in data

    o2 = TD2()
    o2.load(data)
    assert o2 == o

    t = """
        unknown: foo
    """
    data = o.serialize(t)
    o2 = TD2()
    o2.load(data)
    assert o2 == o

    t = "invalid: foo\ninvalid"
    tutils.raises("config error", o2.load, t)

    t = "invalid"
    tutils.raises("config error", o2.load, t)

    t = ""
    o2.load(t)
开发者ID:dwfreed,项目名称:mitmproxy,代码行数:28,代码来源:test_optmanager.py


示例13: test_reader_read_error

 def test_reader_read_error(self):
     s = BytesIO(b"foobar\nfoobar")
     s = tcp.Reader(s)
     o = mock.MagicMock()
     o.read = mock.MagicMock(side_effect=socket.error)
     s.o = o
     tutils.raises(exceptions.TcpDisconnect, s.read, 10)
开发者ID:dwfreed,项目名称:mitmproxy,代码行数:7,代码来源:test_tcp.py


示例14: test_intfield

def test_intfield():
    class TT(base.IntField):
        preamble = "t"
        names = {
            "one": 1,
            "two": 2,
            "three": 3
        }
        max = 4
    e = TT.expr()

    v = e.parseString("tone")[0]
    assert v.value == 1
    assert v.spec() == "tone"
    assert v.values(language.Settings())

    v = e.parseString("t1")[0]
    assert v.value == 1
    assert v.spec() == "t1"

    v = e.parseString("t4")[0]
    assert v.value == 4
    assert v.spec() == "t4"

    tutils.raises("can't exceed", e.parseString, "t5")
开发者ID:YangjunZ,项目名称:mitmproxy,代码行数:25,代码来源:test_language_base.py


示例15: test_client_greeting_assert_socks5

def test_client_greeting_assert_socks5():
    raw = tutils.treader(b"\x00\x00")
    msg = socks.ClientGreeting.from_file(raw)
    tutils.raises(socks.SocksError, msg.assert_socks5)

    raw = tutils.treader(b"HTTP/1.1 200 OK" + b" " * 100)
    msg = socks.ClientGreeting.from_file(raw)
    try:
        msg.assert_socks5()
    except socks.SocksError as e:
        assert "Invalid SOCKS version" in str(e)
        assert "HTTP" not in str(e)
    else:
        assert False

    raw = tutils.treader(b"GET / HTTP/1.1" + b" " * 100)
    msg = socks.ClientGreeting.from_file(raw)
    try:
        msg.assert_socks5()
    except socks.SocksError as e:
        assert "Invalid SOCKS version" in str(e)
        assert "HTTP" in str(e)
    else:
        assert False

    raw = tutils.treader(b"XX")
    tutils.raises(
        socks.SocksError,
        socks.ClientGreeting.from_file,
        raw,
        fail_early=True)
开发者ID:MatthewShao,项目名称:mitmproxy,代码行数:31,代码来源:test_socks.py


示例16: test_simple

def test_simple():
    r = intercept.Intercept()
    with taddons.context(options=Options()) as tctx:
        assert not r.filt
        tctx.configure(r, intercept="~q")
        assert r.filt
        tutils.raises(
            exceptions.OptionsError,
            tctx.configure,
            r,
            intercept="~~"
        )
        tctx.configure(r, intercept=None)
        assert not r.filt

        tctx.configure(r, intercept="~s")

        f = tflow.tflow(resp=True)
        tctx.cycle(r, f)
        assert f.intercepted

        f = tflow.tflow(resp=False)
        tctx.cycle(r, f)
        assert not f.intercepted

        f = tflow.tflow(resp=True)
        f.reply._state = "handled"
        r.response(f)
        assert f.intercepted
开发者ID:YangjunZ,项目名称:mitmproxy,代码行数:29,代码来源:test_intercept.py


示例17: test_echo

 def test_echo(self):
     c = tcp.TCPClient(("127.0.0.1", self.port))
     with c.connect():
         c.convert_to_ssl()
         # Exercise SSL.SysCallError
         c.rfile.read(10)
         c.close()
         tutils.raises(exceptions.TcpDisconnect, c.wfile.write, b"foo")
开发者ID:dwfreed,项目名称:mitmproxy,代码行数:8,代码来源:test_tcp.py


示例18: test_parse_setheaders

 def test_parse_setheaders(self):
     x = setheaders.parse_setheader("/foo/bar/voing")
     assert x == ("foo", "bar", "voing")
     x = setheaders.parse_setheader("/foo/bar/vo/ing/")
     assert x == ("foo", "bar", "vo/ing/")
     x = setheaders.parse_setheader("/bar/voing")
     assert x == (".*", "bar", "voing")
     tutils.raises("invalid replacement", setheaders.parse_setheader, "/")
开发者ID:dwfreed,项目名称:mitmproxy,代码行数:8,代码来源:test_setheaders.py


示例19: test_config

def test_config():
    s = serverplayback.ServerPlayback()
    with tutils.tmpdir() as p:
        with taddons.context() as tctx:
            fpath = os.path.join(p, "flows")
            tdump(fpath, [tflow.tflow(resp=True)])
            tctx.configure(s, server_replay = [fpath])
            tutils.raises(exceptions.OptionsError, tctx.configure, s, server_replay = [p])
开发者ID:YangjunZ,项目名称:mitmproxy,代码行数:8,代码来源:test_serverplayback.py


示例20: test_clientcert_err

 def test_clientcert_err(self):
     c = tcp.TCPClient(("127.0.0.1", self.port))
     with c.connect():
         tutils.raises(
             exceptions.TlsException,
             c.convert_to_ssl,
             cert=tutils.test_data.path("mitmproxy/net/data/clientcert/make")
         )
开发者ID:dwfreed,项目名称:mitmproxy,代码行数:8,代码来源:test_tcp.py



注:本文中的mitmproxy.test.tutils.raises函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python tutils.tmpdir函数代码示例发布时间:2022-05-27
下一篇:
Python tflow.tserver_conn函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap