Skip to content

Commit

Permalink
tests: fix tests & linting
Browse files Browse the repository at this point in the history
  • Loading branch information
TheKevJames committed Nov 4, 2021
1 parent 372443d commit 95ac8a6
Show file tree
Hide file tree
Showing 14 changed files with 120 additions and 152 deletions.
22 changes: 15 additions & 7 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ workflows:
lint:
jobs:
- linter/pre-commit:
python_version: 3.10.0
# N.B. lowest common denominator, don't want to error on not using
# the latest syntax.
python_version: 3.6.15

test-cpython:
jobs:
Expand All @@ -63,35 +65,35 @@ workflows:
tox_environment: py36
matrix:
parameters:
cov_version: ['41', '5']
cov_version: ['41', '5', '6']
- toxpy:
name: test-py3.7-cov<<matrix.cov_version>>
docker_image: '3.7'
tox_environment: py37
matrix:
parameters:
cov_version: ['41', '5']
cov_version: ['41', '5', '6']
- toxpy:
name: test-py3.8-cov<<matrix.cov_version>>
docker_image: '3.8'
tox_environment: py38
matrix:
parameters:
cov_version: ['41', '5']
cov_version: ['41', '5', '6']
- toxpy:
name: test-py3.9-cov<<matrix.cov_version>>
docker_image: '3.9'
tox_environment: py39
matrix:
parameters:
cov_version: ['41', '5']
cov_version: ['41', '5', '6']
- toxpy:
name: test-py3.10-cov<<matrix.cov_version>>
docker_image: '3.10'
tox_environment: py310
matrix:
parameters:
cov_version: ['41', '5']
cov_version: ['41', '5', '6']

test-pypy:
jobs:
Expand All @@ -100,4 +102,10 @@ workflows:
matrix:
parameters:
cov_version: ['41', '5']
docker_image: ['3-5', '3-6', '3-7']
docker_image: ['3-5', '3-6']
- toxpypy:
name: test-pypy3-7-cov<<matrix.cov_version>>
docker_image: '3-7'
matrix:
parameters:
cov_version: ['41', '5', '6']
4 changes: 4 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ repos:
- id: double-quote-string-fixer
exclude: nonunicode/.*
- id: name-tests-test
exclude: tests/data/.*
- id: requirements-txt-fixer
- repo: https://github.com/pycqa/pylint
rev: v2.11.1
Expand All @@ -53,6 +54,9 @@ repos:
- -d too-few-public-methods
- -d ungrouped-imports # conflicts with reorder-python-imports
- -d wrong-import-order # conflicts with reorder-python-imports
- -d consider-using-f-string # not py35 compatible
- -d unspecified-encoding # TODO: reevaluate
- -d disallowed-name # TODO: fix
exclude: example/.*
- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.1.10
Expand Down
5 changes: 3 additions & 2 deletions coveralls/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,9 @@ def load_config_from_environment(self):

def load_config_from_file(self):
try:
with open(os.path.join(os.getcwd(),
self.config_filename)) as config:
fname = os.path.join(os.getcwd(), self.config_filename)

with open(fname) as config:
try:
import yaml # pylint: disable=import-outside-toplevel
self.config.update(yaml.safe_load(config))
Expand Down
16 changes: 8 additions & 8 deletions coveralls/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@


