Skip to content

Commit

Permalink
test(api): add more tests to improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
vchrombie committed Sep 13, 2024
1 parent ff75b50 commit 0c16687
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/api/encoding_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import subprocess
import unittest
from unittest import mock

from coveralls import Coveralls

Expand Down Expand Up @@ -54,3 +55,31 @@ def test_malformed_encoding_declaration_py3_or_coverage4():
' return 1'
)
assert 'branches' not in result[0]

def test_debug_bad_encoding(self):
data = {
'source_files': [
{
'name': 'bad_file.py',
'source': 'def foo():\n return "foo"\n',
'coverage': [1, 1, 1],
},
],
}

# Save the original json.dumps function
original_json_dumps = json.dumps

def mock_json_dumps(value):
if value == 'def foo():\n return "foo"\n':
raise UnicodeDecodeError('utf8', b'', 0, 1, 'bad data')

return original_json_dumps(value)

with mock.patch(
'coveralls.api.json.dumps',
side_effect=mock_json_dumps,
):
with mock.patch('coveralls.api.log') as mock_log:
Coveralls.debug_bad_encoding(data)
mock_log.error.assert_called()
14 changes: 14 additions & 0 deletions tests/api/reporter_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import subprocess
import unittest
from unittest import mock

import pytest

Expand Down Expand Up @@ -267,3 +268,16 @@ def test_not_python(self):
match=r"Couldn't parse .* as Python",
):
Coveralls(repo_token='xxx').get_coverage()

@mock.patch('requests.post')
def test_submit_report_422_github(self, mock_post):
response_mock = mock.Mock()
response_mock.status_code = 422
mock_post.return_value = response_mock

cov = Coveralls(repo_token='test_token', service_name='github')
cov.config['service_name'] = 'github'

with mock.patch('builtins.print') as mock_print:
cov.submit_report('{}')
mock_print.assert_called()

0 comments on commit 0c16687

Please sign in to comment.