mirror of
https://github.com/scrapy/scrapy.git
synced 2025-02-25 04:23:45 +00:00
Merge pull request #1294 from berkerpeksag/ignore-warnings
Ignore ScrapyDeprecationWarning warnings properly.
This commit is contained in:
commit
6446652635
@ -111,7 +111,8 @@ class SgmlLinkExtractor(FilteringLinkExtractor):
|
||||
tag_func = lambda x: x in tags
|
||||
attr_func = lambda x: x in attrs
|
||||
|
||||
with warnings.catch_warnings(record=True):
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter('ignore', ScrapyDeprecationWarning)
|
||||
lx = BaseSgmlLinkExtractor(tag=tag_func, attr=attr_func,
|
||||
unique=unique, process_value=process_value)
|
||||
|
||||
|
@ -490,21 +490,24 @@ class DeprecatedXpathSelectorTest(unittest.TestCase):
|
||||
self.assertTrue(isinstance(usel, XPathSelector))
|
||||
|
||||
def test_xpathselector(self):
|
||||
with warnings.catch_warnings(record=True):
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter('ignore', ScrapyDeprecationWarning)
|
||||
hs = XPathSelector(text=self.text)
|
||||
self.assertEqual(hs.select("//div").extract(),
|
||||
[u'<div><img src="a.jpg"><p>Hello</p></div>'])
|
||||
self.assertRaises(RuntimeError, hs.css, 'div')
|
||||
|
||||
def test_htmlxpathselector(self):
|
||||
with warnings.catch_warnings(record=True):
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter('ignore', ScrapyDeprecationWarning)
|
||||
hs = HtmlXPathSelector(text=self.text)
|
||||
self.assertEqual(hs.select("//div").extract(),
|
||||
[u'<div><img src="a.jpg"><p>Hello</p></div>'])
|
||||
self.assertRaises(RuntimeError, hs.css, 'div')
|
||||
|
||||
def test_xmlxpathselector(self):
|
||||
with warnings.catch_warnings(record=True):
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter('ignore', ScrapyDeprecationWarning)
|
||||
xs = XmlXPathSelector(text=self.text)
|
||||
self.assertEqual(xs.select("//div").extract(),
|
||||
[u'<div><img src="a.jpg"><p>Hello</p></img></div>'])
|
||||
|
@ -3,6 +3,7 @@ from __future__ import absolute_import
|
||||
import inspect
|
||||
import unittest
|
||||
import warnings
|
||||
from scrapy.exceptions import ScrapyDeprecationWarning
|
||||
from scrapy.utils.deprecate import create_deprecated_class, update_classpath
|
||||
|
||||
from tests import mock
|
||||
@ -109,7 +110,8 @@ class WarnWhenSubclassedTest(unittest.TestCase):
|
||||
warn_category=MyWarning)
|
||||
|
||||
# ignore subclassing warnings
|
||||
with warnings.catch_warnings(record=True):
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter('ignore', ScrapyDeprecationWarning)
|
||||
class UserClass(Deprecated):
|
||||
pass
|
||||
|
||||
@ -138,7 +140,8 @@ class WarnWhenSubclassedTest(unittest.TestCase):
|
||||
self.assertIn("tests.test_utils_deprecate.Deprecated", msg)
|
||||
|
||||
def test_issubclass(self):
|
||||
with warnings.catch_warnings(record=True):
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter('ignore', ScrapyDeprecationWarning)
|
||||
DeprecatedName = create_deprecated_class('DeprecatedName', NewName)
|
||||
|
||||
class UpdatedUserClass1(NewName):
|
||||
@ -173,7 +176,8 @@ class WarnWhenSubclassedTest(unittest.TestCase):
|
||||
self.assertRaises(TypeError, issubclass, object(), DeprecatedName)
|
||||
|
||||
def test_isinstance(self):
|
||||
with warnings.catch_warnings(record=True):
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter('ignore', ScrapyDeprecationWarning)
|
||||
DeprecatedName = create_deprecated_class('DeprecatedName', NewName)
|
||||
|
||||
class UpdatedUserClass2(NewName):
|
||||
@ -206,7 +210,8 @@ class WarnWhenSubclassedTest(unittest.TestCase):
|
||||
assert not isinstance(OldStyleClass(), DeprecatedName)
|
||||
|
||||
def test_clsdict(self):
|
||||
with warnings.catch_warnings(record=True):
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter('ignore', ScrapyDeprecationWarning)
|
||||
Deprecated = create_deprecated_class('Deprecated', NewName, {'foo': 'bar'})
|
||||
|
||||
self.assertEqual(Deprecated.foo, 'bar')
|
||||
@ -264,7 +269,8 @@ class UpdateClassPathTest(unittest.TestCase):
|
||||
self.assertIn("scrapy.extensions.debug.Debug", str(w[0].message))
|
||||
|
||||
def test_sorted_replacement(self):
|
||||
with warnings.catch_warnings(record=True):
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter('ignore', ScrapyDeprecationWarning)
|
||||
output = update_classpath('scrapy.contrib.pipeline.Pipeline')
|
||||
self.assertEqual(output, 'scrapy.pipelines.Pipeline')
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user