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

setup.cfg: Enforce 100% branch coverage #283

Merged
merged 7 commits into from
Aug 4, 2018
Merged
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
13 changes: 13 additions & 0 deletions .ci/check_moban.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

set -ex

: "${MOBAN_BRANCH:=master}"

if [ ! -d ../coala-mobans ]; then
git clone https://gitlab.com/coala/mobans \
--branch=${MOBAN_BRANCH} ../coala-mobans
fi

moban
git diff --exit-code
4 changes: 3 additions & 1 deletion .moban.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
overrides: coala.yaml
overrides: .nocover.yaml

name: coala-quickstart
contact: [email protected]
Expand Down Expand Up @@ -44,9 +44,11 @@ configuration:
configuration_dir: ../coala-mobans/
targets:
- setup.py: coala-setup.py.jj2
- setup.cfg: setup.cfg.jj2
- requirements.txt: requirements.txt.jj2
- test-requirements.txt: test-requirements.txt.jj2
- coala_quickstart/VERSION: VERSION.jj2
- coala_quickstart/__init__.py: __init__.py.jj2
- .ci/appveyor.yml: ci/appveyor.yml.jj2
- .ci/run_with_env.cmd: run_with_env.cmd
- .ci/check_moban.sh: ci/check_moban.sh
46 changes: 46 additions & 0 deletions .nocover.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
overrides: coala.yaml

allow_generic_no_cover: true

nocover_file_globs:
# https://github.com/coala/coala-quickstart/issues/274
- coala_quickstart/generation/Bears.py
# https://github.com/coala/coala-quickstart/issues/273
- coala_quickstart/generation/FileGlobs.py
- coala_quickstart/info_extractors/EditorconfigInfoExtractor.py
# https://github.com/coala/coala-quickstart/issues/222
- coala_quickstart/info_extractors/EditorconfigParsing.py
- coala_quickstart/info_extractors/GemfileInfoExtractor.py
- coala_quickstart/info_extractors/GruntfileInfoExtractor.py

nocover_regexes:
# coala_quickstart.py
- args.green_mode
# generation/InfoMapping.py
# https://github.com/coala/coala-quickstart/issues/275
- INFO_SETTING_MAPS =
# generation/Project.py
# https://github.com/coala/coala-quickstart/issues/276
- def language_percentage
# generation/Settings.py::write_coafile
# https://github.com/coala/coala-quickstart/issues/277
- 'if os.path.isfile\(coafile\):'
# generation/SettingsFilling.py
# https://github.com/coala/coala-quickstart/issues/278
- def autofill_value
- def is_autofill_possible
- def require_setting
# generation/Settings.py::get_extensions
# https://github.com/coala/coala-quickstart/issues/279
- if ext in exts
# generation/SettingsClass.py::fillup_optional_settings
# https://github.com/coala/coala-quickstart/issues/280
- if inside_annot
# generation/SettingsClass.py::BearSettings.__init__
- if hasattr.*generate_config
# generation/Utilities.py
# https://github.com/coala/coala-quickstart/issues/281
- def is_glob_exp
- def get_gitignore_glob
- def parse_gitignore_line
- def get_language_from_hashbang
23 changes: 20 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,32 @@ python:
- 3.5
- 3.6

stages:
- test
- moban

.disable_global: &disable_global
before_install: false
install: false
script: false

.check_moban: &check_moban
<<: *disable_global
python: 3.6
stage: moban
install: pip install moban
script: .ci/check_moban.sh

jobs:
include:
- *check_moban

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  allow_failures:
    - *check_moban

?

Copy link
Member Author

@jayvdb jayvdb Aug 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No ;-)

That is only done on coala & coala-bears as we have lots of eyes on those two repos, and those two repos see enhancements first (like pytest-reqs is only working on coala core repo atm)

These other repos will not be maintained unless moban forces them to sync.

cache:
pip: true

before_install:
- pip install setuptools -U
- pip install -r requirements.txt -r test-requirements.txt
- git clone https://gitlab.com/coala/mobans ../coala-mobans
- moban
- git diff --exit-code

