Scrapy, a fast high-level web crawling & scraping framework for Python.
Skipped IBL tests if nltk/numpy are not available.
Rolando Espinoza La fuentee995c5c7ff26
diff --git a/scrapy/tests/test_contrib_ibl/test_extraction.py b/scrapy/tests/test_contrib_ibl/test_extraction.pyindex ee1a69bcc..65d48cf55 100644--- a/scrapy/tests/test_contrib_ibl/test_extraction.py+++ b/scrapy/tests/test_contrib_ibl/test_extraction.py@@ -4,14 +4,26 @@ tests for page parsingPage parsing effectiveness is measured through the evaluation system. Thesetests should focus on specific bits of functionality work correctly."""-from unittest import TestCase+from twisted.trial.unittest import TestCase, SkipTestfrom scrapy.contrib.ibl.htmlpage import HtmlPage-from scrapy.contrib.ibl.extraction import InstanceBasedLearningExtractorfrom scrapy.contrib.ibl.descriptor import (FieldDescriptor as A,ItemDescriptor)from scrapy.contrib.ibl.extractors import (contains_any_numbers,image_url)-++try:+ import nltk+except ImportError:+ nltk = None++try:+ import numpy+except ImportError:+ numpy = None++if nltk and numpy:+ from scrapy.contrib.ibl.extraction import InstanceBasedLearningExtractor+# simple page with all featuresANNOTATED_PAGE1 = u"""@@ -778,7 +790,13 @@ TEST_DATA = [class TestExtraction(TestCase):- def _run(self, name, templates, page, extractors, expected_output):+ def setUp(self):+ if not nltk:+ raise SkipTest("nltk not available")+ if not numpy:+ raise SkipTest("numpy not available")++ def _run_extraction(self, name, templates, page, extractors, expected_output):self.trace = Nonetemplate_pages = [HtmlPage(None, {}, t) for t in templates]extractor = InstanceBasedLearningExtractor(template_pages, extractors, True)@@ -810,7 +828,7 @@ class TestExtraction(TestCase):def test_expected_outputs(self):try:for data in TEST_DATA:- self._run(*data)+ self._run_extraction(*data)except AssertionError:if self.trace:print "Trace:"diff --git a/scrapy/tests/test_contrib_ibl/test_pageparsing.py b/scrapy/tests/test_contrib_ibl/test_pageparsing.pyindex 545e9d46b..264e1644f 100644--- a/scrapy/tests/test_contrib_ibl/test_pageparsing.py+++ b/scrapy/tests/test_contrib_ibl/test_pageparsing.py@@ -5,16 +5,29 @@ import osfrom cStringIO import StringIOfrom gzip import GzipFile-from unittest import TestCase+from twisted.trial.unittest import TestCase, SkipTestfrom scrapy.utils.python import str_to_unicodefrom scrapy.utils.py26 import jsonfrom scrapy.contrib.ibl.htmlpage import HtmlPage-from scrapy.contrib.ibl.extraction.pageparsing import (InstanceLearningParser,- TemplatePageParser, ExtractionPageParser)-from scrapy.contrib.ibl.extraction.pageobjects import TokenDict, TokenTypefrom scrapy.tests.test_contrib_ibl import path+try:+ import nltk+except ImportError:+ nltk = None++try:+ import numpy+except ImportError:+ numpy = None++if nltk and numpy:+ from scrapy.contrib.ibl.extraction.pageparsing import (+ InstanceLearningParser, TemplatePageParser, ExtractionPageParser)+ from scrapy.contrib.ibl.extraction.pageobjects import TokenDict, TokenType++SIMPLE_PAGE = u"""<html> <p some-attr="foo">this is a test</p> </html>"""@@ -160,6 +173,12 @@ def _tags(pp, predicate):class TestPageParsing(TestCase):+ def setUp(self):+ if not nltk:+ raise SkipTest("nltk not available")+ if not numpy:+ raise SkipTest("numpy not available")+def test_instance_parsing(self):pp = _parse_page(InstanceLearningParser, SIMPLE_PAGE)# all tags