<s> """<STR_LIT>""" <EOL> import __builtin__ <EOL> import types <EOL> import unittest <EOL> from java . lang import Object <EOL> from test import test_support <EOL> class ClassGeneralTestCase ( unittest . TestCase ) : <EOL> TE_MSG = "<STR_LIT>" <EOL> def test_dunder_module ( self ) : <EOL> self . assertEqual ( str . __module__ , '<STR_LIT>' ) <EOL> class Foo : <EOL> pass <EOL> Fu = types . ClassType ( '<STR_LIT>' , ( ) , { } ) <EOL> for cls in Foo , Fu : <EOL> self . assert_ ( '<STR_LIT>' in cls . __dict__ ) <EOL> self . assertEqual ( cls . __module__ , __name__ ) <EOL> self . assertEqual ( str ( cls ) , '<STR_LIT>' % ( __name__ , cls . __name__ ) ) <EOL> self . assert_ ( repr ( cls ) . startswith ( '<STR_LIT>' % <EOL> ( __name__ , cls . __name__ ) ) ) <EOL> obj = cls ( ) <EOL> self . assert_ ( str ( obj ) . startswith ( '<STR_LIT>' % <EOL> ( __name__ , cls . __name__ ) ) ) <EOL> class Bar ( object ) : <EOL> pass <EOL> class Baz ( Object ) : <EOL> pass <EOL> Bang = type ( '<STR_LIT>' , ( ) , { } ) <EOL> for cls in Bar , Baz , Bang : <EOL> self . assert_ ( '<STR_LIT>' in cls . __dict__ ) <EOL> self . assertEqual ( cls . __module__ , __name__ ) <EOL> self . assertEqual ( str ( cls ) , "<STR_LIT>" % ( __name__ , cls . __name__ ) ) <EOL> self . assertEqual ( repr ( cls ) , "<STR_LIT>" % ( __name__ , cls . __name__ ) ) <EOL> self . assert_ ( str ( Bar ( ) ) . startswith ( '<STR_LIT>' % __name__ ) ) <EOL> self . assert_ ( str ( Baz ( ) ) . startswith ( "<STR_LIT>" % __name__ ) ) <EOL> def test_builtin_attributes ( self ) : <EOL> for attr , val in dict ( __name__ = '<STR_LIT:foo>' , __module__ = '<STR_LIT:bar>' , __dict__ = { } , <EOL> __flags__ = <NUM_LIT:1> , __base__ = object , <EOL> __bases__ = ( unicode , object ) , <EOL> __mro__ = ( unicode , object ) ) . iteritems ( ) : <EOL> try : <EOL> setattr ( str , attr , val ) <EOL> except TypeError , te : <EOL> self . assertEqual ( str ( te ) , self . TE_MSG ) <EOL> else : <EOL> self . assert_ ( False , <EOL> '<STR_LIT>' % attr ) <EOL> try : <EOL> delattr ( str , attr ) <EOL> except TypeError , te : <EOL> self . assertEqual ( str ( te ) , self . TE_MSG ) <EOL> else : <EOL> self . assert_ ( False , <EOL> '<STR_LIT>' % attr ) <EOL> def test_attributes ( self ) : <EOL> class Foo ( object ) : <EOL> pass <EOL> Foo . __name__ = '<STR_LIT>' <EOL> self . assertEqual ( Foo . __name__ , '<STR_LIT>' ) <EOL> try : <EOL> del Foo . __name__ <EOL> except TypeError , te : <EOL> self . assertEqual ( str ( te ) , "<STR_LIT>" ) <EOL> else : <EOL> self . assert_ ( False , '<STR_LIT>' ) <EOL> Foo . __module__ = '<STR_LIT>' <EOL> self . assertEqual ( Foo . __module__ , '<STR_LIT>' ) <EOL> try : <EOL> del Foo . __module__ <EOL> except TypeError , te : <EOL> self . assertEqual ( str ( te ) , "<STR_LIT>" ) <EOL> else : <EOL> self . assert_ ( False , '<STR_LIT>' ) <EOL> try : <EOL> Foo . __dict__ = { } <EOL> except AttributeError , ae : <EOL> self . assertEqual ( str ( ae ) , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> else : <EOL> self . assert_ ( False , '<STR_LIT>' ) <EOL> try : <EOL> del Foo . __dict__ <EOL> except AttributeError , ae : <EOL> self . assertEqual ( str ( ae ) , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> else : <EOL> self . assert_ ( False , '<STR_LIT>' ) <EOL> for attr , val in dict ( __flags__ = <NUM_LIT:1> , __base__ = object , <EOL> __bases__ = ( unicode , object ) , <EOL> __mro__ = ( unicode , object ) ) . iteritems ( ) : <EOL> try : <EOL> setattr ( str , attr , val ) <EOL> except TypeError , te : <EOL> self . assertEqual ( str ( te ) , self . TE_MSG ) <EOL> else : <EOL> self . assert_ ( False , <EOL> '<STR_LIT>' % attr ) <EOL> try : <EOL> delattr ( str , attr ) <EOL> except TypeError , te : <EOL> self . assertEqual ( str ( te ) , self . TE_MSG ) <EOL> else : <EOL> self . assert_ ( False , <EOL> '<STR_LIT>' % attr ) <EOL> def test_newstyle_new_classobj ( self ) : <EOL> class Foo ( object ) : <EOL> pass <EOL> def hello ( self ) : <EOL> return '<STR_LIT:hello>' <EOL> Bar = types . ClassType ( '<STR_LIT>' , ( Foo , ) , dict ( hello = hello ) ) <EOL> self . assert_ ( type ( Bar ) , type ) <EOL> self . assert_ ( issubclass ( Bar , Foo ) ) <EOL> self . assert_ ( hasattr ( Bar , '<STR_LIT:hello>' ) ) <EOL> self . assertEquals ( Bar ( ) . hello ( ) , '<STR_LIT:hello>' ) <EOL> def test_attribute_error_message ( self ) : <EOL> class Bar : <EOL> pass <EOL> try : <EOL> Bar . bar <EOL> self . _assert ( False ) <EOL> except AttributeError , e : <EOL> self . assertEqual ( "<STR_LIT>" , str ( e ) ) <EOL> class Foo ( object ) : <EOL> pass <EOL> try : <EOL> Foo . bar <EOL> self . _assert ( False ) <EOL> except AttributeError , e : <EOL> self . assertEqual ( "<STR_LIT>" , <EOL> str ( e ) ) <EOL> def test_inner_class_dict ( self ) : <EOL> class z : <EOL> class t : <EOL> def moo ( self ) : <EOL> pass <EOL> keys = list ( z . t . __dict__ ) <EOL> keys . sort ( ) <EOL> self . assertEqual ( str ( keys ) , "<STR_LIT>" ) <EOL> def test_metaclass_and_slotted_base ( self ) : <EOL> class Meta ( type ) : <EOL> pass <EOL> class SlottedBase ( object ) : <EOL> __slots__ = '<STR_LIT:foo>' <EOL> class Bar ( SlottedBase ) : <EOL> __metaclass__ = Meta <EOL> def test_slotted_diamond_problem_bug ( self ) : <EOL> class A ( object ) : <EOL> __slots__ = '<STR_LIT:foo>' <EOL> class B ( A ) : <EOL> pass <EOL> class C ( A ) : <EOL> pass <EOL> class D ( B , C ) : <EOL> pass <EOL> def test_getitem_exceptions ( self ) : <EOL> class A : <EOL> def __getitem__ ( self , key ) : <EOL> raise IndexError , "<STR_LIT>" <EOL> self . assertRaises ( IndexError , A ( ) . __getitem__ , '<STR_LIT:b>' ) <EOL> def test_winning_metatype ( self ) : <EOL> class Meta ( type ) : <EOL> def __new__ ( cls , name , bases , attrs ) : <EOL> attrs [ '<STR_LIT>' ] = name <EOL> attrs [ '<STR_LIT>' ] = <NUM_LIT:0> <EOL> return type . __new__ ( cls , name , bases , attrs ) <EOL> def __init__ ( cls , name , bases , attrs ) : <EOL> cls . counter += <NUM_LIT:1> <EOL> class Base ( object ) : <EOL> __metaclass__ = Meta <EOL> Foo = type ( '<STR_LIT>' , ( Base , ) , { } ) <EOL> self . assertEqual ( Foo . spam , '<STR_LIT>' ) <EOL> self . assertEqual ( Foo . counter , <NUM_LIT:1> ) <EOL> class ClassNamelessModuleTestCase ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> global __name__ <EOL> self . name = __name__ <EOL> del __name__ <EOL> def tearDown ( self ) : <EOL> global __name__ <EOL> __name__ = self . name <EOL> def test_nameless_module ( self ) : <EOL> class Foo : <EOL> pass <EOL> self . assertEqual ( Foo . __module__ , '<STR_LIT>' ) <EOL> self . assertEqual ( str ( Foo ) , '<STR_LIT>' ) <EOL> self . assert_ ( repr ( Foo ) . startswith ( '<STR_LIT>' ) ) <EOL> foo = Foo ( ) <EOL> self . assert_ ( str ( foo ) . startswith ( '<STR_LIT>' ) ) <EOL> class Bar ( object ) : <EOL> pass <EOL> self . assertEqual ( Bar . __module__ , '<STR_LIT>' ) <EOL> self . assertEqual ( str ( Bar ) , "<STR_LIT>" ) <EOL> self . assertEqual ( repr ( Bar ) , "<STR_LIT>" ) <EOL> bar = Bar ( ) <EOL> self . assert_ ( str ( bar ) . startswith ( '<STR_LIT>' ) ) <EOL> self . assert_ ( repr ( bar ) . startswith ( '<STR_LIT>' ) ) <EOL> class BrokenNameTestCase ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> global __name__ <EOL> self . name = __name__ <EOL> self . builtin_name = __builtin__ . __name__ <EOL> del __name__ <EOL> del __builtin__ . __name__ <EOL> def tearDown ( self ) : <EOL> global __name__ <EOL> __builtin__ . __name__ = self . builtin_name <EOL> __name__ = self . name <EOL> def test_broken_name ( self ) : <EOL> try : <EOL> class Foobar : <EOL> pass <EOL> except NameError : <EOL> pass <EOL> else : <EOL> self . assert_ ( False , "<STR_LIT>" ) <EOL> class ClassLocalsTestCase ( unittest . TestCase ) : <EOL> def test_class_locals ( self ) : <EOL> class Foo ( object ) : <EOL> pass <EOL> class Bar ( object ) : <EOL> foo = Foo ( ) <EOL> self . assert_ ( not hasattr ( Bar , '<STR_LIT>' ) ) <EOL> class Bar2 ( object ) : <EOL> foo = Foo ( ) <EOL> locals ( ) <EOL> self . assert_ ( hasattr ( Bar2 , '<STR_LIT>' ) ) <EOL> def test_class_locals_realworld ( self ) : <EOL> class FieldGathererMeta ( type ) : <EOL> def __new__ ( meta , name , bases , class_dict ) : <EOL> cls = type . __new__ ( meta , name , bases , class_dict ) <EOL> cls . fields = [ field . upper ( ) for field in class_dict . iterkeys ( ) if not field . startswith ( '<STR_LIT:_>' ) ] <EOL> cls . fields . sort ( ) <EOL> return cls <EOL> class SomeClass ( object ) : <EOL> pass <EOL> class MyFields ( object ) : <EOL> __metaclass__ = FieldGathererMeta <EOL> jython = '<STR_LIT:foo>' <EOL> java = ( '<STR_LIT:bar>' , SomeClass ( ) ) <EOL> self . assertEqual ( MyFields . fields , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> class MyFields2 ( object ) : <EOL> __metaclass__ = FieldGathererMeta <EOL> jython = '<STR_LIT:foo>' <EOL> java = ( '<STR_LIT:bar>' , SomeClass ( ) ) <EOL> locals ( ) <EOL> self . assertEqual ( MyFields2 . fields , [ '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def test___doc__ ( self ) : <EOL> class Test ( object ) : <EOL> """<STR_LIT>""" <EOL> test = '<STR_LIT>' % __doc__ <EOL> self . assertEqual ( Test . test , '<STR_LIT>' ) <EOL> class IsDescendentTestCase ( unittest . TestCase ) : <EOL> def test_newstyle_descendent_of_oldstyle ( self ) : <EOL> class NewStyle ( object ) : <EOL> pass <EOL> class OldStyle : <EOL> pass <EOL> class Retro ( NewStyle , OldStyle ) : <EOL> pass <EOL> self . assert_ ( issubclass ( Retro , NewStyle ) ) <EOL> self . assert_ ( issubclass ( Retro , OldStyle ) ) <EOL> retro = Retro ( ) <EOL> self . assert_ ( isinstance ( retro , NewStyle ) ) <EOL> self . assert_ ( isinstance ( retro , OldStyle ) ) <EOL> class JavaClassNamingTestCase ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_java_class_name ( self ) : <EOL> from java . lang import String <EOL> self . assertEqual ( String . __name__ , "<STR_LIT>" ) <EOL> self . assertEqual ( String . __module__ , "<STR_LIT>" ) <EOL> module_name = __name__ <EOL> class ClassDefinesDunderModule ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_dundermodule_in_classdef ( self ) : <EOL> class Foo : <EOL> self . assertEqual ( __module__ , module_name ) <EOL> class Bar ( object ) : <EOL> self . assertEqual ( __module__ , module_name ) <EOL> def test_dundermodule_in_class_dict_copy ( self ) : <EOL> class_dict = { '<STR_LIT:a>' : '<STR_LIT>' , '<STR_LIT:b>' : '<STR_LIT>' } <EOL> Foo = type . __new__ ( type , '<STR_LIT>' , ( object , ) , class_dict ) <EOL> Foo . keys = class_dict . keys <EOL> assert sorted ( Foo ( ) . keys ( ) ) == sorted ( [ '<STR_LIT:a>' , '<STR_LIT:b>' ] ) , sorted ( Foo ( ) . keys ( ) ) <EOL> class ClassMetaclassRepr ( unittest . TestCase ) : <EOL> def test_repr_with_metaclass ( self ) : <EOL> class FooMetaclass ( type ) : <EOL> def __new__ ( cls , name , bases , attrs ) : <EOL> return super ( FooMetaclass , cls ) . __new__ ( cls , name , bases , attrs ) <EOL> class Foo ( object ) : <EOL> __metaclass__ = FooMetaclass <EOL> self . assertEqual ( "<STR_LIT>" % __name__ , repr ( Foo ) ) <EOL> def test_metaclass_str ( self ) : <EOL> class Foo ( type ) : <EOL> def __repr__ ( cls ) : <EOL> return '<STR_LIT:foo>' <EOL> class Bar ( object ) : <EOL> __metaclass__ = Foo <EOL> self . assertEqual ( repr ( Bar ) , '<STR_LIT:foo>' ) <EOL> self . assertEqual ( str ( Bar ) , '<STR_LIT:foo>' ) <EOL> def test_main ( ) : <EOL> test_support . run_unittest ( <EOL> ClassGeneralTestCase , <EOL> ClassNamelessModuleTestCase , <EOL> BrokenNameTestCase , <EOL> ClassLocalsTestCase , <EOL> IsDescendentTestCase , <EOL> JavaClassNamingTestCase , <EOL> ClassDefinesDunderModule , <EOL> ClassMetaclassRepr ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> test_main ( ) </s>
