Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update deprecated test aliases #2876

Merged
merged 2 commits into from Aug 9, 2017

Conversation

@ngash
Copy link
Contributor

@ngash ngash commented Aug 7, 2017

  • change failIf to assertFalse
  • change asertEquals to assertEqual
  • change assert_ to assertTrue

https://docs.python.org/2/library/unittest.html#deprecated-aliases

@ngash ngash force-pushed the ngash:update-deprecated-test-aliases branch from 5fdf175 to 49559c5 Aug 7, 2017
- change ``failIf`` to ``assertFalse``
- change ``asertEquals`` to ``assertEqual``
- change ``assert_`` to ``assertTrue``

https://docs.python.org/2/library/unittest.html#deprecated-aliases
@ngash ngash force-pushed the ngash:update-deprecated-test-aliases branch from 49559c5 to 42cb4d2 Aug 7, 2017
@codecov
Copy link

@codecov codecov bot commented Aug 7, 2017

Codecov Report

Merging #2876 into master will not change coverage.
The diff coverage is n/a.

@@          Coverage Diff           @@
##           master   #2876   +/-   ##
======================================
  Coverage    84.7%   84.7%           
======================================
  Files         164     164           
  Lines        9192    9192           
  Branches     1370    1370           
======================================
  Hits         7786    7786           
  Misses       1154    1154           
  Partials      252     252
@kmike
kmike approved these changes Aug 7, 2017
Copy link
Member

@kmike kmike left a comment

Thanks! Looks good to me.

As we're on it, it is a chance to update some of asserts to less generic ones, but I'm also fine with merging this PR as-is.

@@ -62,7 +62,7 @@ def setUp(self):
self.wrapped = WrappedResponse(self.response)

def test_info(self):
self.assert_(self.wrapped.info() is self.wrapped)
self.assertTrue(self.wrapped.info() is self.wrapped)

This comment has been minimized.

@kmike

kmike Aug 7, 2017
Member

would you mind changing it to assertIs, as we're on it?

This comment has been minimized.

@ngash

ngash Aug 8, 2017
Author Contributor

Ok

for s in v:
self.assert_(isinstance(s, bytes))
self.assertTrue(isinstance(s, bytes))

This comment has been minimized.

@kmike

kmike Aug 7, 2017
Member

it'd be awesome to change it to assertIsInstance, as we're updating this code

@@ -437,7 +437,7 @@ def test_join(self):
self.assertRaises(TypeError, proc, [None, '', 'hello', 'world'])
self.assertEqual(proc(['', 'hello', 'world']), u' hello world')
self.assertEqual(proc(['hello', 'world']), u'hello world')
self.assert_(isinstance(proc(['hello', 'world']), six.text_type))
self.assertTrue(isinstance(proc(['hello', 'world']), six.text_type))

This comment has been minimized.

@kmike

kmike Aug 7, 2017
Member

assertIsInstance

@@ -482,29 +482,29 @@ def test_constructor_errors(self):
def test_constructor_with_selector(self):
sel = Selector(text=u"<html><body><div>marta</div></body></html>")
l = TestItemLoader(selector=sel)
self.assert_(l.selector is sel)
self.assertTrue(l.selector is sel)

This comment has been minimized.

@kmike

kmike Aug 7, 2017
Member

assertIs


l.add_xpath('name', '//div/text()')
self.assertEqual(l.get_output_value('name'), [u'Marta'])

def test_constructor_with_selector_css(self):
sel = Selector(text=u"<html><body><div>marta</div></body></html>")
l = TestItemLoader(selector=sel)
self.assert_(l.selector is sel)
self.assertTrue(l.selector is sel)

This comment has been minimized.

@kmike

kmike Aug 7, 2017
Member

assertIs

self.failIf(d is d2) # shouldn't modify in place
self.failIf(any(isinstance(x, six.text_type) for x in d2.keys()))
self.failIf(any(isinstance(x, six.text_type) for x in d2.values()))
self.assertFalse(d is d2) # shouldn't modify in place

This comment has been minimized.

@kmike

kmike Aug 7, 2017
Member

assertIsNot

self.failIf(d is d2) # shouldn't modify in place
self.failIf(any(isinstance(x, six.text_type) for x in d2.keys()), d2.keys())
self.failIf(any(isinstance(x, six.text_type) for x in d2.values()))
self.assertFalse(d is d2) # shouldn't modify in place

This comment has been minimized.

@kmike

kmike Aug 7, 2017
Member

assertIsNot


@unittest.skipUnless(six.PY2, "deprecated function")
def test_stringify_dict_keys_only(self):
d = {'a': 123, u'b': 'c', u'd': u'e', object(): u'e'}
d2 = stringify_dict(d)
self.assertEqual(d, d2)
self.failIf(d is d2) # shouldn't modify in place
self.failIf(any(isinstance(x, six.text_type) for x in d2.keys()))
self.assertFalse(d is d2) # shouldn't modify in place

This comment has been minimized.

@kmike

kmike Aug 7, 2017
Member

assertIsNot

@@ -29,7 +29,7 @@ def test_send_catch_log(self):
self.assertIn('error_handler', record.getMessage())
self.assertEqual(record.levelname, 'ERROR')
self.assertEqual(result[0][0], self.error_handler)
self.assert_(isinstance(result[0][1], Failure))
self.assertTrue(isinstance(result[0][1], Failure))

This comment has been minimized.

@kmike

kmike Aug 7, 2017
Member

assertIsInstance

@@ -326,7 +326,7 @@ def testNotFound(self):
return getPage(self.getURL('notsuchfile')).addCallback(self._cbNoSuchFile)

def _cbNoSuchFile(self, pageData):
self.assert_(b'404 - No Such Resource' in pageData)
self.assertTrue(b'404 - No Such Resource' in pageData)

This comment has been minimized.

@kmike

kmike Aug 7, 2017
Member

assertIn

@@ -64,9 +64,9 @@ def test_headers(self):
h = Headers({'key1': u'val1', u'key2': 'val2'})
h[u'newkey'] = u'newval'
for k, v in h.iteritems():
self.assert_(isinstance(k, bytes))
self.assertTrue(isinstance(k, bytes))

This comment has been minimized.

@kmike

kmike Aug 7, 2017
Member

assertIsInstance

@ngash ngash force-pushed the ngash:update-deprecated-test-aliases branch from bcbb002 to 2404801 Aug 8, 2017
@redapple redapple merged commit fd27cde into scrapy:master Aug 9, 2017
2 checks passed
2 checks passed
@codecov
codecov/patch Coverage not affected when comparing a68a8f8...2404801
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@redapple
Copy link
Contributor

@redapple redapple commented Aug 9, 2017

Thank you @ngash !

@ngash ngash deleted the ngash:update-deprecated-test-aliases branch Aug 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants