Skip to content

Commit

Permalink
Fix doctests
Browse files Browse the repository at this point in the history
  • Loading branch information
suutari-ai authored and suutari committed Jan 7, 2018
1 parent 1454d2e commit d065868
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 30 deletions.
11 changes: 3 additions & 8 deletions piptools/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,9 +454,6 @@ def __exit__(self, exc_type, exc_val, exc_tb):
return


_CUR_DIR = os.path.dirname(os.path.abspath(__file__))


def iter_find_files(directory, patterns, ignored=None):
"""Returns a generator that yields file paths under a *directory*,
matching *patterns* using `glob`_ syntax (e.g., ``*.txt``). Also
Expand All @@ -470,15 +467,13 @@ def iter_find_files(directory, patterns, ignored=None):
ignored (str or list): A single pattern or list of
glob-formatted patterns to ignore.
For example, finding Python files in the current directory:
For example, finding Python files in the directory of this module:
>>> filenames = sorted(iter_find_files(_CUR_DIR, '*.py'))
>>> filenames[-1].split('/')[-1]
'typeutils.py'
>>> files = set(iter_find_files(os.path.dirname(__file__), '*.py'))
Or, Python files while ignoring emacs lockfiles:
>>> filenames = iter_find_files(_CUR_DIR, '*.py', ignored='.#*')
>>> filenames = iter_find_files('.', '*.py', ignored='.#*')
.. _glob: https://en.wikipedia.org/wiki/Glob_%28programming%29
Expand Down
42 changes: 20 additions & 22 deletions piptools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,37 +154,35 @@ def lookup_table(values, key=None, keyval=None, unique=False, use_lists=False):
Supports building normal and unique lookup tables. For example:
>>> lookup_table(['foo', 'bar', 'baz', 'qux', 'quux'],
... lambda s: s[0])
{
'b': {'bar', 'baz'},
'f': {'foo'},
'q': {'quux', 'qux'}
}
>>> assert lookup_table(
... ['foo', 'bar', 'baz', 'qux', 'quux'], lambda s: s[0]) == {
... 'b': {'bar', 'baz'},
... 'f': {'foo'},
... 'q': {'quux', 'qux'}
... }
For key functions that uniquely identify values, set unique=True:
>>> lookup_table(['foo', 'bar', 'baz', 'qux', 'quux'],
... lambda s: s[0],
... unique=True)
{
'b': 'baz',
'f': 'foo',
'q': 'quux'
}
>>> assert lookup_table(
... ['foo', 'bar', 'baz', 'qux', 'quux'], lambda s: s[0],
... unique=True) == {
... 'b': 'baz',
... 'f': 'foo',
... 'q': 'quux'
... }
The values of the resulting lookup table will be values, not sets.
For extra power, you can even change the values while building up the LUT.
To do so, use the `keyval` function instead of the `key` arg:
>>> lookup_table(['foo', 'bar', 'baz', 'qux', 'quux'],
... keyval=lambda s: (s[0], s[1:]))
{
'b': {'ar', 'az'},
'f': {'oo'},
'q': {'uux', 'ux'}
}
>>> assert lookup_table(
... ['foo', 'bar', 'baz', 'qux', 'quux'],
... keyval=lambda s: (s[0], s[1:])) == {
... 'b': {'ar', 'az'},
... 'f': {'oo'},
... 'q': {'uux', 'ux'}
... }
"""
if keyval is None:
Expand Down

0 comments on commit d065868

Please sign in to comment.