Example #1
0
def test_is_impure_async_fn():
    assert is_impure_async_fn(KnownValue(async_fn))
    assert not is_impure_async_fn(KnownValue(async_fn.asynq))
    assert is_impure_async_fn(KnownValue(PropertyObject.async_classmethod))
    assert not is_impure_async_fn(KnownValue(PropertyObject.async_classmethod.asynq))
    assert is_impure_async_fn(KnownValue(cached_fn))
    assert not is_impure_async_fn(KnownValue(cached_fn.asynq))
    assert is_impure_async_fn(KnownValue(proxied_fn))
    assert not is_impure_async_fn(KnownValue(proxied_fn.asynq))
    assert is_impure_async_fn(KnownValue(l0cached_async_fn))
    assert not is_impure_async_fn(KnownValue(l0cached_async_fn.asynq))
    assert is_impure_async_fn(KnownValue(PropertyObject(1).async_method))
    assert not is_impure_async_fn(KnownValue(PropertyObject(1).async_method.asynq))

    # UnboundMethodValue
    assert is_impure_async_fn(UnboundMethodValue("async_method", PropertyObject))
    assert not is_impure_async_fn(
        UnboundMethodValue("async_method", PropertyObject, "asynq")
    )
Example #2
0
def test_stringify_async_fn():
    def check(expected, val):
        assert_eq("pyanalyze.tests." + expected, _stringify_async_fn(val))

    check("async_fn", KnownValue(async_fn))
    check("async_fn." + ASYNQ_METHOD_NAME, KnownValue(async_fn.asynq))
    check(
        "PropertyObject.async_classmethod", KnownValue(PropertyObject.async_classmethod)
    )
    check(
        "PropertyObject.async_classmethod." + ASYNQ_METHOD_NAME,
        KnownValue(PropertyObject.async_classmethod.asynq),
    )
    check("cached_fn", KnownValue(cached_fn))
    check("cached_fn." + ASYNQ_METHOD_NAME, KnownValue(cached_fn.asynq))
    check("proxied_fn", KnownValue(proxied_fn))
    check("l0cached_async_fn", KnownValue(l0cached_async_fn))
    check("l0cached_async_fn." + ASYNQ_METHOD_NAME, KnownValue(l0cached_async_fn.asynq))
    check("PropertyObject.async_method", KnownValue(PropertyObject(1).async_method))
    check(
        "PropertyObject.async_method." + ASYNQ_METHOD_NAME,
        KnownValue(PropertyObject(1).async_method.asynq),
    )

    # UnboundMethodValue
    check(
        "PropertyObject.async_method",
        UnboundMethodValue("async_method", PropertyObject),
    )
    check(
        "PropertyObject.async_method.asynq",
        UnboundMethodValue("async_method", PropertyObject, "asynq"),
    )

    check(
        "Subclass.async_method", KnownValue(super(Subclass, Subclass(1)).async_method)
    )
    assert_eq(
        "super(pyanalyze.tests.Subclass, self).async_method",
        _stringify_async_fn(
            UnboundMethodValue("async_method", super(Subclass, Subclass))
        ),
    )
Example #3
0
def test_get_pure_async_equivalent():
    known_values = [
        async_fn,
        PropertyObject.async_classmethod,
        cached_fn,
        proxied_fn,
        l0cached_async_fn,
        PropertyObject(1).async_method,
    ]
    for fn in known_values:
        expected = "{}.asynq".format(_stringify_async_fn(KnownValue(fn)))
        assert_eq(expected, get_pure_async_equivalent(KnownValue(fn)))

    assert_eq(
        "pyanalyze.tests.PropertyObject.async_method.asynq",
        get_pure_async_equivalent(UnboundMethodValue("async_method", PropertyObject)),
    )
Example #4
0
 def capybara(uid):
     assert_is_value(
         PropertyObject(uid).string_property, TypedValue(str))
Example #5
0
 def get_capybara(qid):
     po = PropertyObject(qid)
     return po.prop_with_get
Example #6
0
 def tree(self):
     log = PropertyObject.async_staticmethod()
     return str(log)
Example #7
0
 def tree(self):
     PropertyObject(self.qid).prop_with_get
     return []
Example #8
0
 def capybara(aid):
     return PropertyObject.async_classmethod(aid)
Example #9
0
 def tree(self):
     z = []
     z += yield PropertyObject(self.poid).async_method.asynq()
     result(z)
Example #10
0
        class LinkImageNonLive(CheckedForAsynq):
            embed_object = property(lambda self: PropertyObject(self.lid).prop)

            def init(self, poid):
                self.poid = poid
Example #11
0
 def capybara(aid):
     po = PropertyObject(aid)
     return po.async_method()
Example #12
0
 def get_url(cls, qid):
     return PropertyObject(qid).prop
Example #13
0
 def tree(self):
     question = PropertyObject(self.qid)
     return self.get_url(question)
Example #14
0
 def tree(self):
     yield PropertyObject(self.qid).get_prop_with_get.asynq()
     result([])
Example #15
0
 def init(self, aid):
     self.answer = PropertyObject(aid)
Example #16
0
 def tree(self):
     z = []
     z += PropertyObject(self.poid).async_method()
     return z
Example #17
0
 def filter_fn(qid):
     result(
         (yield PropertyObject(qid).get_prop_with_get.asynq()) < t)
Example #18
0
 def get_capybara(qid):
     po = PropertyObject(qid)
     result((yield po.get_prop_with_get.asynq()))