Skip to content

Commit

Permalink
Fix pytest warnings
Browse files Browse the repository at this point in the history
The recently released pytest-3.1.0 outputs all warnings at the end of
the testrun. This commit fixes all warnings in the coala unit tests.
See coala#4303 (comment)
for the list of warnings that are detected by pytest.

Closes coala#4303
  • Loading branch information
twmr committed Jun 12, 2017
1 parent 275da99 commit 6fa7c4e
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 33 deletions.
2 changes: 1 addition & 1 deletion coalib/parsing/Globbing.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def translate(pattern):
regex += '[' + sequence + ']'
else:
regex = regex + re.escape(char)
return regex + '\\Z(?ms)'
return '(?ms)' + regex + '\\Z'


def fnmatch(name, globs):
Expand Down
2 changes: 1 addition & 1 deletion test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ argcomplete~=1.8
coverage~=4.3.4
codecov~=2.0.5
freezegun~=0.3.9
pytest~=3.0
pytest~=3.1.1
pytest-cov~=2.2
pytest-env~=0.6.0
pytest-mock~=1.1
Expand Down
4 changes: 2 additions & 2 deletions tests/bearlib/languages/LanguageTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ def tearDown(self):
pass

def test_invalid_attribute(self):
with self.assertRaisesRegexp(AttributeError, 'not a valid attribute'):
with self.assertRaisesRegex(AttributeError, 'not a valid attribute'):
self.lang_cpp.not_an_attribute

def test_attribute_list_empy(self):
with self.assertRaisesRegexp(AttributeError, 'no available attribute'):
with self.assertRaisesRegex(AttributeError, 'no available attribute'):
self.lang_unknown.not_an_attribute
11 changes: 6 additions & 5 deletions tests/bears/BearTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ def test_connection_timeout_mocked(self):
exc = requests.exceptions.ConnectTimeout
with requests_mock.Mocker() as reqmock:
reqmock.get(self.mock_url, exc=exc)
with self.assertRaisesRegexp(exc, '^$'):
with self.assertRaisesRegex(exc, '^$'):
self.uut.download_cached_file(
self.mock_url, self.filename)

Expand All @@ -380,17 +380,18 @@ def test_read_broken(self):

with requests_mock.Mocker() as reqmock:
reqmock.get(self.mock_url, body=fake_content_provider)
with self.assertRaisesRegexp(exc, 'Fake read timeout'):
with self.assertRaisesRegex(exc, 'Fake read timeout'):
self.uut.download_cached_file(
self.mock_url, self.filename)

self.assertTrue(isfile(self.file_location))
self.assertEqual(open(self.file_location, 'rb').read(),
b''.join(fake_content))

with open(self.file_location, 'rb') as fh:
self.assertEqual(fh.read(), b''.join(fake_content))

def test_status_code_error(self):
exc = requests.exceptions.HTTPError
with self.assertRaisesRegexp(exc, '418 Client Error'):
with self.assertRaisesRegex(exc, '418 Client Error'):
self.uut.download_cached_file(
'http://httpbin.org/status/418', self.filename)

Expand Down
4 changes: 2 additions & 2 deletions tests/core/BearTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,13 +211,13 @@ def test_download_cached_file_connection_timeout_mocked(self):
exc = requests.exceptions.ConnectTimeout
with requests_mock.Mocker() as reqmock:
reqmock.get(mock_url, exc=exc)
with self.assertRaisesRegexp(exc, '^$'):
with self.assertRaisesRegex(exc, '^$'):
Bear.download_cached_file(
mock_url, 'test.html')

def test_download_cached_file_status_code_error(self):
exc = requests.exceptions.HTTPError
with self.assertRaisesRegexp(exc, '418 Client Error'):
with self.assertRaisesRegex(exc, '418 Client Error'):
Bear.download_cached_file(
'http://httpbin.org/status/418', 'test.html')

Expand Down
38 changes: 19 additions & 19 deletions tests/output/JSONEncoderTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,25 +56,25 @@ class JSONEncoderTest(unittest.TestCase):
kw = {'cls': JSONEncoder, 'sort_keys': True}

