Skip to content

Commit

Permalink
Merge pull request #1294 from berkerpeksag/ignore-warnings
Browse files Browse the repository at this point in the history
Ignore ScrapyDeprecationWarning warnings properly.
  • Loading branch information
dangra committed Jun 10, 2015
2 parents 90aa5c0 + 8a48d9c commit 6446652
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
3 changes: 2 additions & 1 deletion scrapy/linkextractors/sgml.py
Expand Up @@ -111,7 +111,8 @@ def __init__(self, allow=(), deny=(), allow_domains=(), deny_domains=(), restric
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)

Expand Down
9 changes: 6 additions & 3 deletions tests/test_selector.py
Expand Up @@ -490,21 +490,24 @@ class UserClass(cls):
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>'])
Expand Down
16 changes: 11 additions & 5 deletions tests/test_utils_deprecate.py
Expand Up @@ -3,6 +3,7 @@
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
Expand Down Expand Up @@ -109,7 +110,8 @@ def test_warning_on_instance(self):
warn_category=MyWarning)

# ignore subclassing warnings
with warnings.catch_warnings(record=True):
with warnings.catch_warnings():
warnings.simplefilter('ignore', ScrapyDeprecationWarning)
class UserClass(Deprecated):
pass

Expand Down Expand Up @@ -138,7 +140,8 @@ class UserClass2(Deprecated):
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):
Expand Down Expand Up @@ -173,7 +176,8 @@ class OldStyleClass:
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):
Expand Down Expand Up @@ -206,7 +210,8 @@ class OldStyleClass:
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')
Expand Down Expand Up @@ -264,7 +269,8 @@ def test_old_path_gets_fixed(self):
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')

Expand Down

0 comments on commit 6446652

Please sign in to comment.