<s> from flatland . out . generic import Context , _default_context <EOL> from tests . _util import assert_raises <EOL> Nothing = object ( ) <EOL> def test_read_write_known ( ) : <EOL> ctx = Context ( ) <EOL> needle = _default_context . keys ( ) [ <NUM_LIT:0> ] <EOL> assert needle in ctx <EOL> assert ctx [ needle ] is not Nothing <EOL> ctx [ needle ] = Nothing <EOL> assert ctx [ needle ] is Nothing <EOL> def test_read_write_unknown ( ) : <EOL> ctx = Context ( ) <EOL> needle = '<STR_LIT>' <EOL> assert needle not in _default_context . keys ( ) <EOL> assert needle not in ctx <EOL> assert_raises ( KeyError , lambda : ctx [ needle ] ) <EOL> assert_raises ( KeyError , ctx . __setitem__ , needle , Nothing ) <EOL> def test_push_known ( ) : <EOL> ctx = Context ( ) <EOL> needle = _default_context . keys ( ) [ <NUM_LIT:0> ] <EOL> assert needle in ctx <EOL> assert ctx [ needle ] is not Nothing <EOL> ctx . push ( ** { needle . encode ( '<STR_LIT:ascii>' ) : Nothing } ) <EOL> assert ctx [ needle ] is Nothing <EOL> ctx . pop ( ) <EOL> assert ctx [ needle ] is not Nothing <EOL> def test_push_unknown ( ) : <EOL> ctx = Context ( ) <EOL> needle = '<STR_LIT>' <EOL> assert needle not in _default_context . keys ( ) <EOL> assert_raises ( KeyError , ctx . push , ** { needle : Nothing } ) <EOL> assert_raises ( RuntimeError , ctx . pop ) <EOL> def test_update_known ( ) : <EOL> ctx = Context ( ) <EOL> known = _default_context . keys ( ) <EOL> sentinels = [ object ( ) , object ( ) ] <EOL> iterable = [ ( known [ <NUM_LIT:0> ] , sentinels [ <NUM_LIT:0> ] ) ] <EOL> kwargs = { known [ <NUM_LIT:1> ] . encode ( '<STR_LIT:ascii>' ) : sentinels [ <NUM_LIT:1> ] } <EOL> ctx . update ( iterable , ** kwargs ) <EOL> assert ctx [ known [ <NUM_LIT:0> ] ] is sentinels [ <NUM_LIT:0> ] <EOL> assert ctx [ known [ <NUM_LIT:1> ] ] is sentinels [ <NUM_LIT:1> ] <EOL> ctx = Context ( ) <EOL> ctx . update ( iterable ) <EOL> assert ctx [ known [ <NUM_LIT:0> ] ] is sentinels [ <NUM_LIT:0> ] <EOL> ctx = Context ( ) <EOL> ctx . update ( ** kwargs ) <EOL> assert ctx [ known [ <NUM_LIT:1> ] ] is sentinels [ <NUM_LIT:1> ] <EOL> def test_update_unknown ( ) : <EOL> ctx = Context ( ) <EOL> assert u'<STR_LIT>' not in _default_context . keys ( ) <EOL> assert_raises ( KeyError , ctx . update , xyzzy = <NUM_LIT> ) <EOL> assert u'<STR_LIT>' not in ctx <EOL> def test_update_bogus ( ) : <EOL> ctx = Context ( ) <EOL> assert_raises ( TypeError , ctx . update , [ ] , [ ] ) <EOL> def test_minimum_repr_sanity ( ) : <EOL> ctx = Context ( ) <EOL> assert repr ( ctx ) <EOL> assert str ( ctx ) <EOL> def test_default_minimum_stack ( ) : <EOL> ctx = Context ( ) <EOL> assert_raises ( RuntimeError , ctx . pop ) <EOL> def test_stack_plain_push_pop ( ) : <EOL> ctx = Context ( ) <EOL> needle , initial_value = _default_context . items ( ) [ <NUM_LIT:0> ] <EOL> assert ctx [ needle ] == initial_value <EOL> ctx . push ( ) <EOL> assert ctx [ needle ] == initial_value <EOL> ctx [ needle ] = Nothing <EOL> assert ctx [ needle ] is Nothing <EOL> ctx . pop ( ) <EOL> assert ctx [ needle ] is not Nothing <EOL> assert ctx [ needle ] == initial_value <EOL> assert_raises ( RuntimeError , ctx . pop ) </s>