def test_builtins(self):
self.assertEquals('"test"', json.dumps('test', **self.kw))
self.assertEquals('1', json.dumps(1, **self.kw))
self.assertEquals('true', json.dumps(True, **self.kw))
self.assertEquals('null', json.dumps(None, **self.kw))
self.assertEqual('"test"', json.dumps('test', **self.kw))
self.assertEqual('1', json.dumps(1, **self.kw))
self.assertEqual('true', json.dumps(True, **self.kw))
self.assertEqual('null', json.dumps(None, **self.kw))

def test_iter(self):
self.assertEquals('[0, 1]', json.dumps([0, 1], **self.kw))
self.assertEquals('[0, 1]', json.dumps((0, 1), **self.kw))
self.assertEquals('[0, 1]', json.dumps(range(2), **self.kw))
self.assertEqual('[0, 1]', json.dumps([0, 1], **self.kw))
self.assertEqual('[0, 1]', json.dumps((0, 1), **self.kw))
self.assertEqual('[0, 1]', json.dumps(range(2), **self.kw))

def test_dict(self):
self.assertEquals('{"0": 1}', json.dumps({0: 1}, **self.kw))
self.assertEquals('{"0": 1}', json.dumps({'0': 1}, **self.kw))
self.assertEquals('{"0": "1"}', json.dumps({'0': '1'}, **self.kw))
self.assertEqual('{"0": 1}', json.dumps({0: 1}, **self.kw))
self.assertEqual('{"0": 1}', json.dumps({'0': 1}, **self.kw))
self.assertEqual('{"0": "1"}', json.dumps({'0': '1'}, **self.kw))

def test_time(self):
tf = datetime.today()
self.assertEquals('"' + tf.isoformat() + '"',
json.dumps(tf, **self.kw))
self.assertEqual('"' + tf.isoformat() + '"',
json.dumps(tf, **self.kw))

def test_re_object(self):
uut = re.compile('x')
Expand All @@ -83,19 +83,19 @@ def test_re_object(self):

def test_class1(self):
tc1 = TestClass1()
self.assertEquals('{"a": 0}', json.dumps(tc1, **self.kw))
self.assertEquals('[{"a": 0}]', json.dumps([tc1], **self.kw))
self.assertEquals('{"0": {"a": 0}}', json.dumps({0: tc1}, **self.kw))
self.assertEqual('{"a": 0}', json.dumps(tc1, **self.kw))
self.assertEqual('[{"a": 0}]', json.dumps([tc1], **self.kw))
self.assertEqual('{"0": {"a": 0}}', json.dumps({0: tc1}, **self.kw))

def test_class2(self):
tc2 = TestClass2()
self.assertEquals('{"a": 0, "b": {"a": 0}}',
json.dumps(tc2, **self.kw))
self.assertEqual('{"a": 0, "b": {"a": 0}}',
json.dumps(tc2, **self.kw))

def test_class3(self):
tc3 = TestClass3()
self.assertEquals('{"key": "val"}',
json.dumps(tc3, **self.kw))
self.assertEqual('{"key": "val"}',
json.dumps(tc3, **self.kw))

def test_propertied_class(self):
uut = PropertiedClass()
Expand Down
4 changes: 2 additions & 2 deletions tests/parsing/DefaultArgParserTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ def test_metavar_in_usage(self):
self.output,
flags=re.DOTALL)
self.assertIsNotNone(match)
self.assertEquals(match.group(1), '-a [BOOL]')
self.assertEqual(match.group(1), '-a [BOOL]')

def test_metavar_not_in_optional_args_sections(self):
match = re.search('optional arguments:.+(-a, --all).*',
self.output,
flags=re.DOTALL)
self.assertIsNotNone(match)
self.assertEquals(match.group(1), '-a, --all')
self.assertEqual(match.group(1), '-a, --all')
3 changes: 2 additions & 1 deletion tests/results/result_actions/ApplyPatchActionTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ def test_apply_rename(self):
file_diff_dict)
self.assertFalse(isfile(f_a+'.renamed.orig'))

file_dict = {f_a+'.renamed': open(f_a+'.renamed').readlines()}
with open(f_a+'.renamed') as fh:
file_dict = {f_a+'.renamed': fh.readlines()}

self.assertEqual(file_dict, expected_file_dict)
# Recreate file so that context manager make_temp() can delete it
Expand Down

0 comments on commit 6fa7c4e

Please sign in to comment.