def _clean_string(s): if re.search(r'[A-Z]', s) and not re.search(r'[a-z]', s): # WE'RE IN UPPERCASE from boundaries.titlecase import titlecase s = titlecase(s) s = re.sub(r'(?u)\s', ' ', s) s = re.sub(r'( ?-- ?| - )', '—', s) return s
def test_uc_initials(self): self.assertEqual(titlecase('X.Y.Z. INC.'), 'X.Y.Z. Inc.')
def test_slash(self): self.assertEqual(titlecase('foo/bar/baz'), 'Foo/Bar/Baz')
def test_mac_mc(self): self.assertEqual(titlecase('MACDONALD'), 'MacDonald')
def test_small_words(self): self.assertEqual(titlecase('FOR WHOM THE BELL TOLLS'), 'For Whom the Bell Tolls')
def test_inline_period(self): self.assertEqual(titlecase('example.com'), 'example.com')
def test_apos_second(self): self.assertEqual(titlecase("duck à l'orange"), "Duck à L'Orange")