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") )
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)) ), )
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)), )
def capybara(uid): assert_is_value( PropertyObject(uid).string_property, TypedValue(str))
def get_capybara(qid): po = PropertyObject(qid) return po.prop_with_get
def tree(self): log = PropertyObject.async_staticmethod() return str(log)
def tree(self): PropertyObject(self.qid).prop_with_get return []
def capybara(aid): return PropertyObject.async_classmethod(aid)
def tree(self): z = [] z += yield PropertyObject(self.poid).async_method.asynq() result(z)
class LinkImageNonLive(CheckedForAsynq): embed_object = property(lambda self: PropertyObject(self.lid).prop) def init(self, poid): self.poid = poid
def capybara(aid): po = PropertyObject(aid) return po.async_method()
def get_url(cls, qid): return PropertyObject(qid).prop
def tree(self): question = PropertyObject(self.qid) return self.get_url(question)
def tree(self): yield PropertyObject(self.qid).get_prop_with_get.asynq() result([])
def init(self, aid): self.answer = PropertyObject(aid)
def tree(self): z = [] z += PropertyObject(self.poid).async_method() return z
def filter_fn(qid): result( (yield PropertyObject(qid).get_prop_with_get.asynq()) < t)
def get_capybara(qid): po = PropertyObject(qid) result((yield po.get_prop_with_get.asynq()))