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

drop coveralls and enforce 100% coverage with no cover instead #254

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ jobs:
pip install tox

- name: tox
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: tox -e py,lint,coveralls,release
run: tox -e py,lint,release

- name: upload dist
uses: actions/upload-artifact@v2
Expand Down
3 changes: 0 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
|_|_|_\___/\__,_\___|_| |_||_|_/__\___|


.. image:: https://img.shields.io/coveralls/github/PyCQA/modernize?label=coveralls&logo=coveralls
:alt: Coveralls
:target: https://coveralls.io/github/PyCQA/modernize
.. image:: https://img.shields.io/readthedocs/modernize?logo=read-the-docs
:alt: Read the Docs
:target: https://modernize.readthedocs.io/en/latest/
Expand Down
2 changes: 1 addition & 1 deletion modernize/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
from .main import main

if __name__ == "__main__":
sys.exit(main())
sys.exit(main()) # pragma: no cover
8 changes: 4 additions & 4 deletions modernize/fixes/fix_itertools_imports_six.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ def transform(self, node, results):
for child in children[::2]:
if child.type == token.NAME:
name_node = child
elif child.type == token.STAR:
elif child.type == token.STAR: # pragma: no cover
# Just leave the import as is.
return
else:
assert child.type == syms.import_as_name
name_node = child.children[0]
assert child.type == syms.import_as_name # pragma: no cover
name_node = child.children[0] # pragma: no cover
member_name = name_node.value
if member_name in (
"imap",
Expand All @@ -61,7 +61,7 @@ def transform(self, node, results):
remove_comma ^= True

while children and children[-1].type == token.COMMA:
children.pop().remove()
children.pop().remove() # pragma: no cover

# If there are no imports left, just get rid of the entire statement
if (
Expand Down
6 changes: 4 additions & 2 deletions modernize/fixes/fix_metaclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ def find_metas(cls_node):
for i, simple_node in list(enumerate(node.children)):
if simple_node.type == syms.simple_stmt and simple_node.children:
expr_node = simple_node.children[0]
if expr_node.type == syms.expr_stmt and expr_node.children:
if (
expr_node.type == syms.expr_stmt and expr_node.children
): # pragma: no branch
# Check if the expr_node is a simple assignment.
left_node = expr_node.children[0]
if isinstance(left_node, Leaf) and left_node.value == "__metaclass__":
Expand All @@ -143,7 +145,7 @@ def fixup_indent(suite):
node = kids.pop()
if isinstance(node, Leaf) and node.type != token.DEDENT:
if node.prefix:
node.prefix = ""
node.prefix = "" # pragma: no cover
return
else:
kids.extend(node.children[::-1])
Expand Down
2 changes: 1 addition & 1 deletion modernize/fixes/fix_unichr.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ class FixUnichr(fixer_base.ConditionalFix):

def transform(self, node, results):
if self.should_skip(node):
return
return # pragma: no cover
if is_probably_builtin(node):
fixer_util.touch_import("six", "unichr", node)
24 changes: 15 additions & 9 deletions modernize/fixes/fix_urllib_six.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,17 +163,19 @@ def transform_member(self, node, results):
# Simple case with only a single member being imported
if member:
# this may be a list of length one, or just a node
if isinstance(member, list):
if isinstance(member, list): # pragma: no branch
member = member[0]
new_name = None
for change in MAPPING[mod_member.value]:
if member.value in change[1]:
for change in MAPPING[mod_member.value]: # pragma: no branch
if member.value in change[1]: # pragma: no branch
new_name = change[0]
break
if new_name:
mod_member.replace(Name(new_name, prefix=pref))
else:
self.cannot_convert(node, "This is an invalid module element")
self.cannot_convert(
node, "This is an invalid module element"
) # pragma: no cover

# Multiple members being imported
else:
Expand Down Expand Up @@ -216,7 +218,9 @@ def handle_name(name, prefix):
names.append(Comma())
names.extend(handle_name(elts[-1], pref))
new = FromImport(module, names)
if not first or node.parent.prefix.endswith(indentation):
if not first or node.parent.prefix.endswith(
indentation
): # pragma: no branch
new.prefix = indentation
new_nodes.append(new)
first = False
Expand All @@ -234,16 +238,18 @@ def transform_dot(self, node, results):
module_dot = results.get("bare_with_attr")
member = results.get("member")
new_name = None
if isinstance(member, list):
if isinstance(member, list): # pragma: no branch
member = member[0]
for change in MAPPING[module_dot.value]:
for change in MAPPING[module_dot.value]: # pragma: no branch
if member.value in change[1]:
new_name = change[0]
break
if new_name:
module_dot.replace(Name(new_name, prefix=module_dot.prefix))
else:
self.cannot_convert(node, "This is an invalid module element")
self.cannot_convert(
node, "This is an invalid module element"
) # pragma: no cover

def transform(self, node, results):
if results.get("module"):
Expand All @@ -255,5 +261,5 @@ def transform(self, node, results):
# Renaming and star imports are not supported for these modules.
elif results.get("module_star"):
self.cannot_convert(node, "Cannot handle star imports.")
elif results.get("module_as"):
elif results.get("module_as"): # pragma: no branch
self.cannot_convert(node, "This module is now multiple modules")
42 changes: 23 additions & 19 deletions modernize/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

def format_usage(usage):
"""Method that doesn't output "Usage:" prefix"""
return usage
return usage # pragma: no cover


def main(args=None):
Expand Down Expand Up @@ -134,9 +134,11 @@ def main(args=None):
flags = {}
options, args = parser.parse_args(args)
if not options.write and options.no_diffs:
warn("Not writing files and not printing diffs; that's not very useful.")
warn(
"Not writing files and not printing diffs; that's not very useful."
) # pragma: no cover
if not options.write and options.nobackups:
parser.error("Can't use '-n' without '-w'.")
parser.error("Can't use '-n' without '-w'.") # pragma: no cover
if options.list_fixes:
print(
"Standard transformations available for the "
Expand All @@ -145,21 +147,23 @@ def main(args=None):
for fixname in sorted(avail_fixes):
print(" {} ({})".format(fixname, fixname.split(".fix_", 1)[1]))
print()
if not args:
if not args: # pragma: no branch
return 0
if not args:
print("At least one file or directory argument required.", file=sys.stderr)
print("Use --help to show usage.", file=sys.stderr)
return 2
print(
"At least one file or directory argument required.", file=sys.stderr
) # pragma: no cover
print("Use --help to show usage.", file=sys.stderr) # pragma: no cover
return 2 # pragma: no cover
if "-" in args:
refactor_stdin = True
if options.write:
refactor_stdin = True # pragma: no cover
if options.write: # pragma: no cover
print("Can't write to stdin.", file=sys.stderr)
return 2
if options.print_function:
flags["print_function"] = True
flags["print_function"] = True # pragma: no cover
if options.fixers_here:
sys.path.append(os.getcwd())
sys.path.append(os.getcwd()) # pragma: no cover

# Set up logging handler
level = logging.DEBUG if options.verbose else logging.INFO
Expand All @@ -174,9 +178,9 @@ def main(args=None):
matched = None
for tgt in avail_fixes:
if tgt == fix or tgt.endswith(f".fix_{fix}"):
matched = tgt
unwanted_fixes.add(matched)
break
matched = tgt # pragma: no cover
unwanted_fixes.add(matched) # pragma: no cover
break # pragma: no cover
else:
print(f"Error: fix '{fix}' was not found", file=sys.stderr)
return 2
Expand All @@ -203,7 +207,7 @@ def main(args=None):
splitfixes.extend(fix.split(","))
for fix in splitfixes:
if fix == "default":
default_present = True
default_present = True # pragma: no cover
else:
matched = None
for tgt in avail_fixes:
Expand All @@ -213,7 +217,7 @@ def main(args=None):
break
else:
# A non-standard fix -- trust user to have supplied path
explicit.add(fix)
explicit.add(fix) # pragma: no cover
requested = default_fixes.union(explicit) if default_present else explicit
else:
requested = default_fixes
Expand All @@ -230,7 +234,7 @@ def main(args=None):
file=sys.stderr,
)
else:
print(" (None)", file=sys.stderr)
print(" (None)", file=sys.stderr) # pragma: no cover
print(" Applying the following explicit transformations:", file=sys.stderr)
if explicit:
for fixname in sorted(explicit):
Expand All @@ -250,9 +254,9 @@ def main(args=None):
options.nobackups,
not options.no_diffs,
)
if not rt.errors:
if not rt.errors: # pragma: no branch
if refactor_stdin:
rt.refactor_stdin()
rt.refactor_stdin() # pragma: no cover
else:
try:
rt.refactor(
Expand Down
20 changes: 10 additions & 10 deletions modernize/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def _check_future_import(node):
else return None."""
# node should be the import statement here
if not (node.type == syms.simple_stmt and node.children):
return set()
return set() # pragma: no cover
node = node.children[0]
# now node is the import_from node
if not (
Expand All @@ -23,7 +23,7 @@ def _check_future_import(node):

if node.children[3].type == token.LPAR:
# from __future__ import (..
node = node.children[4]
node = node.children[4] # pragma: no cover
else:
# from __future__ import ...
node = node.children[3]
Expand All @@ -35,15 +35,15 @@ def _check_future_import(node):
for n in node.children:
if n.type == token.NAME:
result.add(n.value)
elif n.type == syms.import_as_name:
n = n.children[0]
assert n.type == token.NAME
result.add(n.value)
elif n.type == syms.import_as_name: # pragma: no cover
n = n.children[0] # pragma: no cover
assert n.type == token.NAME # pragma: no cover
result.add(n.value) # pragma: no cover
return result
elif node.type == syms.import_as_name:
node = node.children[0]
assert node.type == token.NAME
return {node.value}
node = node.children[0] # pragma: no cover
assert node.type == token.NAME # pragma: no cover
return {node.value} # pragma: no cover
elif node.type == token.NAME:
return {node.value}
else: # pragma: no cover
Expand All @@ -54,7 +54,7 @@ def add_future(node, symbol):

root = fixer_util.find_root(node)

for idx, node in enumerate(root.children):
for idx, node in enumerate(root.children): # pragma: no branch
if (
node.type == syms.simple_stmt
and len(node.children) > 0
Expand Down
9 changes: 1 addition & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ addopts = [
"--strict-config",
"--strict-markers",
"--cov",
"--cov-fail-under=92.11",
"--cov-fail-under=100",
"--cov-report=term-missing:skip-covered",
]
xfail_strict = true
Expand Down Expand Up @@ -97,13 +97,6 @@ wheel_build_env = build
# empty environment to build universal wheel once per tox invocation
# https://github.com/ionelmc/tox-wheel#build-configuration

[testenv:coveralls]
passenv = GITHUB_*
deps =
coveralls
coverage>=5.3
commands = coveralls

[testenv:lint]
deps = pre-commit
commands = pre-commit run --all-files --show-diff-on-failure {posargs}
Expand Down
22 changes: 0 additions & 22 deletions tests/test_fix_imports_six.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from __future__ import generator_stop

import sys
import unittest

try:
from six.moves import tkinter
Expand All @@ -10,7 +8,6 @@

from utils import check_on_input

from modernize.fixes import fix_imports_six

MOVED_MODULE = (
"""\
Expand Down Expand Up @@ -43,22 +40,3 @@ def test_moved_module():

def test_moved_module_fromlist():
check_on_input(*MOVED_MODULE_FROMLIST)


@unittest.skipIf(sys.version_info[0] >= 3, "Test only runs on Python 2")
def test_validate_mapping():
for py2_name, six_name in fix_imports_six.FixImportsSix.mapping.items():
try:
__import__(py2_name)
__import__(six_name)
except ImportError:
if "tkinter" in six_name:
# Ignore error if tkinter not installed
if tkinter is not None:
raise
elif "winreg" in six_name:
# Ignore error if we're not on Windows
if sys.platform.startswith("win"):
raise
else:
raise
8 changes: 4 additions & 4 deletions tests/test_fixes.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ def check_existence(prefix, module_names):
dotted_prefix = prefix + "."
for module_name in module_names:
if not module_name.startswith(dotted_prefix):
msg = f"{module_name!r} does not start with {prefix!r}"
raise AssertionError(msg)
msg = f"{module_name!r} does not start with {prefix!r}" # pragma: no cover
raise AssertionError(msg) # pragma: no cover
try:
__import__(module_name)
except ImportError:
except ImportError: # pragma: no cover
raise AssertionError(f"{module_name!r} cannot be imported")


Expand All @@ -34,5 +34,5 @@ def test_fixers_importable():
for module_name in fixers:
try:
__import__(module_name)
except ImportError:
except ImportError: # pragma: no cover
raise AssertionError(f"{module_name!r} cannot be imported")
Loading