Example #1
0
class WebSearchServicesJournalHintService(InvenioTestCase):

    """Check JournalHintService plugin."""

    def setUp(self):
        """Load plugin."""
        from invenio_search.searchext.services.JournalHintService import \
            JournalHintService
        self.plugin = JournalHintService()

    def test_seems_a_journal_reference(self):
        """Check function JournalHintService.seems_a_journal_reference."""
        test_pairs = [
            # Empty strings
            ("", False),
            (" ", False),
            ("\t", False),
            ("\t \t", False),
            # Invenio and Inspire queries
            ("author:Tom", False),
            ("find a John", False),
            ("find date after 2001", False),
            ("year:2001 OR year:2002", False),
            # Invalid journals with bad format
            ("Monkey", False),
            ("Monkey monkey", False),
            ("Monkey monkey (1)", False),
            ("Monkey monkey 1234", False),
            # Invalid journals with good format
            ("Monkey monkey, 1234", True),
            ("Monkey (2000)", True),
            # Invalid journals with good format, utf8
            (u"Capellà Pere (2000)".encode("utf8"), True),
            (u"País Valencià, 1234".encode("utf8"), True),
            # Valid journal with good format
            ("JHEP 9906:028 (1999)", True),
            ("Phys. Rev. Lett. 83 (1999) 3605", True),
            ("Nucl.Phys.,B75,(1974),461", True),
            ("  Nucl.  Phys.   B75   (1974)  461   ", True),
            ("D.S. Salopek, J.R.Bond and J.M.Bardeen,Phys.Rev.D40(1989)1753.",
             True),
        ]

        for test_input, expected in test_pairs:
            test_output = self.plugin.seems_a_journal_reference(test_input)
            self.assertEqual(
                test_output,
                expected,
                "JournalHintService.seems_a_journal_reference('%s') "
                "returned '%s' instead of '%s'"
                % (repr(test_input), repr(test_output), repr(expected))
            )
Example #2
0
 def setUp(self):
     """Load plugin."""
     from invenio_search.searchext.services.JournalHintService import \
         JournalHintService
     self.plugin = JournalHintService()