コード例 #1
0
def test_not_synthed():
    @t.synth()
    def synth(task):
        task.synth(t.tmpfname())
    
    t.raises(t.FileSynthError, t.app.run, None, ["synth"])
    
コード例 #2
0
def test_exp_02():
    with mock.patch.object(SyncthingClient, 'request') as mock_response:
        code = 500
        msg = 'Error occured'
        mock_response.side_effect = PySyncthingError(code=code, message=msg)
        api = SyncthingClient(TOKEN, BASE_URL)
        t.raises(PySyncthingError, api.get_version)
コード例 #3
0
ファイル: test_002_collectd.py プロジェクト: dimrozakis/bucky
def test_counter_eq_derive():
    """Test parsing of counters when expecting derives and vice versa"""

    def run_parse(parse_func):
        def wrapped(data):
            return list(parse_func(data))

        return wrapped

    types = "false_counter value:COUNTER:U:U\nfalse_derive value:DERIVE:U:U\n"
    with t.unlinking(t.temp_file(TYPESDB + types)) as path:
        parser = bucky.collectd.CollectDParser(types_dbs=[path])
        for pkts_file in ('collectd-counter.pkts', 'collectd-derive.pkts'):
            for data in pkts(pkts_file):
                t.not_raises(ProtocolError, run_parse(parser.parse), data)
        for pkts_file in ('collectd-false-counter.pkts',
                          'collectd-false-derive.pkts'):
            for data in pkts(pkts_file):
                t.raises(ProtocolError, run_parse(parser.parse), data)

        parser = bucky.collectd.CollectDParser(types_dbs=[path],
                                               counter_eq_derive=True)
        for pkts_file in ('collectd-counter.pkts', 'collectd-derive.pkts',
                          'collectd-false-counter.pkts',
                          'collectd-false-derive.pkts'):
            for data in pkts(pkts_file):
                t.not_raises(ProtocolError, run_parse(parser.parse), data)
コード例 #4
0
def test_no_underscores(cx):
    def fn(obj, name):
        return name.strip()[:1] != "_"
    cx.set_access(fn)
    cx.add_global("foo", {"bar": "baz", "_bar": "_baz"})
    t.eq(cx.execute('foo["bar"]'), "baz")
    t.raises(t.JSError, cx.execute, 'foo["_bar"]')
コード例 #5
0
def test_005(res):
    r = res.get('/json', headers={'Content-Type': 'application/json'})
    t.eq(r.status_int, 200)
    t.raises(RequestFailed,
             res.get,
             '/json',
             headers={'Content-Type': 'text/plain'})
コード例 #6
0
def test_set_item():
    fl = t.FileList("a.c", "b.c")
    fl[0] = "foo.py"
    t.eq(fl, ["foo.py", "b.c"])
    def assign():
        fl[1] = 2
    t.raises(TypeError, assign)
コード例 #7
0
ファイル: test_002_collectd.py プロジェクト: upsight/bucky
def test_counter_eq_derive():
    """Test parsing of counters when expecting derives and vice versa"""
    def run_parse(parse_func):
        def wrapped(data):
            return list(parse_func(data))

        return wrapped

    types = "false_counter value:COUNTER:U:U\nfalse_derive value:DERIVE:U:U\n"
    with t.unlinking(t.temp_file(TYPESDB + types)) as path:
        parser = bucky.collectd.CollectDParser(types_dbs=[path])
        for pkts_file in ('collectd-counter.pkts', 'collectd-derive.pkts'):
            for data in pkts(pkts_file):
                t.not_raises(ProtocolError, run_parse(parser.parse), data)
        for pkts_file in ('collectd-false-counter.pkts',
                          'collectd-false-derive.pkts'):
            for data in pkts(pkts_file):
                t.raises(ProtocolError, run_parse(parser.parse), data)

        parser = bucky.collectd.CollectDParser(types_dbs=[path],
                                               counter_eq_derive=True)
        for pkts_file in ('collectd-counter.pkts', 'collectd-derive.pkts',
                          'collectd-false-counter.pkts',
                          'collectd-false-derive.pkts'):
            for data in pkts(pkts_file):
                t.not_raises(ProtocolError, run_parse(parser.parse), data)
