def test_local_stack(): """Test the LocalStack""" ident = get_ident() ls = LocalStack() assert ident not in ls._local.__storage__ assert ls.top is None ls.push(42) assert ident in ls._local.__storage__ assert ls.top == 42 ls.push(23) assert ls.top == 23 ls.pop() assert ls.top == 42 ls.pop() assert ls.top is None assert ls.pop() is None assert ls.pop() is None proxy = ls() ls.push([1, 2]) assert proxy == [1, 2] ls.push((1, 2)) assert proxy == (1, 2) ls.pop() ls.pop() assert repr(proxy) == "<LocalProxy unbound>" assert ident not in ls._local.__storage__
def test_local_stack(): """Test the LocalStack""" ident = get_ident() ls = LocalStack() assert ident not in ls._local.__storage__ assert ls.top is None ls.push(42) assert ident in ls._local.__storage__ assert ls.top == 42 ls.push(23) assert ls.top == 23 ls.pop() assert ls.top == 42 ls.pop() assert ls.top is None assert ls.pop() is None assert ls.pop() is None proxy = ls() ls.push([1, 2]) assert proxy == [1, 2] ls.push((1, 2)) assert proxy == (1, 2) ls.pop() ls.pop() assert repr(proxy) == '<LocalProxy unbound>' assert ident not in ls._local.__storage__
def test_custom_idents(): """Local manager supports custom ident functions""" ident = 0 local = Local() stack = LocalStack() mgr = LocalManager([local, stack], ident_func=lambda: ident) local.foo = 42 stack.push({"foo": 42}) ident = 1 local.foo = 23 stack.push({"foo": 23}) ident = 0 assert local.foo == 42 assert stack.top["foo"] == 42 stack.pop() assert stack.top is None ident = 1 assert local.foo == 23 assert stack.top["foo"] == 23 stack.pop() assert stack.top is None