Skip to content

Commit

Permalink
new: pkg: added coverage information and abilities.
Browse files Browse the repository at this point in the history
  • Loading branch information
vaab committed Jan 27, 2015
1 parent 174854f commit 1dad369
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 38 deletions.
29 changes: 29 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# .coveragerc to control coverage.py
[run]
branch = True
source = gitchangelog
[report]
# Regexes for lines to exclude from consideration
exclude_lines =
# Have to re-enable the standard pragma
pragma: no cover

# Don't complain about missing debug-only code:
def __repr__
if self\.debug

# Don't complain if tests don't hit defensive assertion code:
raise AssertionError
raise NotImplementedError

# Don't complain if non-runnable code isn't run:
if 0:
if __name__ == .__main__.:

if PY3:

if not PY3:

ignore_errors = True
[html]
directory = cover
13 changes: 8 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
language: python
python:
- "3.3"
- "3.2"
- "3.4"
- "2.7"
install: ./autogen.sh && python setup.py install && python setup.py develop easy_install gitchangelog[test]
install:
- ./autogen.sh && python setup.py install && python setup.py develop easy_install gitchangelog[test]
- pip install coverage coveralls
script:
- python -m unittest discover -fv -s test && python -m doctest gitchangelog.py
- ./autogen.sh && python setup.py sdist --formats=gztar && pip install dist/gitchangelog-$(./autogen.sh --get-version | tr "_" "-").tar.gz --upgrade
- git reset --hard HEAD ; git clean -d -f ; ./autogen.sh && python setup.py sdist --formats=gztar && pip install dist/gitchangelog-$(./autogen.sh --get-version | tr "_" "-").tar.gz --upgrade
- nosetests .
after_success:
- coveralls
18 changes: 14 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,21 @@
gitchangelog
============

.. image:: https://pypip.in/v/gitchangelog/badge.png
:target: https://pypi.python.org/pypi/gitchangelog
.. image:: http://img.shields.io/pypi/v/gitchangelog.svg?style=flat
:target: https://pypi.python.org/pypi/gitchangelog/
:alt: Latest PyPI version

.. image:: https://secure.travis-ci.org/vaab/gitchangelog.png?branch=master
:target: http://travis-ci.org/vaab/gitchangelog
.. image:: http://img.shields.io/pypi/dm/gitchangelog.svg?style=flat
:target: https://pypi.python.org/pypi/gitchangelog/
:alt: Number of PyPI downloads

.. image:: http://img.shields.io/travis/vaab/gitchangelog/master.svg?style=flat
:target: https://travis-ci.org/vaab/gitchangelog/
:alt: Travis CI build status

.. image:: http://img.shields.io/coveralls/vaab/gitchangelog/master.svg?style=flat
:target: https://coveralls.io/r/vaab/gitchangelog
:alt: Test coverage


Translate commit message history to a changelog.
Expand Down
26 changes: 4 additions & 22 deletions gitchangelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@

try:
import pystache
except ImportError:
except ImportError: ## pragma: no cover
pystache = None

try:
import mako
except ImportError:
except ImportError: ## pragma: no cover
mako = None

PY3 = sys.version_info[0] >= 3

if PY3:
imap = map
else:
else: ## pragma: no cover
imap = itertools.imap

usage_msg = """usage: %(exname)s"""
Expand Down Expand Up @@ -139,24 +139,6 @@ def final_dot(msg):
return msg


def first(elts, predicate, default=Null):
for elt in elts:
if predicate(elt):
return elt
if default is Null:
raise ValueError("No elements satisfy predicate")
else:
return default


def dedent(txt):
"""Detect if first line is not indented and dedent the remaining"""
lines = txt.strip().split("\n")
idx, line = first(enumerate(lines), lambda elt: elt[1] != "")
if line.startswith("\t") or line.startswith(" "):
return textwrap.dedent("\n".join(lines))
return line + "\n" + textwrap.dedent("\n".join(lines[idx+1:]))

def indent(text, chars=" ", first=None):
"""Return text string indented with the given chars
Expand Down Expand Up @@ -591,7 +573,7 @@ def __init__(self, path):
self.bare = self.swrap("git rev-parse --is-bare-repository") == "true"
self.toplevel = None if self.bare else \
self.swrap("git rev-parse --show-toplevel")
self.gitdir = os.path.normpath(
self.gitdir = normpath(
os.path.join(self._orig_path,
self.swrap("git rev-parse --git-dir")))

Expand Down
9 changes: 9 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[nosetests]
verbosity = 3
with-doctest = 1
doctest-extension = rst
exe = 1
with-coverage = 1
cover-package = gitchangelog
#cover-min-percentage = 90
doctest-options = +ELLIPSIS,+NORMALIZE_WHITESPACE
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
'Mustache': ["pystache", ],
'Mako': ["mako", ],
'test': [
"nose",
"minimock",
"mako",
"pystache",
Expand Down
25 changes: 18 additions & 7 deletions test/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,34 @@ def simple_renderer(data, opts):
return s


def set_env(key, value):
def set_env(**se_kwargs):

def decorator(f):

def _wrapped(*args, **kwargs):
kwargs["env"] = dict(kwargs.get("env") or os.environ)
kwargs["env"][key] = value
for key, value in se_kwargs.items():
kwargs["env"][key] = value
return f(*args, **kwargs)
return _wrapped
return decorator

tprog = os.path.join(
BASE_PATH = os.path.normpath(os.path.join(
os.path.dirname(os.path.realpath(__file__)),
"..", "gitchangelog.py")

w = set_env("tprog", tprog)(gitchangelog.wrap)
cmd = set_env("tprog", tprog)(gitchangelog.cmd)
".."))
tprog = os.path.join(BASE_PATH, "gitchangelog.py")

WITH_COVERAGE = gitchangelog.cmd("type coverage")[2] == 0
if WITH_COVERAGE:
tprog_set = set_env(
COVERAGE_FILE="%s/.coverage.2" % BASE_PATH,
PYTHONPATH="%s" % BASE_PATH,
tprog='coverage run -a --source=%s --rcfile="%s/.coveragerc" %s' % (BASE_PATH, BASE_PATH, tprog))
else:
tprog_set = set_env(tprog=tprog)

w = tprog_set(gitchangelog.wrap)
cmd = tprog_set(gitchangelog.cmd)


class ExtendedTest(unittest.TestCase):
Expand Down

0 comments on commit 1dad369

Please sign in to comment.