コード例 #8
0
def test_del_item():
    fl = t.FileList("a.c", "b.c")
    del fl[0]
    t.eq(fl[0], "b.c")
    def rem():
        del fl[2]
    t.raises(IndexError, rem)
コード例 #9
0
def test_two_task_cycle():
    t.task("foo", ["bar"])(lambda: 2)
    t.task("bar", ["foo"])(lambda: "hi")
    
    for task in ["foo", "bar"]:
        t.app.clear()
        t.raises(t.DependencyCycleError, t.app.run, None, [task])
        t.eq(t.app._dbg, [])
コード例 #10
0
def test_simple_ns():
    with t.ns("rho"):
        @t.task
        def foo():
            return 2
    t.raises(t.TaskNotFoundError, t.app.run, None, ["foo"])
    t.app.run(None, ["rho:foo"])
    t.eq(t.app._dbg, [("rho:foo", 2)])
コード例 #11
0
ファイル: 005-util-test.py プロジェクト: pombredanne/sheba
def test_date_errors():
    # Disallowed by iso8601 to avoid confusion with YYMMDD
    t.raises(FMT_ERROR, pdate, "195406")

    t.raises(FMT_ERROR, pdate, "foo")
    t.raises(FMT_ERROR, pdate, "1954-0607")
    t.raises(FMT_ERROR, pdate, "195406-07")
    t.raises(FMT_ERROR, pdate, "1954")
コード例 #12
0
def test_iter():
    fl = t.FileList("a.c", "b.c", "exist*")
    i = iter(fl)
    t.eq(isinstance(i, t.FileListIter), True)
    t.eq(i.next(), "a.c")
    t.eq(isinstance(i.next(), t.path), True)
    t.eq(i.next(), "existing")
    t.raises(StopIteration, i.next)
コード例 #13
0
def test_exp_01():
    with mock.patch.object(SyncthingClient, 'request') as mock_response:
        code = 500
        msg = 'Error occured'
        mock_response.status_int = code
        mock_response.body_string.return_value = msg
        api = SyncthingClient(TOKEN, BASE_URL)
        t.raises(PySyncthingError, api.get_version)
コード例 #14
0
def test_exceed_time(cx):
    script = """
        var time = function() {return (new Date()).getTime();};
        var start = time();
        while((time() - start) < 100000) {}
    """
    cx.max_time(1)
    t.raises(SystemError, cx.execute, script)
コード例 #15
0
def test_iter():
    fl = t.FileList("a.c", "b.c", "exist*")
    i = iter(fl)
    t.eq(isinstance(i, t.FileListIter), True)
    t.eq(i.next(), "a.c")
    t.eq(isinstance(i.next(), t.path), True)
    t.eq(i.next(), "existing")
    t.raises(StopIteration, i.next)
コード例 #16
0
def test_019(res):
    import StringIO
    content = StringIO.StringIO("test")
    t.raises(RequestFailed,
             res.post,
             '/json',
             payload=content,
             headers={'Content-Type': 'text/plain'})
コード例 #17
0
ファイル: 003-test-config.py プロジェクト: bbroad/gunicorn
def test_callable_validation():
    c = config.Config()
    def func(a, b):
        pass
    c.set("pre_fork", func)
    t.eq(c.pre_fork, func)
    t.raises(TypeError, c.set, "pre_fork", 1)
    t.raises(TypeError, c.set, "pre_fork", lambda x: True)
コード例 #18
0
def test_020():
    u = "http://*****:*****@%s:%s/auth" % (HOST, PORT)
    res = Resource(u)
    r = res.get()
    t.eq(r.status_int, 200)
    u = "http://*****:*****@%s:%s/auth" % (HOST, PORT)
    res = Resource(u)
    t.raises(Unauthorized, res.get)
コード例 #19
0
def test_exceed_time(cx):
    script = """
        var time = function() {return (new Date()).getTime();};
        var start = time();
        while((time() - start) < 100000) {}
    """
    cx.max_time(1)
    t.raises(SystemError, cx.execute, script)
