| 4 | |
| 5 | |
| 6 | def test_stack_operations(): |
| 7 | s = Stack() |
| 8 | with pytest.raises(ValueError): |
| 9 | s.pop() |
| 10 | |
| 11 | with pytest.raises(KeyError): |
| 12 | _ = s['g'] |
| 13 | |
| 14 | s['g'] = 'global_value' |
| 15 | assert s['g'] == 'global_value' |
| 16 | s.push() |
| 17 | assert s['g'] == 'global_value' |
| 18 | assert s.frame.previous is not None |
| 19 | assert s.frame.previous is s.bottom |
| 20 | assert s.frame is not s.bottom |
| 21 | with pytest.raises(KeyError): |
| 22 | _ = s['x'] |
| 23 | |
| 24 | s['x'] = 'local_value' |
| 25 | assert s['x'] == 'local_value' |
| 26 | s.pop() |
| 27 | assert s.frame.previous is None |
| 28 | assert s.bottom is s.frame |
| 29 | with pytest.raises(KeyError): |
| 30 | _ = s['x'] |
| 31 | |
| 32 | |
| 33 | def test_stack_copy(): |