コード例 #1
0
 def setUp(self):
     self.ss = ScholarSearch('query text')
     fixture_path = normpath(
         join(dirname(__file__), ('../../../../tests/'
                                  'fixtures/search/scholarSearch.html')))
     self.fixture = open(fixture_path)
     self.page = BeautifulSoup(self.fixture.read())
     self.results = self.ss._extract_raw_results_list(self.page)
コード例 #2
0
 def setUp(self):
     self.ss = ScholarSearch('query text')
     fixture_path = normpath(join(dirname(__file__), ('../../../../tests/'
         'fixtures/search/scholarSearch.html')))
     self.fixture = open(fixture_path)
     self.page = BeautifulSoup(self.fixture.read())
     self.results = self.ss._extract_raw_results_list(self.page)
コード例 #3
0
 def create_searcher(self, engine):
     if engine == Searcher.GOOGLE:
         return GoogleJSONSearch()
     elif engine == Searcher.SCHOLAR:
         return ScholarSearch()
     elif engine == Searcher.BING:
         return BingSearch()
     elif engine == Searcher.YAHOO:
         return YahooSearch()
     else:
         raise UtilCreationError('Requested searcher is not available')
コード例 #4
0
class TestScholarSearch(unittest.TestCase):
    def setUp(self):
        self.ss = ScholarSearch('query text')
        fixture_path = normpath(
            join(dirname(__file__), ('../../../../tests/'
                                     'fixtures/search/scholarSearch.html')))
        self.fixture = open(fixture_path)
        self.page = BeautifulSoup(self.fixture.read())
        self.results = self.ss._extract_raw_results_list(self.page)

    def tearDown(self):
        self.fixture.close()

    def test_extract_info(self):
        search_info = self.ss._extract_info(self.page)
        self.failUnless(search_info['to'] == 10, 'Wrong "to" field')
        self.failUnless(search_info['from'] == 1, 'Wrong "from" field')
        self.failUnless(search_info['total'] == 1470000, 'Wrong "total" field')

    def test_extract_desc(self):
        desc = self.ss._extract_description(self.results[0])
        self.failUnless(desc.startswith('Witten and Frank\'s textbook'),
                        'Description does not start were it should')
        self.failUnless(desc.endswith('representation that can  ...'),
                        'Description does not end were it should')

    def test_extract_authors(self):
        authors = self.ss._extract_authors(self.results[0])
        self.failUnless(authors == ['IH Witten', 'E Frank'])

    def test_extract_authors_ellipsis_removal(self):
        authors = self.ss._extract_authors(self.results[1])
        self.failUnless(authors == ['T Hastie', 'R Tibshirani', 'J Friedman'])

    def test_extract_year(self):
        year = self.ss._extract_year(self.results[0])
        self.failUnless(year == '2002')
コード例 #5
0
class TestScholarSearch(unittest.TestCase):
    def setUp(self):
        self.ss = ScholarSearch('query text')
        fixture_path = normpath(join(dirname(__file__), ('../../../../tests/'
            'fixtures/search/scholarSearch.html')))
        self.fixture = open(fixture_path)
        self.page = BeautifulSoup(self.fixture.read())
        self.results = self.ss._extract_raw_results_list(self.page)

    def tearDown(self):
        self.fixture.close()

    def test_extract_info(self):
        search_info = self.ss._extract_info(self.page)
        self.failUnless(search_info['to'] == 10, 'Wrong "to" field')
        self.failUnless(search_info['from'] == 1, 'Wrong "from" field')
        self.failUnless(search_info['total'] == 1470000, 'Wrong "total" field')
    
    def test_extract_desc(self):
        desc = self.ss._extract_description(self.results[0])
        self.failUnless(desc.startswith('Witten and Frank\'s textbook'),
                        'Description does not start were it should')
        self.failUnless(desc.endswith('representation that can  ...'),
                        'Description does not end were it should')

    def test_extract_authors(self):
        authors = self.ss._extract_authors(self.results[0])
        self.failUnless(authors == ['IH Witten', 'E Frank'])
        
    def test_extract_authors_ellipsis_removal(self):
        authors = self.ss._extract_authors(self.results[1])
        self.failUnless(authors == ['T Hastie', 'R Tibshirani', 'J Friedman'])

    def test_extract_year(self):
        year = self.ss._extract_year(self.results[0])
        self.failUnless(year == '2002')