コード例 #20
0
ファイル: 005-test-resource.py プロジェクト: czue/restkit
def test_020():
    u = "http://*****:*****@%s:%s/auth" % (HOST, PORT)
    res = Resource(u)
    r = res.get()
    t.eq(r.status_int, 200)
    u = "http://*****:*****@%s:%s/auth" % (HOST, PORT)
    res = Resource(u)
    t.raises(Unauthorized, res.get)
コード例 #21
0
def test_callable_validation():
    c = config.Config()
    def func(a, b):
        pass
    c.set("pre_fork", func)
    t.eq(c.pre_fork, func)
    t.raises(TypeError, c.set, "pre_fork", 1)
    t.raises(TypeError, c.set, "pre_fork", lambda x: True)
コード例 #22
0
def test_ident_unknown(conn, cursor):
    obj = {"name": "test", "sql": "select 1 as ${'zing' | ident}"}
    s = t.Statement(obj)
    t.raises(t.RenderError, s.dbs[None].prepare, conn, {})
    try:
        s.dbs[None].prepare(conn, {})
    except t.RenderError, e:
        str(e)  # Doesn't raise
コード例 #23
0
def test_dissallow_ctor(cx):
    class DirtyCar(object):
        def __init__(self):
            self.zap = 2
    def check(obj, name):
        return name != "__init__"
    cx.add_global("DirtyCar", DirtyCar)
    cx.set_access(check)
    t.raises(t.JSError, cx.execute, "DirtyCall();")
コード例 #24
0
def test_ident_no_dbinfo(conn, cursor):
    info = t.dbwrapper.DB_INFO["sqlite"]
    try:
        t.dbwrapper.DB_INFO.pop("sqlite")
        obj = {"name": "test", "sql": "select 1 as ${foo | ident}"}
        s = t.Statement(obj)
        t.raises(KeyError, s.dbs[None].prepare, conn, {"foo": "zip"})
    finally:
        t.dbwrapper.DB_INFO["sqlite"] = info
コード例 #25
0
def test_set_callback(cx):
    t.eq(cx.set_access(), None)
    t.raises(TypeError, cx.set_access, "foo")
    t.raises(TypeError, cx.set_access, 1)
    def cb(obj, name): return True
    t.eq(cx.set_access(cb), None)
    t.eq(cx.set_access(), cb)
    # Check that we don't erase it.
    t.eq(cx.set_access(), cb)
コード例 #26
0
def test_del_item():
    fl = t.FileList("a.c", "b.c")
    del fl[0]
    t.eq(fl[0], "b.c")

    def rem():
        del fl[2]

    t.raises(IndexError, rem)
コード例 #27
0
def test_no_set_invalid(cx):
    def fn(obj, name):
        return name.strip()[:1] != "_"
    cx.set_access(fn)
    glbl = {}
    cx.add_global("foo", glbl)
    cx.execute('foo["bar"] = "baz";')
    t.raises(t.JSError, cx.execute, 'foo["_bar"] = "baz"')
    t.eq(glbl, {"bar": "baz"})
コード例 #28
0
def test_set_item():
    fl = t.FileList("a.c", "b.c")
    fl[0] = "foo.py"
    t.eq(fl, ["foo.py", "b.c"])

    def assign():
        fl[1] = 2

    t.raises(TypeError, assign)
コード例 #29
0
ファイル: test_003-config.py プロジェクト: wayhome/gunicorn
def test_str_to_list_validation():
    c = config.Config()
    t.eq(c.forwarded_allow_ips, ["127.0.0.1"])
    c.set("forwarded_allow_ips", "127.0.0.1,192.168.0.1")
    t.eq(c.forwarded_allow_ips, ["127.0.0.1", "192.168.0.1"])
    c.set("forwarded_allow_ips", "")
    t.eq(c.forwarded_allow_ips, [])
    c.set("forwarded_allow_ips", None)
    t.eq(c.forwarded_allow_ips, [])
    t.raises(TypeError, c.set, "forwarded_allow_ips", 1)
