t071.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 # System Test 071
00015 # Tests implementation of builtin function eval()
00016 #
00017 
00018 # Create the code image blow by following these steps::
00019 #
00020 #   >>> pic = pmImgCreator.PmImgCreator()
00021 #   >>> codestr = "import sys; sys.putb(0x34); n=42; sys.putb(0x32)"
00022 #   >>> co = compile(codestr, "", "single")
00023 #   >>> codeimg = pic.co_to_str(co)
00024 #   >>> print codeimg
00025 #
00026 
00027 # The variable "n" does not exist
00028 # "n" will be initialized by the code contained in the image below
00029 # The image below is an image of the following code snippet::
00030 #
00031 #   ipm> import sys; sys.putb(0x34); n=42; sys.putb(0x32)
00032 #
00033 img = '\nc\x00\x00\x03\x00\x04\x04\x03\x03\x00sys\x03\x04\x00putb\x03\x01\x00n\x03\x00\x00\x04\x05\x01\xff\xff\xff\xff\x00\x014\x00\x00\x00\x01*\x00\x00\x00\x012\x00\x00\x00d\x00\x00d\x01\x00k\x00\x00Z\x00\x00e\x00\x00i\x01\x00d\x02\x00\x83\x01\x00Fd\x03\x00Z\x02\x00e\x00\x00i\x01\x00d\x04\x00\x83\x01\x00Fd\x01\x00S'
00034 
00035 # Convert the image to a code object and evaluate it
00036 co = Co(img)
00037 eval(co)
00038 
00039 # Assert that "n" is now set to the predetermined value
00040 assert n == 42

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