def run_command(*args):
cmd = subprocess.Popen(list(args), stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
stdout, stderr = cmd.communicate()
with subprocess.Popen(list(args), stdout=subprocess.PIPE,
stderr=subprocess.PIPE) as cmd:
stdout, stderr = cmd.communicate()

if cmd.returncode != 0:
raise CoverallsException(
'command return code {}, STDOUT: "{}"\nSTDERR: "{}"'.format(
cmd.returncode, stdout, stderr))
if cmd.returncode != 0:
raise CoverallsException(
'command return code {}, STDOUT: "{}"\nSTDERR: "{}"'.format(
cmd.returncode, stdout, stderr))

return stdout.decode().strip()
return stdout.decode().strip()


def gitlog(fmt):
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
VERSION_FILE = os.path.join(os.path.abspath(os.path.dirname(__file__)),
'coveralls', 'version.py')

DESCRIPTION = open('README.rst').read()
with open('README.rst') as f:
DESCRIPTION = f.read()

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

Expand Down
2 changes: 1 addition & 1 deletion tests/api/configuration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def test_service_name_from_env(self):
assert cover.config['repo_token'] == 'a1b2c3d4'
assert cover.config['service_name'] == 'bbb'
assert cover.config['flag_name'] == 'cc'
assert cover.config['service_number'] == '1234'
assert cover.config['service_job_number'] == '1234'


@mock.patch.object(Coveralls, 'config_filename', '.coveralls.mock')
Expand Down
56 changes: 28 additions & 28 deletions tests/api/wear_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,46 +33,46 @@ def test_wet_run(self, mock_requests):
assert result == EXPECTED

def test_merge(self, _mock_requests):
coverage_file = tempfile.NamedTemporaryFile()
coverage_file.write(
b'{"source_files": [{"name": "foobar", "coverage": []}]}')
coverage_file.seek(0)
with tempfile.NamedTemporaryFile() as coverage_file:
coverage_file.write(
b'{"source_files": [{"name": "foobar", "coverage": []}]}')
coverage_file.seek(0)

api = coveralls.Coveralls(repo_token='xxx')
api.merge(coverage_file.name)
result = api.create_report()
api = coveralls.Coveralls(repo_token='xxx')
api.merge(coverage_file.name)
result = api.create_report()

source_files = json.loads(result)['source_files']
assert source_files == [{'name': 'foobar', 'coverage': []}]
source_files = json.loads(result)['source_files']
assert source_files == [{'name': 'foobar', 'coverage': []}]

def test_merge_empty_data(self, _mock_requests):
coverage_file = tempfile.NamedTemporaryFile()
coverage_file.write(b'{}')
coverage_file.seek(0)
with tempfile.NamedTemporaryFile() as coverage_file:
coverage_file.write(b'{}')
coverage_file.seek(0)

api = coveralls.Coveralls(repo_token='xxx')
api.merge(coverage_file.name)
result = api.create_report()
api = coveralls.Coveralls(repo_token='xxx')
api.merge(coverage_file.name)
result = api.create_report()

source_files = json.loads(result)['source_files']
assert source_files == []
source_files = json.loads(result)['source_files']
assert source_files == []

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

api = coveralls.Coveralls(repo_token='xxx')
api.merge(coverage_file.name)
result = api.create_report()
api = coveralls.Coveralls(repo_token='xxx')
api.merge(coverage_file.name)
result = api.create_report()

source_files = json.loads(result)['source_files']
assert source_files == []
source_files = json.loads(result)['source_files']
assert source_files == []

mock_logger.assert_called_once_with('No data to be merged; does the '
'json file contain "source_files" '
'data?')
mock_logger.assert_called_once_with(
'No data to be merged; does the json file contain '
'"source_files" data?')

def test_dry_run(self, mock_requests):
mock_requests.post.return_value.json.return_value = EXPECTED
Expand Down
4 changes: 2 additions & 2 deletions tests/cli_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,9 @@ def test_save_report_to_file_no_token(mock_coveralls):
@mock.patch.dict(os.environ, {'TRAVIS': 'True'}, clear=True)
def test_submit(mock_submit):
json_file = os.path.join(EXAMPLE_DIR, 'example.json')
json_string = open(json_file).read()
coveralls.cli.main(argv=['--submit=' + json_file])
mock_submit.assert_called_with(json_string)
with open(json_file) as f:
mock_submit.assert_called_with(f.read())


@mock.patch('coveralls.cli.Coveralls')
Expand Down
13 changes: 0 additions & 13 deletions tests/coverage_templates/bar_310.py

This file was deleted.

8 changes: 0 additions & 8 deletions tests/coverage_templates/foo.py

This file was deleted.

10 changes: 5 additions & 5 deletions tests/coverage_templates/bar.py → tests/data/foo.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
def test_func(max_val):
for idx in range(0, max_val):
if idx == -1:
print("Miss 1", idx)
print('Miss 1', idx)
elif idx == 4:
print("Hit 1", idx)
print('Hit 1', idx)
elif idx == 6:
print("Hit 2", idx)
print('Hit 2', idx)
elif idx == 12:
print("Miss 2", idx)
print('Miss 2', idx)
else:
print("Other", idx)
print('Other', idx)
3 changes: 2 additions & 1 deletion tests/git_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ def setUp(self):
self.dir = tempfile.mkdtemp()

os.chdir(self.dir)
open('README', 'a').close()
# TODO: switch to pathlib
open('README', 'a').close() # pylint: disable=consider-using-with

subprocess.call(['git', 'init'], cwd=self.dir)
subprocess.call(['git', 'config', 'user.name',
Expand Down
Loading

0 comments on commit 95ac8a6

Please sign in to comment.