コード例 #30
0
def test_adding_more_actions():
    def foo():
        return 2
    def bar():
        return "hi"
    t.task("foo")(foo)
    t.task("foo")(bar)
    t.app.run(None, ["foo"])
    t.eq(t.app._dbg, [("foo", 2), ("foo", "hi")])
    t.raises(t.TaskNotFoundError, t.app.run, None, ["bar"])
コード例 #31
0
ファイル: 002-test-aliases.py プロジェクト: akissa/BaruwaAPI
def test_get_alias(api):
    addressid = 2
    req = api.get_aliases(addressid)
    path = ENDPOINTS["aliases"]["get"]["name"] % dict(addressid=addressid)
    t.eq(api.response.final_url, "%s%s%s" % (BASE_URL, API_PATH, path))
    t.eq(api.response.request.method, ENDPOINTS["aliases"]["get"]["method"])
    t.eq(api.response.status_int, 200)
    t.eq(req["id"], addressid)
    t.eq(req["address"], "*****@*****.**")
    t.raises(BaruwaAPIError, api.get_aliases, 7)
コード例 #32
0
ファイル: 003-test-config.py プロジェクト: bbroad/gunicorn
def test_str_to_list_validation():
    c = config.Config()
    t.eq(c.forwarded_allow_ips, ["127.0.0.1"])
    c.set("forwarded_allow_ips", "127.0.0.1,192.168.0.1")
    t.eq(c.forwarded_allow_ips, ["127.0.0.1", "192.168.0.1"])
    c.set("forwarded_allow_ips", "")
    t.eq(c.forwarded_allow_ips, [])
    c.set("forwarded_allow_ips", None)
    t.eq(c.forwarded_allow_ips, [])
    t.raises(TypeError, c.set, "forwarded_allow_ips", 1)
コード例 #33
0
def test_simple_ns():
    with t.ns("rho"):

        @t.task
        def foo():
            return 2

    t.raises(t.TaskNotFoundError, t.app.run, None, ["foo"])
    t.app.run(None, ["rho:foo"])
    t.eq(t.app._dbg, [("rho:foo", 2)])
コード例 #34
0
def test_011(res):
    r = res.post('/json',
                 payload="test",
                 headers={'Content-Type': 'application/json'})
    t.eq(r.status_int, 200)
    t.raises(RequestFailed,
             res.post,
             '/json',
             payload='test',
             headers={'Content-Type': 'text/plain'})
コード例 #35
0
def test_access_global(rt):
    names = []
    def fn(obj, name):
        names.append(name)
        return not name.startswith("_")
    glbl = {"foo": "bar", "_bin": "zingle"}
    cx = rt.new_context(glbl, fn)
    t.eq(cx.execute('foo;'), "bar")
    t.raises(t.JSError, cx.execute, '_bin;')
    t.eq(names, ["foo", "foo", "_bin"])
コード例 #36
0
ファイル: 003-test-config.py プロジェクト: bbroad/gunicorn
def test_bool_validation():
    c = config.Config()
    t.eq(c.debug, False)
    c.set("debug", True)
    t.eq(c.debug, True)
    c.set("debug", "true")
    t.eq(c.debug, True)
    c.set("debug", "false")
    t.eq(c.debug, False)
    t.raises(ValueError, c.set, "debug", "zilch")
    t.raises(TypeError, c.set, "debug", 4)
コード例 #37
0
ファイル: 001-test-users.py プロジェクト: akissa/BaruwaAPI
def test_set_user_password(api):
    userid = 10
    data = {"password1": "Hp9hzcd1grdSqtrn", "password2": "Hp9hzcd1grdSqtrn"}
    data2 = {"password1": "Hp9hzcd1grdSqtrn"}
    req = api.set_user_passwd(userid, data)
    path = ENDPOINTS["users"]["password"]["name"] % dict(userid=userid)
    t.eq(api.response.final_url, "%s%s%s" % (BASE_URL, API_PATH, path))
    t.eq(api.response.request.method, ENDPOINTS["users"]["password"]["method"])
    t.eq(api.response.status_int, 204)
    t.eq(req["code"], 204)
    t.raises(BaruwaAPIError, api.set_user_passwd, userid, data2)
