<s> '''<STR_LIT>''' <EOL> import unittest <EOL> from typeof import TypeOf <EOL> class Parent ( object ) : <EOL> pass <EOL> class Child ( Parent ) : <EOL> pass <EOL> class DemoClass ( object ) : <EOL> string = TypeOf ( "<STR_LIT:string>" , str ) <EOL> child = TypeOf ( "<STR_LIT>" , Child ) <EOL> parent = TypeOf ( "<STR_LIT>" , Parent ) <EOL> class Test_typeof ( unittest . TestCase ) : <EOL> def test_field_access_when_not_set ( self ) : <EOL> demo = DemoClass ( ) <EOL> self . assertEqual ( None , demo . string ) <EOL> def test_field_access_when_set ( self ) : <EOL> demo = DemoClass ( ) <EOL> demo . string = '<STR_LIT>' <EOL> self . assertEqual ( '<STR_LIT>' , demo . string ) <EOL> def test_set_to_null ( self ) : <EOL> demo = DemoClass ( ) <EOL> demo . string = None <EOL> self . assertEqual ( None , demo . string ) <EOL> def test_set_to_bad_type ( self ) : <EOL> demo = DemoClass ( ) <EOL> try : <EOL> demo . string = <NUM_LIT> <EOL> self . fail ( '<STR_LIT>' ) <EOL> except AssertionError as e : <EOL> self . assertEqual ( "<STR_LIT>" , e . message ) <EOL> def test_type_hierarchy_ok ( self ) : <EOL> demo = DemoClass ( ) <EOL> demo . child = Child ( ) <EOL> demo . parent = Parent ( ) <EOL> demo . parent = Child ( ) <EOL> def test_type_hierarchy_bad ( self ) : <EOL> demo = DemoClass ( ) <EOL> try : <EOL> demo . child = Parent ( ) <EOL> self . fail ( '<STR_LIT>' ) <EOL> except AssertionError as e : <EOL> self . assertEqual ( "<STR_LIT>" , e . message ) </s>
