Skip to content

Commit 95ac8a6

Browse files
committed
tests: fix tests & linting
1 parent 372443d commit 95ac8a6

File tree

14 files changed

+120
-152
lines changed

14 files changed

+120
-152
lines changed

.circleci/config.yml

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ workflows:
4949
lint:
5050
jobs:
5151
- linter/pre-commit:
52-
python_version: 3.10.0
52+
# N.B. lowest common denominator, don't want to error on not using
53+
# the latest syntax.
54+
python_version: 3.6.15
5355

5456
test-cpython:
5557
jobs:
@@ -63,35 +65,35 @@ workflows:
6365
tox_environment: py36
6466
matrix:
6567
parameters:
66-
cov_version: ['41', '5']
68+
cov_version: ['41', '5', '6']
6769
- toxpy:
6870
name: test-py3.7-cov<<matrix.cov_version>>
6971
docker_image: '3.7'
7072
tox_environment: py37
7173
matrix:
7274
parameters:
73-
cov_version: ['41', '5']
75+
cov_version: ['41', '5', '6']
7476
- toxpy:
7577
name: test-py3.8-cov<<matrix.cov_version>>
7678
docker_image: '3.8'
7779
tox_environment: py38
7880
matrix:
7981
parameters:
80-
cov_version: ['41', '5']
82+
cov_version: ['41', '5', '6']
8183
- toxpy:
8284
name: test-py3.9-cov<<matrix.cov_version>>
8385
docker_image: '3.9'
8486
tox_environment: py39
8587
matrix:
8688
parameters:
87-
cov_version: ['41', '5']
89+
cov_version: ['41', '5', '6']
8890
- toxpy:
8991
name: test-py3.10-cov<<matrix.cov_version>>
9092
docker_image: '3.10'
9193
tox_environment: py310
9294
matrix:
9395
parameters:
94-
cov_version: ['41', '5']
96+
cov_version: ['41', '5', '6']
9597

9698
test-pypy:
9799
jobs:
@@ -100,4 +102,10 @@ workflows:
100102
matrix:
101103
parameters:
102104
cov_version: ['41', '5']
103-
docker_image: ['3-5', '3-6', '3-7']
105+
docker_image: ['3-5', '3-6']
106+
- toxpypy:
107+
name: test-pypy3-7-cov<<matrix.cov_version>>
108+
docker_image: '3-7'
109+
matrix:
110+
parameters:
111+
cov_version: ['41', '5', '6']

.pre-commit-config.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ repos:
2828
- id: double-quote-string-fixer
2929
exclude: nonunicode/.*
3030
- id: name-tests-test
31+
exclude: tests/data/.*
3132
- id: requirements-txt-fixer
3233
- repo: https://github.com/pycqa/pylint
3334
rev: v2.11.1
@@ -53,6 +54,9 @@ repos:
5354
- -d too-few-public-methods
5455
- -d ungrouped-imports # conflicts with reorder-python-imports
5556
- -d wrong-import-order # conflicts with reorder-python-imports
57+
- -d consider-using-f-string # not py35 compatible
58+
- -d unspecified-encoding # TODO: reevaluate
59+
- -d disallowed-name # TODO: fix
5660
exclude: example/.*
5761
- repo: https://github.com/Lucas-C/pre-commit-hooks
5862
rev: v1.1.10

coveralls/api.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,9 @@ def load_config_from_environment(self):
229229

230230
def load_config_from_file(self):
231231
try:
232-
with open(os.path.join(os.getcwd(),
233-
self.config_filename)) as config:
232+
fname = os.path.join(os.getcwd(), self.config_filename)
233+
234+
with open(fname) as config:
234235
try:
235236
import yaml # pylint: disable=import-outside-toplevel
236237
self.config.update(yaml.safe_load(config))

coveralls/git.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@
99

1010

1111
def run_command(*args):
12-
cmd = subprocess.Popen(list(args), stdout=subprocess.PIPE,
13-
stderr=subprocess.PIPE)
14-
stdout, stderr = cmd.communicate()
12+
with subprocess.Popen(list(args), stdout=subprocess.PIPE,
13+
stderr=subprocess.PIPE) as cmd:
14+
stdout, stderr = cmd.communicate()
1515

16-
if cmd.returncode != 0:
17-
raise CoverallsException(
18-
'command return code {}, STDOUT: "{}"\nSTDERR: "{}"'.format(
19-
cmd.returncode, stdout, stderr))
16+
if cmd.returncode != 0:
17+
raise CoverallsException(
18+
'command return code {}, STDOUT: "{}"\nSTDERR: "{}"'.format(
19+
cmd.returncode, stdout, stderr))
2020

21-
return stdout.decode().strip()
21+
return stdout.decode().strip()
2222

2323

2424
def gitlog(fmt):

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
VERSION_FILE = os.path.join(os.path.abspath(os.path.dirname(__file__)),
77
'coveralls', 'version.py')
88

