Beispiel #1
0
 def test_titlecase(self):
     """Tests various inputs for the titlecase function"""
     test_pairs = [
         ["Q&A with steve jobs: 'that's what happens in technology'",
          u"Q&A With Steve Jobs: 'That's What Happens in Technology'"],
         ["What is AT&T's problem?",
          u"What is AT&T's Problem?"],
         ['Apple deal with AT&T falls through',
          u'Apple Deal With AT&T Falls Through'],
         ['this v that',
          u'This v That'],
         ['this v. that',
          u'This v. That'],
         ['this vs that',
          u'This vs That'],
         ['this vs. that',
          u'This vs. That'],
         ["The SEC's Apple Probe: What You Need to Know",
          u"The SEC's Apple Probe: What You Need to Know"],
         ["'by the Way, small word at the start but within quotes.'",
          u"'By the Way, Small Word at the Start but Within Quotes.'"],
         ['Small word at end is nothing to be afraid of',
          u'Small Word at End is Nothing to Be Afraid Of'],
         ['Starting Sub-Phrase With a Small Word: a Trick, Perhaps?',
          u'Starting Sub-Phrase With a Small Word: A Trick, Perhaps?'],
         ["Sub-Phrase With a Small Word in Quotes: 'a Trick, Perhaps?'",
          u"Sub-Phrase With a Small Word in Quotes: 'A Trick, Perhaps?'"],
         ['Sub-Phrase With a Small Word in Quotes: "a Trick, Perhaps?"',
          u'Sub-Phrase With a Small Word in Quotes: "A Trick, Perhaps?"'],
         ['"Nothing to Be Afraid of?"',
          u'"Nothing to Be Afraid Of?"'],
         ['"Nothing to be Afraid Of?"',
          u'"Nothing to Be Afraid Of?"'],
         ['a thing',
          u'A Thing'],
         ["2lmc Spool: 'gruber on OmniFocus and vapo(u)rware'",
          u"2lmc Spool: 'Gruber on OmniFocus and Vapo(u)rware'"],
         ['this is just an example.com',
          u'This is Just an example.com'],
         ['this is something listed on del.icio.us',
          u'This is Something Listed on del.icio.us'],
         ['iTunes should be unmolested',
          u'iTunes Should Be Unmolested'],
         ['Reading between the lines of steve jobs’s ‘thoughts on music’',
          # Tests unicode
          u'Reading Between the Lines of Steve Jobs’s ‘thoughts on Music’'],
         ['seriously, ‘repair permissions’ is voodoo',  # Tests unicode
          u'Seriously, ‘repair Permissions’ is Voodoo'],
         [
             'generalissimo francisco franco: still dead; kieren McCarthy: '
             'still a jackass',
             u'Generalissimo Francisco Franco: Still Dead; Kieren McCarthy:'
             u' Still a Jackass'],
         ['Chapman v. u.s. Postal Service',
          u'Chapman v. U.S. Postal Service'],
         ['Spread Spectrum Screening Llc. v. Eastman Kodak Co.',
          u'Spread Spectrum Screening LLC. v. Eastman Kodak Co.'],
         [
             'Consolidated Edison Co. of New York, Inc. v. Entergy Nuclear '
             'Indian Point 2, Llc.',
             u'Consolidated Edison Co. of New York, Inc. v. Entergy Nuclear'
             u' Indian Point 2, LLC.'],
         ['Infosint s.a. v. H. Lundbeck A/s',
          u'Infosint S.A. v. H. Lundbeck A/S'],
         ["KEVIN O'CONNELL v. KELLY HARRINGTON",
          u"Kevin O'Connell v. Kelly Harrington"],
         ['International Union of Painter v. J&r Flooring, Inc',
          u'International Union of Painter v. J&R Flooring, Inc'],
         [
             'DOROTHY L. BIERY, and JERRAMY and ERIN PANKRATZ v. THE UNITED'
             ' STATES 07-693L And',
             u'Dorothy L. Biery, and Jerramy and Erin Pankratz v. the '
             u'United States 07-693l And'],
         ['CARVER v. US',
          u'Carver v. US']]
     for pair in test_pairs:
         self.assertEqual(titlecase(force_unicode(pair[0])),
                          pair[1])
    def test_titlecase(self):
        """Tests various inputs for the titlecase function"""
        test_pairs = [
            [
                "Q&A with steve jobs: 'that's what happens in technology'",
                "Q&A With Steve Jobs: 'That's What Happens in Technology'",
            ],
            ["What is AT&T's problem?", "What is AT&T's Problem?"],
            [
                "Apple deal with AT&T falls through",
                "Apple Deal With AT&T Falls Through",
            ],
            ["this v that", "This v That"],
            ["this v. that", "This v. That"],
            ["this vs that", "This vs That"],
            ["this vs. that", "This vs. That"],
            [
                "The SEC's Apple Probe: What You Need to Know",
                "The SEC's Apple Probe: What You Need to Know",
            ],
            [
                "'by the Way, small word at the start but within quotes.'",
                "'By the Way, Small Word at the Start but Within Quotes.'",
            ],
            [
                "Small word at end is nothing to be afraid of",
                "Small Word at End is Nothing to Be Afraid Of",
            ],
            [
                "Starting Sub-Phrase With a Small Word: a Trick, Perhaps?",
                "Starting Sub-Phrase With a Small Word: A Trick, Perhaps?",
            ],
            [
                "Sub-Phrase With a Small Word in Quotes: 'a Trick, Perhaps?'",
                "Sub-Phrase With a Small Word in Quotes: 'A Trick, Perhaps?'",
            ],
            [
                'Sub-Phrase With a Small Word in Quotes: "a Trick, Perhaps?"',
                'Sub-Phrase With a Small Word in Quotes: "A Trick, Perhaps?"',
            ],
            ['"Nothing to Be Afraid of?"', '"Nothing to Be Afraid Of?"'],
            ['"Nothing to be Afraid Of?"', '"Nothing to Be Afraid Of?"'],
            ["a thing", "A Thing"],
            [
                "2lmc Spool: 'gruber on OmniFocus and vapo(u)rware'",
                "2lmc Spool: 'Gruber on OmniFocus and Vapo(u)rware'",
            ],
            ["this is just an example.com", "This is Just an example.com"],
            [
                "this is something listed on del.icio.us",
                "This is Something Listed on del.icio.us",
            ],
            ["iTunes should be unmolested", "iTunes Should Be Unmolested"],
            [
                "Reading between the lines of steve jobs’s ‘thoughts on music’",
                # Tests unicode
                "Reading Between the Lines of Steve Jobs’s ‘Thoughts on Music’",
            ],
            [
                "seriously, ‘repair permissions’ is voodoo",  # Tests unicode
                "Seriously, ‘Repair Permissions’ is Voodoo",
            ],
            [
                "generalissimo francisco franco: still dead; kieren McCarthy: "
                "still a jackass",
                "Generalissimo Francisco Franco: Still Dead; Kieren McCarthy:"
                " Still a Jackass",
            ],
            [
                "Chapman v. u.s. Postal Service",
                "Chapman v. U.S. Postal Service",
            ],
            [
                "Spread Spectrum Screening Llc. v. Eastman Kodak Co.",
                "Spread Spectrum Screening LLC. v. Eastman Kodak Co.",
            ],
            [
                "Consolidated Edison Co. of New York, Inc. v. Entergy Nuclear "
                "Indian Point 2, Llc.",
                "Consolidated Edison Co. of New York, Inc. v. Entergy Nuclear"
                " Indian Point 2, LLC.",
            ],
            [
                "Infosint s.a. v. H. Lundbeck A/s",
                "Infosint S.A. v. H. Lundbeck A/S",
            ],
            [
                "KEVIN O'CONNELL v. KELLY HARRINGTON",
                "Kevin O'Connell v. Kelly Harrington",
            ],
            [
                "International Union of Painter v. J&r Flooring, Inc",
                "International Union of Painter v. J&R Flooring, Inc",
            ],
            [
                "DOROTHY L. BIERY, and JERRAMY and ERIN PANKRATZ v. THE UNITED"
                " STATES 07-693L And",
                "Dorothy L. Biery, and Jerramy and Erin Pankratz v. the "
                "United States 07-693l And",
            ],
            ["CARVER v. US", "Carver v. US"],
        ]

        for pair in test_pairs:
            unicode_string = force_unicode(pair[0])
            self.assertEqual(titlecase(unicode_string, DEBUG=False), pair[1])