t202.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 202
00015 # Implement classes in the vm
00016 #
00017 
00018 
00019 print "testing Foo..."
00020 class Foo(object):
00021     def foo(self,):
00022         print "In foo."
00023 
00024 foo = Foo()
00025 foo.foo()
00026 assert type(Foo) == 0x07
00027 assert type(foo) == 0x09
00028 
00029 
00030 print "testing Bar..."
00031 class Bar(Foo):
00032     def __init__(self, val):
00033         self.v = val # STORE_ATTR for instance not yet implemented
00034 
00035     a=42
00036 
00037     def foo(self,):
00038         print "In Bar's foo."
00039 
00040 bar = Bar(99)
00041 bar.foo()
00042 assert bar.a == 42
00043 assert bar.v == 99
00044 
00045 
00046 print "Testing Baz..."
00047 class Baz(object, Bar):
00048     def foo(self,):
00049         print "In Baz's foo."
00050 baz = Baz(100)
00051 baz.foo()
00052 assert baz.a == 42
00053 assert baz.v == 100
00054 
00055 # Test how unknown attr fails
00056 #print baz.zilch # Expect AttributeError (0xE5)
00057 
00058 print "Expect TypeError:"
00059 bar = Bar() # Expect TypeError (0xED) (too few args)

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