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

Enh tail #39

Open
wants to merge 2 commits into
base: main
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
6 changes: 6 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[run]
source=cycler
branch=True
[report]
omit =
*test*
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ matrix:

install:
- python setup.py install
- pip install coveralls six
- pip install pytest pytest-cov coverage six

script:
- python run_tests.py
- coverage run run_tests.py
- coverage report -m

after_success:
coveralls
- bash <(curl -s https://codecov.io/bash)
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ install:
- "python -c \"import struct; print(struct.calcsize('P') * 8)\""

# Install the build and runtime dependencies of the project.
- "%CMD_IN_ENV% pip install -v six nose coveralls"
- "%CMD_IN_ENV% pip install -v six nose pytest pytest-cov coverage"

# Install the generated wheel package to test it
- "python setup.py install"
Expand Down
29 changes: 29 additions & 0 deletions cycler.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,3 +558,32 @@ def _cycler(label, itr):
itr = (v[lab] for v in itr)

return Cycler._from_iter(label, itr)


def cycler_with_tail(cyl, tail):
'''After the cycle is exhausted continue to yield tail


Parameters
----------
cyl : Cycler
The cycler to iterate through

tail : dict
The dictionary to yield. Must have the same keys as ``cyl``.

Yields
------
sty : dict
'''
tk = set(tail.keys())
if cyl.keys != tk:
raise RuntimeError('The cycler has keys {} and the tail {}. The '
'different keys are {}'.format(cyl.keys,
tk, tk ^ cyl.keys))

for sty in cyl:
yield sty

while True:
yield tail
9 changes: 5 additions & 4 deletions doc/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ github https://github.com/matplotlib/cycler
cycler
Cycler
concat
cycler_with_tail

The public API of :py:mod:`cycler` consists of a class `Cycler`, a
factory function :func:`cycler`, and a concatenation function
:func:`concat`. The factory function provides a simple interface for
creating 'base' `Cycler` objects while the class takes care of the
composition and iteration logic.
factory function :func:`cycler`, a concatenation function
:func:`concat`, and a few helper functions. The factory function
provides a simple interface for creating 'base' `Cycler` objects while
the class takes care of the composition and iteration logic.


`Cycler` Usage
Expand Down
32 changes: 8 additions & 24 deletions run_tests.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,11 @@
#!/usr/bin/env python
# This file is closely based on tests.py from matplotlib
#
# This allows running the matplotlib tests from the command line: e.g.
#
# $ python run_tests.py -v -d
#
# The arguments are identical to the arguments accepted by nosetests.
#
# See https://nose.readthedocs.org/ for a detailed description of
# these options.
import nose


env = {"NOSE_WITH_COVERAGE": 1,
'NOSE_COVER_PACKAGE': ['cycler'],
'NOSE_COVER_HTML': 1}
plugins = []


def run():

nose.main(addplugins=[x() for x in plugins], env=env)

import sys
import pytest

if __name__ == '__main__':
run()
# show output results from every test function
args = []
args.extend(sys.argv[1:])
# call pytest and exit with the return code from pytest so that
# travis will fail correctly if tests fail
sys.exit(pytest.main(args))
Loading