t149.py

00001 # This file is Copyright 2003, 2006, 2007, 2009 Dean Hall.
00002 #
00003 # This file is part of the Python-on-a-Chip program.
00004 # Python-on-a-Chip is free software: you can redistribute it and/or modify
00005 # it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE Version 2.1.
00006 #
00007 # Python-on-a-Chip is distributed in the hope that it will be useful,
00008 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00009 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00010 # A copy of the GNU LESSER GENERAL PUBLIC LICENSE Version 2.1
00011 # is seen in the file COPYING up one directory from this.
00012 
00013 #
00014 # Test for Issue #149: Support the keyword del
00015 #
00016 
00017 import dict
00018 
00019 
00020 #
00021 # Tests for DELETE_SUBSCR bytecode
00022 #
00023 l = range(5)
00024 print "del l[3]"
00025 del l[3]
00026 print l
00027 assert l[3] == 4
00028 
00029 
00030 d = {}
00031 for n in range(5):
00032     d[n] = n
00033 print "del d[3]"
00034 del d[3]
00035 assert 3 not in dict.keys(d)
00036 print "d=", d
00037 
00038 
00039 #
00040 # Test for DELETE_NAME bytecode
00041 #
00042 del d
00043 assert "d" not in dict.keys(locals())
00044 print "keys(locals)=", dict.keys(locals())
00045 
00046 
00047 #
00048 # Test the DELETE_GLOBAL bytecode
00049 #
00050 def delglob():
00051     global l
00052     print "delglob's l=",l
00053     del l
00054 
00055 delglob()
00056 assert "l" not in dict.keys(globals())
00057 print "globals=", dict.keys(globals())
00058 
00059 
00060 #
00061 # Test the DELETE_FAST bytecode
00062 #
00063 def delfast():
00064     i = 42
00065     del i
00066     assert i == None
00067 
00068 delfast()
00069 
00070 #
00071 # Test the DELETE_ATTR bytecode
00072 #
00073 delglob.foo = "foo"
00074 print delglob.foo
00075 del delglob.foo
00076 print "Expect AttributeError:"
00077 print delglob.foo # Expect AttributeError (0xE5)

Generated on Mon Oct 18 07:40:47 2010 for Python-on-a-chip by  doxygen 1.5.9