コード例 #38
0
ファイル: test_003-config.py プロジェクト: 1stvamp/gunicorn
def test_bool_validation():
    c = config.Config()
    t.eq(c.preload_app, False)
    c.set("preload_app", True)
    t.eq(c.preload_app, True)
    c.set("preload_app", "true")
    t.eq(c.preload_app, True)
    c.set("preload_app", "false")
    t.eq(c.preload_app, False)
    t.raises(ValueError, c.set, "preload_app", "zilch")
    t.raises(TypeError, c.set, "preload_app", 4)
コード例 #39
0
def test_bool_validation():
    c = config.Config()
    t.eq(c.debug, False)
    c.set("debug", True)
    t.eq(c.debug, True)
    c.set("debug", "true")
    t.eq(c.debug, True)
    c.set("debug", "false")
    t.eq(c.debug, False)
    t.raises(ValueError, c.set, "debug", "zilch")
    t.raises(TypeError, c.set, "debug", 4)
コード例 #40
0
ファイル: test_003-config.py プロジェクト: wayhome/gunicorn
def test_bool_validation():
    c = config.Config()
    t.eq(c.preload_app, False)
    c.set("preload_app", True)
    t.eq(c.preload_app, True)
    c.set("preload_app", "true")
    t.eq(c.preload_app, True)
    c.set("preload_app", "false")
    t.eq(c.preload_app, False)
    t.raises(ValueError, c.set, "preload_app", "zilch")
    t.raises(TypeError, c.set, "preload_app", 4)
コード例 #41
0
ファイル: test_002_collectd.py プロジェクト: upsight/bucky
def test_crypto_auth_reload():
    crypto = cfg_crypto(1, "bob: 123\n")
    signed_pkt = next(pkts('collectd-squares-signed.pkts'))
    enc_pkt = next(pkts('collectd-squares-encrypted.pkts'))
    t.raises(ProtocolError, crypto.parse, signed_pkt)
    t.raises(ProtocolError, crypto.parse, enc_pkt)
    with open(crypto.auth_file, "a") as f:
        f.write("alice: 12345678\n")
    time.sleep(1)
    t.eq(bool(crypto.parse(signed_pkt)), True)
    t.eq(bool(crypto.parse(enc_pkt)), True)
コード例 #42
0
ファイル: test_002_collectd.py プロジェクト: dimrozakis/bucky
def test_crypto_auth_reload():
    crypto = cfg_crypto(1, "bob: 123\n")
    signed_pkt = next(pkts('collectd-squares-signed.pkts'))
    enc_pkt = next(pkts('collectd-squares-encrypted.pkts'))
    t.raises(ProtocolError, crypto.parse, signed_pkt)
    t.raises(ProtocolError, crypto.parse, enc_pkt)
    with open(crypto.auth_file, "a") as f:
        f.write("alice: 12345678\n")
    time.sleep(1)
    t.eq(bool(crypto.parse(signed_pkt)), True)
    t.eq(bool(crypto.parse(enc_pkt)), True)
コード例 #43
0
ファイル: test-extract.py プロジェクト: pombredanne/nebseq
def test_bad_span_indexes():
    locs = [
        {"type": "span", "from": 10, "to": 1},
        {"type": "span", "from": 10, "to": 20},
        {"type": "span", "from": -1, "to": 10},
        {"type": "span", "from": 1, "to": 10},
        {"type": "index", "position": -1},
        {"type": "index", "position": 10}
    ]
    for l in locs:
        t.raises(IndexError, t.extract, "ACG", l)
コード例 #44
0
ファイル: 010-test-relays.py プロジェクト: akissa/BaruwaAPI
def test_get_relay(api):
    relayid = 1
    req = api.get_relay(relayid)
    path = ENDPOINTS['relays']['get']['name'] % dict(relayid=relayid)
    t.eq(
        api.response.final_url,
        '%s%s%s' % (BASE_URL, API_PATH, path))
    t.eq(api.response.request.method, ENDPOINTS['relays']['get']['method'])
    t.eq(api.response.status_int, 200)
    t.eq(req['address'], '192.168.1.20')
    t.raises(BaruwaAPIError, api.get_relay, 7)