script:
- pytest
Expand Down
14 changes: 4 additions & 10 deletions coala_quickstart/generation/SettingsFilling.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def fill_section(section,
for setting in needed_settings.keys():
setting_bears = needed_settings[setting]['bears']
setting_help_text = needed_settings[setting]['help_text']
to_fill_values = list(autofill_value_if_possible(
to_fill_values = list(autofill_value(
setting, section, setting_bears, extracted_info))

if len(set(to_fill_values)) == 1:
Expand All @@ -71,7 +71,7 @@ def fill_section(section,
setting, setting_help_text, setting_bears, to_fill_values)
satisfied_settings.append(setting)

else:
else: # pragma: no cover
pass

for setting in satisfied_settings:
Expand All @@ -86,10 +86,7 @@ def fill_section(section,
return section


def autofill_value_if_possible(setting_key,
section,
bears,
extracted_information):
def autofill_value(setting_key, section, bears, extracted_information):
"""
For the given setting configurations, checks if there is a
possiblity of filling the value from the extracted information,
Expand Down Expand Up @@ -121,10 +118,7 @@ def autofill_value_if_possible(setting_key,
yield mapping['mapper_function'](val)


def is_autofill_possible(setting_key,
section,
bears,
extracted_info):
def is_autofill_possible(setting_key, section, bears, extracted_info):
"""
Checks if it is possible to autofill the setting values.
"""
Expand Down
2 changes: 1 addition & 1 deletion coala_quickstart/generation/Utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def split_by_language(project_files):
for lang in exts[ext]:
lang_files[lang.lower()].add(file)
lang_files['all'].add(file)
else:
else: # pragma: nocover
with open(file, 'r') as data:
hashbang = data.readline()
if(re.match(HASHBANG_REGEX, hashbang)):
Expand Down
3 changes: 0 additions & 3 deletions coala_quickstart/info_extraction/Info.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ def __init__(self,
:param extractor: ``InfoExtractor`` instance used to extract the
information.
"""
if not self.value_type:
self.value_type = (object,)

assert_type_signature(value, self.value_type, 'value')
self.source = source
self._value = value
Expand Down
4 changes: 4 additions & 0 deletions coala_quickstart/info_extraction/Utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ def assert_type_signature(value, type_signature, argname):
True
>>> assert_type_signature("tab", {"tab", "space"}, "var")
True
>>> assert_type_signature("tab", 1, "var")
Traceback (most recent call last):
...
TypeError: type_signature must be an Iterable or a type...

:param value: Object to be validated against ``type_signature``.
:param type_signature: Object that describes allowed types and values for
Expand Down
104 changes: 82 additions & 22 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,29 +1,89 @@
[bdist_wheel]
python-tag = py34.py35.py36

[tool:pytest]
norecursedirs =
.git
dist
build
venv
.env
minversion = 3.6.1

testpaths =
coala_quickstart
tests
python_files = *.py
timeout = 35
coala_quickstart
tests

python_files = *Test.py
python_classes = *Test

addopts =
--color=yes
--doctest-glob=*.rst
--doctest-modules
--cov=coala_quickstart
-r s
env =
PYTHONHASHSEED=0
# PYTHONHASHSEED=0 is required to use same hashes in pytests-xdist's workers
-r a
-p no:logging
--color=yes
--doctest-glob=*.rst
--doctest-modules
--doctest-ignore-import-error
--error-for-skips
--cov
--instafail
--profile
--reorder 'requirements.txt' 'test-requirements.txt' '*'

doctest_optionflags =
ELLIPSIS
IGNORE_EXCEPTION_DETAIL

reqsfilenamepatterns =
requirements.txt
test-requirements.txt

reqsignorevcs = True

timeout = 35

[coverage:coverage_env_plugin]
markers = True

[coverage:run]
branch=True
cover_pylib=False
source = coala_quickstart
branch = True
cover_pylib = False

plugins =
coverage_env_plugin
coverage_config_reload_plugin

source =
coala_quickstart

omit =
tests/*
setup.py
coala_quickstart/__init__.py
coala_quickstart/generation/Bears.py
coala_quickstart/generation/FileGlobs.py
coala_quickstart/info_extractors/EditorconfigInfoExtractor.py
coala_quickstart/info_extractors/EditorconfigParsing.py
coala_quickstart/info_extractors/GemfileInfoExtractor.py
coala_quickstart/info_extractors/GruntfileInfoExtractor.py

[coverage:report]
show_missing=True
fail_under = 100
show_missing = True
skip_covered = False
sort = Miss
exclude_lines =
pragma: no ?cover
pragma ${PLATFORM_SYSTEM}: no cover
pragma ${OS_NAME}: no cover
pragma Python [0-9.,]*${PYTHON_VERSION}[0-9.,]*: no cover
args.green_mode
INFO_SETTING_MAPS =
def language_percentage
if os.path.isfile\(coafile\):
def autofill_value
def is_autofill_possible
def require_setting
if ext in exts
if inside_annot
if hasattr.*generate_config
def is_glob_exp
def get_gitignore_glob
def parse_gitignore_line
def get_language_from_hashbang

[coverage:force_end_of_section]
File renamed without changes.
4 changes: 4 additions & 0 deletions tests/generation/SettingsFillingTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ def setUp(self):
self.section = Section('test')
self.section.append(Setting('key', 'val'))

def test_acquire_settings_error(self):
with self.assertRaises(TypeError):
acquire_settings(1, 2, 3)

def test_fill_settings(self):
sections = {'test': self.section}
with simulate_console_inputs() as generator:
Expand Down
6 changes: 5 additions & 1 deletion tests/info_extractors/UtilitiesTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from coala_quickstart.info_extractors import Utilities


class UtititiesTest(unittest.TestCase):
class SearchObjectRecursivelyTest(unittest.TestCase):

def setUp(self):
self.simple_dict = {
Expand Down Expand Up @@ -49,6 +49,10 @@ def setUp(self):
}
}

def test_type_error(self):
with self.assertRaises(TypeError):
Utilities.search_object_recursively(1, 1)

def test_search_object_recursively(self):
uut = Utilities.search_object_recursively

Expand Down
File renamed without changes.