def context_2(): try: s = get_current_store() except ContextError: values.append('error') else: values.append(s) with store_context(store_2): values.append(get_current_store())
def test_store_context(): path = tempfile.mkdtemp() store = FileSystemStore(path, 'http://localhost/') with raises(ContextError): get_current_store() with raises(ContextError): current_store.get_current_object() store2 = Store() with store_context(store) as s: assert s is store assert get_current_store() is store assert current_store == store with store_context(store2) as s2: assert s2 is store2 assert get_current_store() is store2 assert current_store == store2 with store_context(store) as s3: assert s3 is store assert get_current_store() is store assert current_store == store assert s2 is store2 assert get_current_store() is store2 assert current_store == store2 assert s is store assert get_current_store() is store assert current_store == store with raises(ContextError): get_current_store() with raises(ContextError): current_store.get_current_object() shutil.rmtree(path)
def context_1(): try: s = get_current_store() except ContextError: values.append('error') else: values.append(s) with store_context(store_1): values.append(get_current_store()) greenlet_2.switch() values.append(get_current_store()) try: s = get_current_store() except ContextError: values.append('error') else: values.append(s)
def context_1(): try: s = get_current_store() except ContextError: values.append('error') else: values.append(s) with store_context(store_1): values.append(get_current_store()) thread_2.start() thread_2.join() values.append(get_current_store()) try: s = get_current_store() except ContextError: values.append('error') else: values.append(s)
def context_1(channel, join_channel): try: s = get_current_store() except ContextError: values.append('error') else: values.append(s) with store_context(store_1): values.append(get_current_store()) task_2(channel) channel.receive() values.append(get_current_store()) try: s = get_current_store() except ContextError: values.append('error') else: values.append(s) join_channel.send(None)
def test_push_pop(): store_1 = Store() store_2 = Store() with raises(ContextError): get_current_store() push_store_context(store_1) assert get_current_store() is store_1 push_store_context(store_2) assert get_current_store() is store_2 pop_store_context() assert get_current_store() is store_1 pop_store_context() with raises(ContextError): get_current_store()