@@ -69,10 +69,12 @@ def test_initials_delimiter(self) -> None:
6969 def test_initials_delimiter_constants (self ) -> None :
7070 from nameparser .config import CONSTANTS
7171 _orig = CONSTANTS .initials_delimiter
72- CONSTANTS .initials_delimiter = ";"
73- hn = HumanName ("Doe, John A. Kenneth, Jr." )
74- self .m (hn .initials (), "J; A; K; D;" , hn )
75- CONSTANTS .initials_delimiter = _orig
72+ try :
73+ CONSTANTS .initials_delimiter = ";"
74+ hn = HumanName ("Doe, John A. Kenneth, Jr." )
75+ self .m (hn .initials (), "J; A; K; D;" , hn )
76+ finally :
77+ CONSTANTS .initials_delimiter = _orig
7678
7779 def test_initials_separator_default_on_constants (self ) -> None :
7880 from nameparser .config import CONSTANTS
@@ -103,10 +105,10 @@ def test_initials_format_empty_string_kwarg(self) -> None:
103105 # Regression: initials_format='' was silently ignored due to `or` defaulting
104106 hn = HumanName ("Doe, John A." )
105107 hn2 = HumanName ("Doe, John A." , initials_format = "" )
106- assert hn .initials () != hn2 .initials ()
107- # When format is empty string, result should be either "" or empty_attribute_default
108- result = hn2 . initials ()
109- assert result == "" or result == hn2 .C . empty_attribute_default
108+ self . assertNotEqual ( hn .initials (), hn2 .initials () )
109+ # "". format(...) returns ""; collapse_whitespace returns "" which falls through
110+ # to empty_attribute_default (may be "" or None depending on config variant).
111+ self . assertFalse ( hn2 .initials ())
110112
111113 def test_initials_separator_kwarg (self ) -> None :
112114 # initials_separator="" with initials_format="{first}{middle}{last}" gives
@@ -118,6 +120,20 @@ def test_initials_separator_kwarg(self) -> None:
118120 )
119121 self .m (hn .initials (), "J.A.K.D." , hn )
120122
123+ def test_initials_separator_custom_value (self ) -> None :
124+ # Non-empty custom separator exercising __process_initial__ on a multi-word
125+ # token. "Van Berg" is a single name part whose two words produce two initials
126+ # joined by initials_separator.
127+ hn = HumanName ("" , initials_separator = "-" , initials_delimiter = "." )
128+ result = hn .__process_initial__ ("Van Berg" , firstname = True )
129+ self .assertEqual (result , "V-B" )
130+
131+ def test_str_default_behavior_unchanged (self ) -> None :
132+ # Regression guard for the `or` → `is not None` change in __str__:
133+ # the default path (no string_format kwarg) must still produce the expected string.
134+ hn = HumanName ("John Doe" )
135+ self .assertEqual (str (hn ), "John Doe" )
136+
121137 def test_constructor_first (self ) -> None :
122138 hn = HumanName (first = "TheName" )
123139 self .assertFalse (hn .unparsable )
@@ -167,15 +183,6 @@ def test_string_format_empty_string_kwarg(self) -> None:
167183 hn = HumanName ("John Doe" , string_format = "" )
168184 self .assertEqual (str (hn ), "" )
169185
170- def test_initials_separator_multiword_name_part (self ) -> None :
171- # __process_initial__ splits on spaces internally for multi-word tokens;
172- # initials_separator must flow through there too.
173- hn = HumanName ("" , constants = None )
174- hn .initials_separator = ""
175- # Directly exercise __process_initial__ with a two-word part
176- result = hn .__process_initial__ ("Van Berg" , firstname = True )
177- self .assertEqual (result , "VB" )
178-
179186 def test_initials_separator_empty_multi_part_middle (self ) -> None :
180187 # Full workflow from issue #152: empty delimiter + separator + compact format
181188 # gives fully concatenated initials with no spaces or punctuation.
@@ -193,11 +200,13 @@ def test_initials_separator_constants_multi_part_middle(self) -> None:
193200 _orig_d = CONSTANTS .initials_delimiter
194201 _orig_s = CONSTANTS .initials_separator
195202 _orig_f = CONSTANTS .initials_format
196- CONSTANTS .initials_delimiter = ""
197- CONSTANTS .initials_separator = ""
198- CONSTANTS .initials_format = "{first}{middle}{last}"
199- hn = HumanName ("Doe, John A. Kenneth" )
200- self .m (hn .initials (), "JAKD" , hn )
201- CONSTANTS .initials_delimiter = _orig_d
202- CONSTANTS .initials_separator = _orig_s
203- CONSTANTS .initials_format = _orig_f
203+ try :
204+ CONSTANTS .initials_delimiter = ""
205+ CONSTANTS .initials_separator = ""
206+ CONSTANTS .initials_format = "{first}{middle}{last}"
207+ hn = HumanName ("Doe, John A. Kenneth" )
208+ self .m (hn .initials (), "JAKD" , hn )
209+ finally :
210+ CONSTANTS .initials_delimiter = _orig_d
211+ CONSTANTS .initials_separator = _orig_s
212+ CONSTANTS .initials_format = _orig_f
0 commit comments