#NEWLINE# def testBasic( self ) : #NEWLINE# #INDENT# 'A basic test of StyleManager.' #NEWLINE# mgr = MyStyleManager ( ) #NEWLINE# style1 = mgr . create ( 'Style #1' ) #NEWLINE# style1 . figure . text . size = 12 #NEWLINE# style1 . axes . text . size = 8 #NEWLINE# style2 = mgr . create ( 'Style #2' , { #NEWLINE# #INDENT# 'figure.bgColor' : 'grey' , #NEWLINE# 'axes.bgColor' : 'white' , #NEWLINE# #UNINDENT# } ) #NEWLINE# style2 . figure . bgColor = 'grey' #NEWLINE# style2 . axes . bgColor = 'white' #NEWLINE# style3 = mgr . create ( 'Style #3' , parent = style1 ) #NEWLINE# style3 . figure . text . size = 24 #NEWLINE# style4 = MyStyle ( 'Style #4' ) #NEWLINE# style4 . figure . text . size = 24 #NEWLINE# style4 . axes . text . size = 8 #NEWLINE# style4 . figure . bgColor = 'grey' #NEWLINE# style4 . axes . bgColor = 'white' #NEWLINE# style5 = mgr . create ( 'Style #5' ) #NEWLINE# mgr [ 'Style #5' ] . figure . text . size = 16 #NEWLINE# mgr [ 'Style #5' ] . axes . text . size = 8 #NEWLINE# mgr [ 'Style #5' ] . figure . bgColor = 'grey' #NEWLINE# mgr [ 'Style #5' ] . axes . bgColor = 'white' #NEWLINE# style6 = mgr . create ( 'Style #6' , parent = 'Style #5' ) #NEWLINE# style6 . figure . text . color = 'orange' #NEWLINE# style6 . axes . text . color = 'purple' #NEWLINE# newStyle = mgr . copy ( style3 , 'NewStyle1' ) #NEWLINE# self . checkStyleEq ( 'Copy by style' , style3 , newStyle ) #NEWLINE# newStyle = mgr . copy ( 'Style #3' , 'NewStyle2' ) #NEWLINE# self . checkStyleEq ( 'Copy by name' , style3 , newStyle ) #NEWLINE# self . assertRaises ( Exception , mgr . copy , 'badName' , 'blah' , msg = 'Failed to raise when copying a non-existant style.' ) #NEWLINE# resolvedStyle = mgr . resolve ( 'Resolved Style #1' , 'Style #2' ) #NEWLINE# self . checkStyleEq ( 'Resolve by name' , style2 , resolvedStyle ) #NEWLINE# mgr . erase ( resolvedStyle ) #NEWLINE# resolvedStyle = mgr . resolve ( 'Resolved Style #2' , [ 'Style #2' , style3 , 'blah' ] , ignoreNotFound = True ) #NEWLINE# self . checkStyleEq ( 'Resolve by list' , style4 , result ) #NEWLINE# mgr . erase ( resolvedStyle ) #NEWLINE# self . assertRaises ( Exception , mgr . resolve , None , 'does not exist' , msg = 'Resolve failed to throw on invalid style.' ) #NEWLINE# def customFunc( obj ) : #NEWLINE# #INDENT# obj . figureBgColor = 'grey' #NEWLINE# obj . axesBgColor = 'white' #NEWLINE# #UNINDENT# style3 . custom = customFunc #NEWLINE# obj = S . types . Data ( figureTextSize = None , figureTextColor = None , figureBgColor = None , figureFgColor = None , axesTextSize = None , axesTextColor = None , axesBgColor = None , axesFgColor = None ) #NEWLINE# mgr . apply ( obj , style4 ) #NEWLINE# self . checkObj ( 'Apply by style' , obj , style4 ) #NEWLINE# self . assertEqual ( True , mgr . exists ( style4 ) , msg = 'Failed to auto add an applied style.' ) #NEWLINE# obj = S . types . Data ( figureTextSize = None , figureTextColor = None , figureBgColor = None , figureFgColor = None , axesTextSize = None , axesTextColor = None , axesBgColor = None , axesFgColor = None ) #NEWLINE# self . assertRaises ( Exception , mgr . apply , obj , 'invalidName' , msg = 'Failed to raise on applying a bad style.' ) #NEWLINE# self . assertEqual ( [ ] , mgr . getElementStyles ( obj ) , msg = 'Element styles should be [].' ) #NEWLINE# mgr . apply ( obj , 'Style #3' ) #NEWLINE# self . checkObj ( 'Apply by name' , obj , style4 ) #NEWLINE# style3 . figure . text . size = 16 #NEWLINE# mgr . reapply ( ) #NEWLINE# self . checkObj ( 'Re-Apply' , obj , style5 ) #NEWLINE# mgr . set ( obj , 'figure.text.size' , 24 ) #NEWLINE# self . checkObj ( 'Set by name' , obj , style4 ) #NEWLINE# mgr . set ( obj , { #NEWLINE# #INDENT# 'figure.text.size' : 16 , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . checkObj ( 'Set by dict' , obj , style5 ) #NEWLINE# self . assertRaises ( Exception , mgr . set , obj , { #NEWLINE# #INDENT# 'foo' : 1 , #NEWLINE# #UNINDENT# } , 1 , msg = "Failed to throw with invalid 'set' parameters." ) #NEWLINE# obj = S . types . Data ( figureTextSize = None , figureTextColor = None , figureBgColor = None , figureFgColor = None , axesTextSize = None , axesTextColor = None , axesBgColor = None , axesFgColor = None ) #NEWLINE# mgr . apply ( obj , style5 ) #NEWLINE# self . assertEqual ( [ ] , mgr . getTags ( obj ) , msg = 'Element name should be None' ) #NEWLINE# mgr . untag ( obj , 'testTag' ) #NEWLINE# self . assertEqual ( False , mgr . hasTag ( obj , 'testTag' ) , msg = 'Incorrect result for hasTag (when nothing set).' ) #NEWLINE# mgr . tag ( obj , 'testTag' ) #NEWLINE# self . assertEqual ( [ 'testTag' ] , mgr . getTags ( obj ) , msg = 'Set/get tag failed for obj' ) #NEWLINE# self . assertEqual ( True , mgr . hasTag ( obj , 'testTag' ) , msg = 'Incorrect result for hasTag (when it has it)' ) #NEWLINE# mgr . untag ( obj , 'testTag' ) #NEWLINE# self . assertEqual ( False , mgr . hasTag ( obj , 'testTag' ) , msg = "Incorrect result for hasTag (when it doesn't have it)" ) #NEWLINE# mgr . tag ( obj , 'testTag' ) #NEWLINE# tagStyle = MyStyle ( 'TagStyle' ) #NEWLINE# tagStyle . figure . text . color = 'orange' #NEWLINE# tagStyle . axes . text . color = 'purple' #NEWLINE# mgr . apply ( obj , tagStyle , tag = 'OtherTag' ) #NEWLINE# self . checkObj ( 'Set by incorrect tag' , obj , style5 ) #NEWLINE# mgr . apply ( obj , tagStyle , tag = 'testTag' ) #NEWLINE# self . checkObj ( 'Set by correct tag' , obj , style6 ) #NEWLINE# obj = S . types . Data ( figureTextSize = None , figureTextColor = None , figureBgColor = None , figureFgColor = None , axesTextSize = None , axesTextColor = None , axesBgColor = None , axesFgColor = None ) #NEWLINE# mgr . tag ( obj , 'applyTestTag' ) #NEWLINE# mgr . apply ( None , style6 , tag = 'applyTestTag' ) #NEWLINE# self . checkObj ( 'Apply by tag' , obj , style6 ) #NEWLINE# tmpStyle1 = MyStyle ( 'TmpStyle #1' ) #NEWLINE# mgr . resolve ( None , tmpStyle1 ) #NEWLINE# tmpStyle2 = MyStyle ( 'TmpStyle #2' ) #NEWLINE# mgr . create ( None , parent = tmpStyle2 ) #NEWLINE# expected = [ 'NewStyle1' , 'NewStyle2' , 'Style #1' , 'Style #2' , 'Style #3' , 'Style #4' , 'Style #5' , 'Style #6' , 'TagStyle' , 'TmpStyle #1' , 'TmpStyle #2' ] #NEWLINE# self . assertEqual ( expected , mgr . getAll ( ) , msg = 'Invalid list of loaded styles.' ) #NEWLINE# tmpfile = open ( os . path . join ( self . outputDir , 'warning-output.log' ) , 'w' ) #NEWLINE# mgr . apply ( obj , [ style1 , 'Style #3' ] ) #NEWLINE# mgr . erase ( style3 ) #NEWLINE# mgr . reapply ( ) #NEWLINE# tmpfile . close ( ) #NEWLINE# mgr . clear ( ) #NEWLINE# expected = [ ] #NEWLINE# self . assertEqual ( expected , mgr . getAll ( ) , msg = 'mgr shows styles loaded, when should be empty.' ) #NEWLINE# tmpStyle = MyStyle ( 'Temp Style' ) #NEWLINE# mgr . add ( tmpStyle ) #NEWLINE# self . assertRaises ( Exception , mgr . add , tmpStyle , msg = 'Failed to throw on multiple adds.' ) #NEWLINE# mgr . erase ( tmpStyle ) #NEWLINE# result = mgr . find ( tmpStyle . name ) #NEWLINE# self . assertEqual ( None , result , msg = "Did not remove 'tmpStyle' from the manager." ) #NEWLINE# msg = 'Failed to throw on multiple removes.' #NEWLINE# self . assertRaises ( Exception , mgr . erase , tmpStyle , msg = msg ) #NEWLINE# msg = 'Failed to throw with invalid parent' #NEWLINE# self . assertRaises ( Exception , mgr . create , 'Bad Parent' , parent = 'Bogus' , msg = msg )