9-
DESCRIPTION = open('README.rst').read()
9+
with open('README.rst') as f:
10+
DESCRIPTION = f.read()
1011

11-
VERSION = None
1212
with open(VERSION_FILE) as f:
1313
VERSION = f.read().split()[2][1:-1]
1414

tests/api/configuration_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ def test_service_name_from_env(self):
250250
assert cover.config['repo_token'] == 'a1b2c3d4'
251251
assert cover.config['service_name'] == 'bbb'
252252
assert cover.config['flag_name'] == 'cc'
253-
assert cover.config['service_number'] == '1234'
253+
assert cover.config['service_job_number'] == '1234'
254254

255255

256256
@mock.patch.object(Coveralls, 'config_filename', '.coveralls.mock')

tests/api/wear_test.py

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -33,46 +33,46 @@ def test_wet_run(self, mock_requests):
3333
assert result == EXPECTED
3434

3535
def test_merge(self, _mock_requests):
36-
coverage_file = tempfile.NamedTemporaryFile()
37-
coverage_file.write(
38-
b'{"source_files": [{"name": "foobar", "coverage": []}]}')
39-
coverage_file.seek(0)
36+
with tempfile.NamedTemporaryFile() as coverage_file:
37+
coverage_file.write(
38+
b'{"source_files": [{"name": "foobar", "coverage": []}]}')
39+
coverage_file.seek(0)
4040

41-
api = coveralls.Coveralls(repo_token='xxx')
42-
api.merge(coverage_file.name)
43-
result = api.create_report()
41+
api = coveralls.Coveralls(repo_token='xxx')
42+
api.merge(coverage_file.name)
43+
result = api.create_report()
4444

45-
source_files = json.loads(result)['source_files']
46-
assert source_files == [{'name': 'foobar', 'coverage': []}]
45+
source_files = json.loads(result)['source_files']
46+
assert source_files == [{'name': 'foobar', 'coverage': []}]
4747

4848
def test_merge_empty_data(self, _mock_requests):
49-
coverage_file = tempfile.NamedTemporaryFile()
50-
coverage_file.write(b'{}')
51-
coverage_file.seek(0)
49+
with tempfile.NamedTemporaryFile() as coverage_file:
50+
coverage_file.write(b'{}')
51+
coverage_file.seek(0)
5252

53-
api = coveralls.Coveralls(repo_token='xxx')
54-
api.merge(coverage_file.name)
55-
result = api.create_report()
53+
api = coveralls.Coveralls(repo_token='xxx')
54+
api.merge(coverage_file.name)
55+
result = api.create_report()
5656

57-
source_files = json.loads(result)['source_files']
58-
assert source_files == []
57+
source_files = json.loads(result)['source_files']
58+
assert source_files == []
5959

6060
@mock.patch.object(log, 'warning')
6161
def test_merge_invalid_data(self, mock_logger, _mock_requests):
62-
coverage_file = tempfile.NamedTemporaryFile()
63-
coverage_file.write(b'{"random": "stuff"}')
64-
coverage_file.seek(0)
62+
with tempfile.NamedTemporaryFile() as coverage_file:
63+
coverage_file.write(b'{"random": "stuff"}')
64+
coverage_file.seek(0)
6565

66-
api = coveralls.Coveralls(repo_token='xxx')
67-
api.merge(coverage_file.name)
68-
result = api.create_report()
66+
api = coveralls.Coveralls(repo_token='xxx')
67+
api.merge(coverage_file.name)
68+
result = api.create_report()
6969

70-
source_files = json.loads(result)['source_files']
71-
assert source_files == []
70+
source_files = json.loads(result)['source_files']
71+
assert source_files == []
7272

73-
mock_logger.assert_called_once_with('No data to be merged; does the '
74-
'json file contain "source_files" '
75-
'data?')
73+
mock_logger.assert_called_once_with(
74+
'No data to be merged; does the json file contain '
75+
'"source_files" data?')
7676

7777
def test_dry_run(self, mock_requests):
7878
mock_requests.post.return_value.json.return_value = EXPECTED

tests/cli_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,9 @@ def test_save_report_to_file_no_token(mock_coveralls):
180180
@mock.patch.dict(os.environ, {'TRAVIS': 'True'}, clear=True)
181181
def test_submit(mock_submit):
182182
json_file = os.path.join(EXAMPLE_DIR, 'example.json')
183-
json_string = open(json_file).read()
184183
coveralls.cli.main(argv=['--submit=' + json_file])
185-
mock_submit.assert_called_with(json_string)
184+
with open(json_file) as f:
185+
mock_submit.assert_called_with(f.read())
186186

187187

188188
@mock.patch('coveralls.cli.Coveralls')

tests/coverage_templates/bar_310.py

Lines changed: 0 additions & 13 deletions
This file was deleted.

tests/coverage_templates/foo.py

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)