def item_creation(options):
if not options.mutable:<EOL><INDENT>mapping = options.constructor()<EOL>try:<EOL><INDENT>mapping.foo = '<STR_LIT:bar>'<EOL><DEDENT>except TypeError:<EOL><INDENT>pass  <EOL><DEDENT>else:<EOL><INDENT>pass  <EOL><DEDENT>def item():<EOL><INDENT>"""<STR_LIT>"""<EOL>mapping['<STR_LIT:foo>'] = '<STR_LIT:bar>'<EOL><DEDENT>assert_raises(TypeError, item)<EOL>assert_false('<STR_LIT:foo>' in mapping)<EOL><DEDENT>else:<EOL><INDENT>mapping = options.constructor()<EOL>mapping.foo = '<STR_LIT:bar>'<EOL>assert_equals(mapping.foo, '<STR_LIT:bar>')<EOL>assert_equals(mapping['<STR_LIT:foo>'], '<STR_LIT:bar>')<EOL>assert_equals(mapping('<STR_LIT:foo>'), '<STR_LIT:bar>')<EOL>assert_equals(mapping.get('<STR_LIT:foo>'), '<STR_LIT:bar>')<EOL>mapping['<STR_LIT>'] = '<STR_LIT>'<EOL>assert_equals(mapping.baz, '<STR_LIT>')<EOL>assert_equals(mapping['<STR_LIT>'], '<STR_LIT>')<EOL>assert_equals(mapping('<STR_LIT>'), '<STR_LIT>')<EOL>assert_equals(mapping.get('<STR_LIT>'), '<STR_LIT>')<EOL>assert_raises(TypeError, setattr, mapping, <NUM_LIT:1>, '<STR_LIT>')<EOL>assert_true(<NUM_LIT:1> not in mapping)<EOL>mapping[<NUM_LIT:2>] = '<STR_LIT>'<EOL>assert_equals(mapping[<NUM_LIT:2>], '<STR_LIT>')<EOL>assert_equals(mapping(<NUM_LIT:2>), '<STR_LIT>')<EOL>assert_equals(mapping.get(<NUM_LIT:2>), '<STR_LIT>')<EOL>def add_foo():<EOL><INDENT>"<STR_LIT>"<EOL>mapping._foo = '<STR_LIT>'<EOL><DEDENT>assert_raises(TypeError, add_foo)<EOL>assert_false('<STR_LIT>' in mapping)<EOL>mapping['<STR_LIT>'] = '<STR_LIT>'<EOL>def get_baz():<EOL><INDENT>"<STR_LIT>"<EOL>return mapping._baz<EOL><DEDENT>assert_raises(AttributeError, get_baz)<EOL>assert_equals(mapping['<STR_LIT>'], '<STR_LIT>')<EOL>assert_equals(mapping('<STR_LIT>'), '<STR_LIT>')<EOL>assert_equals(mapping.get('<STR_LIT>'), '<STR_LIT>')<EOL>def add_get():<EOL><INDENT>"<STR_LIT>"<EOL>mapping.get = '<STR_LIT>'<EOL><DEDENT>assert_raises(TypeError, add_get)<EOL>assert_false('<STR_LIT>' in mapping)<EOL>mapping['<STR_LIT>'] = '<STR_LIT:value>'<EOL>assert_not_equals(mapping.get, '<STR_LIT:value>')<EOL>assert_equals(mapping['<STR_LIT>'], '<STR_LIT:value>')<EOL>assert_equals(mapping('<STR_LIT>'), '<STR_LIT:value>')<EOL>assert_equals(mapping.get('<STR_LIT>'), '<STR_LIT:value>')<EOL>mapping.foo = '<STR_LIT>'<EOL>assert_equals(mapping.foo, '<STR_LIT>')<EOL>assert_equals(mapping['<STR_LIT:foo>'], '<STR_LIT>')<EOL>assert_equals(mapping('<STR_LIT:foo>'), '<STR_LIT>')<EOL>assert_equals(mapping.get('<STR_LIT:foo>'), '<STR_LIT>')<EOL>mapping['<STR_LIT:bar>'] = '<STR_LIT>'<EOL>assert_equals(mapping.bar, '<STR_LIT>')<EOL>assert_equals(mapping['<STR_LIT:bar>'], '<STR_LIT>')<EOL>assert_equals(mapping('<STR_LIT:bar>'), '<STR_LIT>')<EOL>assert_equals(mapping.get('<STR_LIT:bar>'), '<STR_LIT>')<EOL>if options.recursive:<EOL><INDENT>recursed = options.constructor({'<STR_LIT:foo>': {'<STR_LIT:bar>': '<STR_LIT>'}})<EOL>recursed.foo.bar = '<STR_LIT>'<EOL>recursed.foo.alpha = '<STR_LIT>'<EOL>assert_equals(recursed, {'<STR_LIT:foo>': {'<STR_LIT:bar>': '<STR_LIT>', '<STR_LIT>': '<STR_LIT>'}})<EOL><DEDENT><DEDENT>
Add a key-value pair to an {cls}