def test_switch2_not_initialized(self): from _continuation import continulet c0 = continulet.__new__(continulet) c0bis = continulet.__new__(continulet) res = c0.switch(123, to=c0) assert res == 123 res = c0.switch(123, to=c0bis) assert res == 123 raises(ValueError, c0.throw, ValueError, to=c0) raises(ValueError, c0.throw, ValueError, to=c0bis) # def f1(c1): c1.switch('a') raises(ValueError, c1.switch, 'b') raises(KeyError, c1.switch, 'c') return 'd' c1 = continulet(f1) res = c0.switch(to=c1) assert res == 'a' res = c1.switch(to=c0) assert res == 'b' res = c1.throw(ValueError, to=c0) assert res == 'c' res = c0.throw(KeyError, to=c1) assert res == 'd'
def test_switch2_not_initialized(self): from _continuation import continulet c0 = continulet.__new__(continulet) c0bis = continulet.__new__(continulet) res = c0.switch(123, to=c0) assert res == 123 res = c0.switch(123, to=c0bis) assert res == 123 raises(ValueError, c0.throw, ValueError, to=c0) raises(ValueError, c0.throw, ValueError, to=c0bis) # def f1(c1): c1.switch("a") raises(ValueError, c1.switch, "b") raises(KeyError, c1.switch, "c") return "d" c1 = continulet(f1) res = c0.switch(to=c1) assert res == "a" res = c1.switch(to=c0) assert res == "b" res = c1.throw(ValueError, to=c0) assert res == "c" res = c0.throw(KeyError, to=c1) assert res == "d"
def test_exc_info_save_restore(self): from _continuation import continulet import sys main = [] def f(c): print("in f... 222") try: raise ValueError('fun') except: print("333") exc_info = sys.exc_info() print("444") c17650 = continulet(h) bd50.switch(to=c17650) print("back in f...") assert exc_info == sys.exc_info() def h(c): print("in h... 555") assert sys.exc_info() == (None, None, None) print("666") main = continulet.__new__(continulet) print(111) bd50 = continulet(f) main.switch(to=bd50) print(999)
def test_bug_issue1984(self): from _continuation import continulet, error c1 = continulet.__new__(continulet) c2 = continulet(lambda g: None) continulet.switch(c1, to=c2) raises(error, continulet.switch, c1, to=c2)
def test_switch_not_initialized(self): from _continuation import continulet c0 = continulet.__new__(continulet) res = c0.switch() assert res is None res = c0.switch(123) assert res == 123 raises(ValueError, c0.throw, ValueError)
def test_pickle_continulet_empty(self): from _continuation import continulet lst = [4] co = continulet.__new__(continulet) import pickle pckl = pickle.dumps(co, self.version) print repr(pckl) co2 = pickle.loads(pckl) assert co2 is not co assert not co.is_pending() assert not co2.is_pending() # the empty unpickled coroutine can still be used: result = [5] co2.__init__(result.append) res = co2.switch() assert res is None assert result == [5, co2]
def test_pickle_continulet_empty(self): from _continuation import continulet lst = [4] co = continulet.__new__(continulet) import pickle pckl = pickle.dumps(co, self.version) print(repr(pckl)) co2 = pickle.loads(pckl) assert co2 is not co assert not co.is_pending() assert not co2.is_pending() # the empty unpickled coroutine can still be used: result = [5] co2.__init__(result.append) res = co2.switch() assert res is None assert result == [5, co2]
def test_is_pending(self): from _continuation import continulet # def switchbackonce_callback(c): assert c.is_pending() res = c.switch('a') assert res == 'b' assert c.is_pending() return 'c' # c = continulet.__new__(continulet) assert not c.is_pending() c.__init__(switchbackonce_callback) assert c.is_pending() res = c.switch() assert res == 'a' assert c.is_pending() res = c.switch('b') assert res == 'c' assert not c.is_pending()
def test_pickle_continulet_empty_subclass(self): from test_pickle_continulet import continulet, A lst = [4] co = continulet.__new__(A) co.foo = 'bar' co.bar = 'baz' import pickle pckl = pickle.dumps(co, self.version) print(repr(pckl)) co2 = pickle.loads(pckl) assert co2 is not co assert not co.is_pending() assert not co2.is_pending() assert type(co) is type(co2) is A assert co.foo == co2.foo == 'bar' assert co.bar == co2.bar == 'baz' # the empty unpickled coroutine can still be used: result = [5] co2.__init__(result.append) res = co2.switch() assert res is None assert result == [5, co2]
def test_is_pending(self): from _continuation import continulet # def switchbackonce_callback(c): assert c.is_pending() res = c.switch("a") assert res == "b" assert c.is_pending() return "c" # c = continulet.__new__(continulet) assert not c.is_pending() c.__init__(switchbackonce_callback) assert c.is_pending() res = c.switch() assert res == "a" assert c.is_pending() res = c.switch("b") assert res == "c" assert not c.is_pending()
def test_pickle_continulet_empty_subclass(self): from test_pickle_continulet import continulet, A lst = [4] co = continulet.__new__(A) co.foo = 'bar' co.bar = 'baz' import pickle pckl = pickle.dumps(co, self.version) print repr(pckl) co2 = pickle.loads(pckl) assert co2 is not co assert not co.is_pending() assert not co2.is_pending() assert type(co) is type(co2) is A assert co.foo == co2.foo == 'bar' assert co.bar == co2.bar == 'baz' # the empty unpickled coroutine can still be used: result = [5] co2.__init__(result.append) res = co2.switch() assert res is None assert result == [5, co2]
def test_permute_noninitialized(self): from _continuation import continulet, permute permute(continulet.__new__(continulet)) # ignored permute( continulet.__new__(continulet), # ignored continulet.__new__(continulet))
def test_permute_noninitialized(self): from _continuation import continulet, permute permute(continulet.__new__(continulet)) # ignored permute(continulet.__new__(continulet), # ignored continulet.__new__(continulet))