コード例 #45
0
ファイル: 003-test-domains.py プロジェクト: akissa/BaruwaAPI
def test_get_domain(api):
    domainid = 1
    req = api.get_domain(domainid)
    path = ENDPOINTS['domains']['get']['name'] % dict(domainid=domainid)
    t.eq(
        api.response.final_url,
        '%s%s%s' % (BASE_URL, API_PATH, path))
    t.eq(api.response.request.method, ENDPOINTS['domains']['get']['method'])
    t.eq(api.response.status_int, 200)
    t.eq(req['id'], 1)
    t.eq(req['name'], 'example.com')
    t.raises(BaruwaAPIError, api.get_domain, 7)
コード例 #46
0
def test_dissalow_call(cx):
    class PepsiCan(object):
        def __init__(self):
            self.caffeine = "zaney!"
        def __call__(self, arg):
            return arg * 2
    def check(obj, name):
        return name != "__call__"
    cx.add_global("PepsiCan", PepsiCan)
    cx.set_access(check)
    t.eq(cx.execute("var c = new PepsiCan(); c.caffeine;"), "zaney!")
    t.raises(t.JSError, cx.execute, "c();")
コード例 #47
0
ファイル: 001-test-users.py プロジェクト: akissa/BaruwaAPI
def test_get_user(api):
    userid = 5
    req = api.get_user(userid)
    path = ENDPOINTS["users"]["get"]["name"] % dict(userid=userid)
    t.eq(api.response.final_url, "%s%s%s" % (BASE_URL, API_PATH, path))
    t.eq(api.response.request.method, ENDPOINTS["users"]["get"]["method"])
    t.eq(api.response.status_int, 200)
    t.isin("username", req)
    t.isin("email", req)
    t.eq(req["username"], "rowdyrough")
    t.eq(req["email"], "*****@*****.**")
    t.raises(BaruwaAPIError, api.get_user, 7)
コード例 #48
0
ファイル: 001-task-tests.py プロジェクト: joelimome/smithy
def test_adding_more_actions():
    def foo():
        return 2

    def bar():
        return "hi"

    t.task("foo")(foo)
    t.task("foo")(bar)
    t.app.run(None, ["foo"])
    t.eq(t.app._dbg, [("foo", 2), ("foo", "hi")])
    t.raises(t.TaskNotFoundError, t.app.run, None, ["bar"])
コード例 #49
0
def test_ring_cycle():
    t.task("foo")(lambda: 2)
    t.task("bar")(lambda: "hi")
    t.task("frog")(lambda: "bird")
    
    t.task("foo", ["frog"])
    t.task("bar", ["foo"])
    t.task("frog", ["bar"])

    for task in ["foo", "bar", "frog"]:
        t.app.clear()
        t.raises(t.DependencyCycleError, t.app.run, None, [task])
        t.eq(t.app._dbg, [])
コード例 #50
0
ファイル: test_003-config.py プロジェクト: wayhome/gunicorn
def test_pos_int_validation():
    c = config.Config()
    t.eq(c.workers, 1)
    c.set("workers", 4)
    t.eq(c.workers, 4)
    c.set("workers", "5")
    t.eq(c.workers, 5)
    c.set("workers", "0xFF")
    t.eq(c.workers, 255)
    c.set("workers", True)
    t.eq(c.workers, 1)  # Yes. That's right...
    t.raises(ValueError, c.set, "workers", -21)
    t.raises(TypeError, c.set, "workers", c)
コード例 #51
0
ファイル: test_002_collectd.py プロジェクト: dimrozakis/bucky
def assert_crypto(state, testfile, sec_level, auth_file):
    crypto = cfg_crypto(sec_level, auth_file)
    i = 0
    if state:
        for data in pkts(testfile):
            data = crypto.parse(data)
            t.eq(bool(data), True)
            i += 1
    else:
        for data in pkts(testfile):
            t.raises(ProtocolError, crypto.parse, data)
            i += 1
    t.eq(i, 2)
