#NEWLINE# def test_check_compliance( self ) : #NEWLINE# #INDENT# class IPerson ( Interface ) : #NEWLINE# #INDENT# first_name = 'First name.' #NEWLINE# last_name = 'Last name.' #NEWLINE# def get_full_name( ) : #NEWLINE# #INDENT# "Returns person's full name." #NEWLINE# #UNINDENT# #UNINDENT# class ValidPerson ( object ) : #NEWLINE# #INDENT# def __init__( self ) : #NEWLINE# #INDENT# self . first_name = 'Jimmy' #NEWLINE# self . last_name = 'Example' #NEWLINE# #UNINDENT# def get_full_name( self ) : #NEWLINE# #INDENT# return ' ' . join ( ( self . first_name , self . last_name ) ) #NEWLINE# #UNINDENT# #UNINDENT# class MissingAttributePerson ( object ) : #NEWLINE# #INDENT# def __init__( self ) : #NEWLINE# #INDENT# self . last_name = 'Example' #NEWLINE# #UNINDENT# def get_full_name( self ) : #NEWLINE# #INDENT# return self . last_name #NEWLINE# #UNINDENT# #UNINDENT# class BadMethodPerson ( object ) : #NEWLINE# #INDENT# def __init__( self ) : #NEWLINE# #INDENT# self . first_name = 'Jimmy' #NEWLINE# self . last_name = 'Example' #NEWLINE# #UNINDENT# def get_full_name( self , foobar ) : #NEWLINE# #INDENT# return ' ' . join ( ( self . first_name , self . last_name ) ) #NEWLINE# #UNINDENT# #UNINDENT# with self . assertRaises ( TypeError ) : #NEWLINE# #INDENT# IPerson . check_compliance ( ValidPerson ) #NEWLINE# #UNINDENT# IPerson . check_compliance ( ValidPerson ( ) ) #NEWLINE# with self . assertRaises ( MissingAttributeError ) as cm : #NEWLINE# #INDENT# IPerson . check_compliance ( MissingAttributePerson ( ) ) #NEWLINE# #UNINDENT# self . assertIsInstance ( cm . exception , InterfaceComplianceError ) #NEWLINE# self . assertEquals ( cm . exception . attribute_name , 'first_name' ) #NEWLINE# self . assertEquals ( str ( cm . exception ) , 'Validated object is missing `first_name` attribute.' ) #NEWLINE# bad_method_person = BadMethodPerson ( ) #NEWLINE# with self . assertRaises ( MethodValidationError ) as cm : #NEWLINE# #INDENT# IPerson . check_compliance ( bad_method_person ) #NEWLINE# #UNINDENT# self . assertIsInstance ( cm . exception , InterfaceComplianceError ) #NEWLINE# self . assertEquals ( cm . exception . function , bad_method_person . get_full_name )