@@ -120,8 +120,8 @@ def test_comparison_case_insensitive(self):
120120 def test_slice (self ):
121121 hn = HumanName ("Doe-Ray, Dr. John P., CLU, CFP, LUTC" )
122122 self .m (list (hn ), ['Dr.' , 'John' , 'P.' , 'Doe-Ray' , 'CLU, CFP, LUTC' ], hn )
123- self .m (hn [1 :], ['John' , 'P.' , 'Doe-Ray' , 'CLU, CFP, LUTC' ], hn )
124- self .m (hn [1 :- 1 ], ['John' , 'P.' , 'Doe-Ray' ], hn )
123+ self .m (hn [1 :], ['John' , 'P.' , 'Doe-Ray' , 'CLU, CFP, LUTC' , '' ], hn )
124+ self .m (hn [1 :- 2 ], ['John' , 'P.' , 'Doe-Ray' ], hn )
125125
126126 def test_conjunction_names (self ):
127127 hn = HumanName ("johnny y" )
@@ -1511,11 +1511,11 @@ def test_downcasing_mc(self):
15111511
15121512class HumanNameOutputFormatTests (HumanNameTestBase ):
15131513 def test_formating (self ):
1514- hn = HumanName ("Rev John A. Kenneth Doe III" )
1515- hn .string_format = "{title} {first} {middle} {last} {suffix}"
1516- self .assertEqual (u (hn ), "Rev John A. Kenneth Doe III" )
1517- hn .string_format = "{last}, {title} {first} {middle}, {suffix}"
1518- self .assertEqual (u (hn ), "Doe, Rev John A. Kenneth, III" )
1514+ hn = HumanName ("Rev John A. Kenneth Doe III (Kenny) " )
1515+ hn .string_format = "{title} {first} {middle} {last} {suffix} ({nickname}) "
1516+ self .assertEqual (u (hn ), "Rev John A. Kenneth Doe III (Kenny) " )
1517+ hn .string_format = "{last}, {title} {first} {middle}, {suffix} ({nickname}) "
1518+ self .assertEqual (u (hn ), "Doe, Rev John A. Kenneth, III (Kenny) " )
15191519
15201520
15211521TEST_NAMES = (
@@ -1706,9 +1706,27 @@ def test_variations_of_TEST_NAMES(self):
17061706 hn = HumanName (name )
17071707 if len (hn .suffix_list ) > 1 :
17081708 hn = HumanName ("{title} {first} {middle} {last} {suffix}" .format (** hn ._dict ).split (',' )[0 ])
1709- nocomma = HumanName ("{title} {first} {middle} {last} {suffix}" .format (** hn ._dict ))
1710- lastnamecomma = HumanName ("{last}, {title} {first} {middle} {suffix}" .format (** hn ._dict ))
1711- suffixcomma = HumanName ("{title} {first} {middle} {last}, {suffix}" .format (** hn ._dict ))
1709+ hn_dict = hn ._dict .copy ()
1710+ attrs = [
1711+ 'title' ,
1712+ 'first' ,
1713+ 'middle' ,
1714+ 'last' ,
1715+ 'suffix' ,
1716+ 'nickname' ,
1717+ ]
1718+ for attr in attrs :
1719+ if not getattr (hn , attr ):
1720+ setattr (hn ,attr ,'' )
1721+ nocomma = HumanName ("{title} {first} {middle} {last} {suffix}" .format (** hn_dict ))
1722+ lastnamecomma = HumanName ("{last}, {title} {first} {middle} {suffix}" .format (** hn_dict ))
1723+ if hn .suffix :
1724+ suffixcomma = HumanName ("{title} {first} {middle} {last}, {suffix}" .format (** hn_dict ))
1725+ if hn .nickname :
1726+ nocomma = HumanName ("{title} {first} {middle} {last} {suffix} ({nickname})" .format (** hn_dict ))
1727+ lastnamecomma = HumanName ("{last}, {title} {first} {middle} {suffix} ({nickname})" .format (** hn_dict ))
1728+ if hn .suffix :
1729+ suffixcomma = HumanName ("{title} {first} {middle} {last}, {suffix} ({nickname})" .format (** hn_dict ))
17121730 for attr in hn ._members :
17131731 self .m (getattr (hn , attr ), getattr (nocomma , attr ), hn )
17141732 self .m (getattr (hn , attr ), getattr (lastnamecomma , attr ), hn )
0 commit comments