コード例 #52
0
ファイル: 003-test-config.py プロジェクト: bbroad/gunicorn
def test_pos_int_validation():
    c = config.Config()
    t.eq(c.workers, 1)
    c.set("workers", 4)
    t.eq(c.workers, 4)
    c.set("workers", "5")
    t.eq(c.workers, 5)
    c.set("workers", "0xFF")
    t.eq(c.workers, 255)
    c.set("workers", True)
    t.eq(c.workers, 1) # Yes. That's right...
    t.raises(ValueError, c.set, "workers", -21)
    t.raises(TypeError, c.set, "workers", c)
コード例 #53
0
def test_get_organization(api):
    orgid = 1
    req = api.get_organization(orgid)
    path = ENDPOINTS['organizations']['get']['name'] % dict(orgid=orgid)
    t.eq(
        api.response.final_url,
        '%s%s%s' % (BASE_URL, API_PATH, path))
    t.eq(
        api.response.request.method,
        ENDPOINTS['organizations']['get']['method'])
    t.eq(api.response.status_int, 200)
    t.eq(req['name'], 'My Org')
    t.raises(BaruwaAPIError, api.get_organization, 7)
コード例 #54
0
def test_obj_method(cx):
    class Checker(object):
        def __init__(self):
            self.names = []
        def check(self, obj, name):
            self.names.append(name)
            return name != "kablooie"
    c = Checker()
    cx.set_access(c.check)
    cx.add_global("bing", {"kablooie": "bar", "bing": 3})
    t.eq(cx.execute('bing["bing"]'), 3)
    t.raises(t.JSError, cx.execute, 'bing["kablooie"]')
    t.eq(c.names, ["bing", "kablooie"])
コード例 #55
0
ファイル: test_002_collectd.py プロジェクト: upsight/bucky
def assert_crypto(state, testfile, sec_level, auth_file):
    crypto = cfg_crypto(sec_level, auth_file)
    i = 0
    if state:
        for data in pkts(testfile):
            data = crypto.parse(data)
            t.eq(bool(data), True)
            i += 1
    else:
        for data in pkts(testfile):
            t.raises(ProtocolError, crypto.parse, data)
            i += 1
    t.eq(i, 2)
コード例 #56
0
def test_add_arrays():
    t.eq(t.FileList("a.c", "b.c") + ["foo.py"], ["a.c", "b.c", "foo.py"])
    t.eq(["foo.py"] + t.FileList("a.c", "b.c"), ["foo.py", "a.c", "b.c"])
    t.raises(TypeError, lambda: t.FileList("a.c", "b.c") + 1)
    t.raises(TypeError, lambda: t.FileList("a.c", "b.c") + [1])
    t.raises(TypeError, lambda: 1 + t.FileList("a.c", "b.c"))
    t.raises(TypeError, lambda: [1] + t.FileList("a.c", "b.c"))
コード例 #57
0
def test_on_wrapped_obj(cx):
    class ShamWow(object):
        def __init__(self):
            self.bar = 2
            self._bing = 3
    def func():
        return ShamWow()
    cx.add_global("whee", func)

    def check(obj, name):
        return name in ["__call__", "__init__"] or not name.startswith("_")
    cx.set_access(check);

    t.eq(cx.execute("var f = whee(); f.bar;"), 2)
    t.raises(t.JSError, cx.execute, "f._bing")
コード例 #58
0
ファイル: test_003-config.py プロジェクト: wayhome/gunicorn
def test_callable_validation_for_string():
    from os.path import isdir as testfunc
    t.eq(config.validate_callable(-1)("os.path.isdir"), testfunc)

    # invalid values tests
    t.raises(TypeError, config.validate_callable(-1), "")
    t.raises(TypeError, config.validate_callable(-1), "os.path.not_found_func")
    t.raises(TypeError, config.validate_callable(-1), "notfoundmodule.func")