cli-helpers 2.15.3__tar.gz → 2.15.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {cli_helpers-2.15.3 → cli_helpers-2.15.4}/AUTHORS +1 -0
- {cli_helpers-2.15.3 → cli_helpers-2.15.4}/CHANGELOG +6 -0
- {cli_helpers-2.15.3/cli_helpers.egg-info → cli_helpers-2.15.4}/PKG-INFO +1 -1
- cli_helpers-2.15.4/cli_helpers/__init__.py +1 -0
- {cli_helpers-2.15.3 → cli_helpers-2.15.4}/cli_helpers/tabular_output/output_formatter.py +4 -3
- {cli_helpers-2.15.3 → cli_helpers-2.15.4/cli_helpers.egg-info}/PKG-INFO +1 -1
- {cli_helpers-2.15.3 → cli_helpers-2.15.4}/cli_helpers.egg-info/SOURCES.txt +1 -0
- cli_helpers-2.15.4/tests/tabular_output/test_formatter_options.py +101 -0
- cli_helpers-2.15.3/cli_helpers/__init__.py +0 -1
- {cli_helpers-2.15.3 → cli_helpers-2.15.4}/.github/PULL_REQUEST_TEMPLATE.md +0 -0
- {cli_helpers-2.15.3 → cli_helpers-2.15.4}/.github/workflows/codeql.yml +0 -0
- {cli_helpers-2.15.3 → cli_helpers-2.15.4}/.gitignore +0 -0
- {cli_helpers-2.15.3 → cli_helpers-2.15.4}/.travis/install.sh +0 -0
- {cli_helpers-2.15.3 → cli_helpers-2.15.4}/.travis.yml +0 -0
- {cli_helpers-2.15.3 → cli_helpers-2.15.4}/CONTRIBUTING.rst +0 -0
- {cli_helpers-2.15.3 → cli_helpers-2.15.4}/LICENSE +0 -0
- {cli_helpers-2.15.3 → cli_helpers-2.15.4}/MANIFEST.in +0 -0
- {cli_helpers-2.15.3 → cli_helpers-2.15.4}/README.rst +0 -0
- {cli_helpers-2.15.3 → cli_helpers-2.15.4}/appveyor.yml +0 -0
- {cli_helpers-2.15.3 → cli_helpers-2.15.4}/cli_helpers/compat.py +0 -0
- {cli_helpers-2.15.3 → cli_helpers-2.15.4}/cli_helpers/config.py +0 -0
- {cli_helpers-2.15.3 → cli_helpers-2.15.4}/cli_helpers/tabular_output/__init__.py +0 -0
- {cli_helpers-2.15.3 → cli_helpers-2.15.4}/cli_helpers/tabular_output/delimited_output_adapter.py +0 -0
- {cli_helpers-2.15.3 → cli_helpers-2.15.4}/cli_helpers/tabular_output/json_output_adapter.py +0 -0
- {cli_helpers-2.15.3 → cli_helpers-2.15.4}/cli_helpers/tabular_output/preprocessors.py +0 -0
- {cli_helpers-2.15.3 → cli_helpers-2.15.4}/cli_helpers/tabular_output/tabulate_adapter.py +0 -0
- {cli_helpers-2.15.3 → cli_helpers-2.15.4}/cli_helpers/tabular_output/tsv_output_adapter.py +0 -0
- {cli_helpers-2.15.3 → cli_helpers-2.15.4}/cli_helpers/tabular_output/vertical_table_adapter.py +0 -0
- {cli_helpers-2.15.3 → cli_helpers-2.15.4}/cli_helpers/utils.py +0 -0
- {cli_helpers-2.15.3 → cli_helpers-2.15.4}/cli_helpers.egg-info/dependency_links.txt +0 -0
- {cli_helpers-2.15.3 → cli_helpers-2.15.4}/cli_helpers.egg-info/requires.txt +0 -0
- {cli_helpers-2.15.3 → cli_helpers-2.15.4}/cli_helpers.egg-info/top_level.txt +0 -0
- {cli_helpers-2.15.3 → cli_helpers-2.15.4}/docs/Makefile +0 -0
- {cli_helpers-2.15.3 → cli_helpers-2.15.4}/docs/source/api.rst +0 -0
- {cli_helpers-2.15.3 → cli_helpers-2.15.4}/docs/source/authors.rst +0 -0
- {cli_helpers-2.15.3 → cli_helpers-2.15.4}/docs/source/changelog.rst +0 -0
- {cli_helpers-2.15.3 → cli_helpers-2.15.4}/docs/source/conf.py +0 -0
- {cli_helpers-2.15.3 → cli_helpers-2.15.4}/docs/source/contributing.rst +0 -0
- {cli_helpers-2.15.3 → cli_helpers-2.15.4}/docs/source/index.rst +0 -0
- {cli_helpers-2.15.3 → cli_helpers-2.15.4}/docs/source/license.rst +0 -0
- {cli_helpers-2.15.3 → cli_helpers-2.15.4}/docs/source/quickstart.rst +0 -0
- {cli_helpers-2.15.3 → cli_helpers-2.15.4}/release.py +0 -0
- {cli_helpers-2.15.3 → cli_helpers-2.15.4}/requirements-dev.txt +0 -0
- {cli_helpers-2.15.3 → cli_helpers-2.15.4}/setup.cfg +0 -0
- {cli_helpers-2.15.3 → cli_helpers-2.15.4}/setup.py +0 -0
- {cli_helpers-2.15.3 → cli_helpers-2.15.4}/tasks.py +0 -0
- {cli_helpers-2.15.3 → cli_helpers-2.15.4}/tests/__init__.py +0 -0
- {cli_helpers-2.15.3 → cli_helpers-2.15.4}/tests/compat.py +0 -0
- {cli_helpers-2.15.3 → cli_helpers-2.15.4}/tests/config_data/configrc +0 -0
- {cli_helpers-2.15.3 → cli_helpers-2.15.4}/tests/config_data/configspecrc +0 -0
- {cli_helpers-2.15.3 → cli_helpers-2.15.4}/tests/config_data/invalid_configrc +0 -0
- {cli_helpers-2.15.3 → cli_helpers-2.15.4}/tests/config_data/invalid_configspecrc +0 -0
- {cli_helpers-2.15.3 → cli_helpers-2.15.4}/tests/tabular_output/__init__.py +0 -0
- {cli_helpers-2.15.3 → cli_helpers-2.15.4}/tests/tabular_output/test_delimited_output_adapter.py +0 -0
- {cli_helpers-2.15.3 → cli_helpers-2.15.4}/tests/tabular_output/test_json_output_adapter.py +0 -0
- {cli_helpers-2.15.3 → cli_helpers-2.15.4}/tests/tabular_output/test_output_formatter.py +0 -0
- {cli_helpers-2.15.3 → cli_helpers-2.15.4}/tests/tabular_output/test_preprocessors.py +0 -0
- {cli_helpers-2.15.3 → cli_helpers-2.15.4}/tests/tabular_output/test_tabulate_adapter.py +0 -0
- {cli_helpers-2.15.3 → cli_helpers-2.15.4}/tests/tabular_output/test_tsv_output_adapter.py +0 -0
- {cli_helpers-2.15.3 → cli_helpers-2.15.4}/tests/tabular_output/test_vertical_table_adapter.py +0 -0
- {cli_helpers-2.15.3 → cli_helpers-2.15.4}/tests/test_cli_helpers.py +0 -0
- {cli_helpers-2.15.3 → cli_helpers-2.15.4}/tests/test_config.py +0 -0
- {cli_helpers-2.15.3 → cli_helpers-2.15.4}/tests/test_utils.py +0 -0
- {cli_helpers-2.15.3 → cli_helpers-2.15.4}/tests/utils.py +0 -0
- {cli_helpers-2.15.3 → cli_helpers-2.15.4}/tox.ini +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "2.15.4"
|
|
@@ -148,7 +148,7 @@ class TabularOutputFormatter(object):
|
|
|
148
148
|
:class:`TabularOutputFormatter` object has a default format set).
|
|
149
149
|
:param tuple preprocessors: Additional preprocessors to call before
|
|
150
150
|
any formatter preprocessors.
|
|
151
|
-
:param \*\*kwargs: Optional arguments for the formatter.
|
|
151
|
+
:param \*\*kwargs: Optional arguments for this call to the formatter.
|
|
152
152
|
:return: The formatted data.
|
|
153
153
|
:rtype: str
|
|
154
154
|
:raises ValueError: If the *format_name* is not recognized.
|
|
@@ -158,7 +158,8 @@ class TabularOutputFormatter(object):
|
|
|
158
158
|
if format_name not in self.supported_formats:
|
|
159
159
|
raise ValueError('unrecognized format "{}"'.format(format_name))
|
|
160
160
|
|
|
161
|
-
|
|
161
|
+
_, _preprocessors, formatter, fkwargs = self._output_formats[format_name]
|
|
162
|
+
fkwargs = fkwargs.copy()
|
|
162
163
|
fkwargs.update(kwargs)
|
|
163
164
|
if column_types is None:
|
|
164
165
|
data = list(data)
|
|
@@ -200,7 +201,7 @@ def format_output(data, headers, format_name, **kwargs):
|
|
|
200
201
|
:param iterable data: An :term:`iterable` (e.g. list) of rows.
|
|
201
202
|
:param iterable headers: The column headers.
|
|
202
203
|
:param str format_name: The display format to use.
|
|
203
|
-
:param \*\*kwargs: Optional arguments for the formatter.
|
|
204
|
+
:param \*\*kwargs: Optional arguments for this call to the formatter.
|
|
204
205
|
:return: The formatted data.
|
|
205
206
|
:rtype: str
|
|
206
207
|
|
|
@@ -54,6 +54,7 @@ tests/config_data/invalid_configrc
|
|
|
54
54
|
tests/config_data/invalid_configspecrc
|
|
55
55
|
tests/tabular_output/__init__.py
|
|
56
56
|
tests/tabular_output/test_delimited_output_adapter.py
|
|
57
|
+
tests/tabular_output/test_formatter_options.py
|
|
57
58
|
tests/tabular_output/test_json_output_adapter.py
|
|
58
59
|
tests/tabular_output/test_output_formatter.py
|
|
59
60
|
tests/tabular_output/test_preprocessors.py
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""Per-call options must not change another output call's defaults."""
|
|
3
|
+
|
|
4
|
+
from __future__ import unicode_literals
|
|
5
|
+
|
|
6
|
+
import pytest
|
|
7
|
+
|
|
8
|
+
from cli_helpers.tabular_output import format_output, TabularOutputFormatter
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@pytest.fixture
|
|
12
|
+
def isolated_output_formats(monkeypatch):
|
|
13
|
+
# Do not let either the regression or earlier tests change other tests' options.
|
|
14
|
+
formats = {
|
|
15
|
+
name: handler._replace(formatter_args=handler.formatter_args.copy())
|
|
16
|
+
for name, handler in TabularOutputFormatter._output_formats.items()
|
|
17
|
+
}
|
|
18
|
+
monkeypatch.setattr(TabularOutputFormatter, "_output_formats", formats)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
@pytest.mark.parametrize(
|
|
22
|
+
"caller", ["same_instance", "new_instance", "wrapper", "subclass"]
|
|
23
|
+
)
|
|
24
|
+
@pytest.mark.parametrize(
|
|
25
|
+
"data, override",
|
|
26
|
+
[
|
|
27
|
+
([[None]], {"missing_value": "one-call-only"}),
|
|
28
|
+
([["important-data"]], {"max_field_width": 5}),
|
|
29
|
+
([[1.234567]], {"floatfmt": ".1f"}),
|
|
30
|
+
],
|
|
31
|
+
)
|
|
32
|
+
def test_per_call_options_do_not_change_later_output(
|
|
33
|
+
isolated_output_formats, caller, data, override
|
|
34
|
+
):
|
|
35
|
+
class InheritedFormatter(TabularOutputFormatter):
|
|
36
|
+
pass
|
|
37
|
+
|
|
38
|
+
formatter = TabularOutputFormatter("plain")
|
|
39
|
+
|
|
40
|
+
def render(**kwargs):
|
|
41
|
+
if caller == "wrapper":
|
|
42
|
+
result = format_output(data, ["value"], "plain", **kwargs)
|
|
43
|
+
elif caller == "new_instance":
|
|
44
|
+
result = TabularOutputFormatter("plain").format_output(
|
|
45
|
+
data, ["value"], **kwargs
|
|
46
|
+
)
|
|
47
|
+
elif caller == "subclass":
|
|
48
|
+
target = formatter if kwargs else InheritedFormatter("plain")
|
|
49
|
+
result = target.format_output(data, ["value"], **kwargs)
|
|
50
|
+
else:
|
|
51
|
+
result = formatter.format_output(data, ["value"], **kwargs)
|
|
52
|
+
return "\n".join(result)
|
|
53
|
+
|
|
54
|
+
original = render()
|
|
55
|
+
assert render(**override) != original
|
|
56
|
+
assert render() == original
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def test_per_call_options_preserve_registered_defaults(isolated_output_formats):
|
|
60
|
+
marker = object()
|
|
61
|
+
defaults = {"label": "registered", "marker": marker}
|
|
62
|
+
seen_markers = []
|
|
63
|
+
|
|
64
|
+
def render(data, headers, label, marker, **_):
|
|
65
|
+
seen_markers.append(marker)
|
|
66
|
+
return iter([label])
|
|
67
|
+
|
|
68
|
+
TabularOutputFormatter.register_new_formatter(
|
|
69
|
+
"call-options", render, kwargs=defaults
|
|
70
|
+
)
|
|
71
|
+
formatter = TabularOutputFormatter("call-options")
|
|
72
|
+
assert list(formatter.format_output([], [], label="temporary")) == ["temporary"]
|
|
73
|
+
assert defaults == {"label": "registered", "marker": marker}
|
|
74
|
+
assert list(formatter.format_output([], [])) == ["registered"]
|
|
75
|
+
assert seen_markers == [marker, marker]
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
@pytest.mark.parametrize("failure_stage", ["preprocessor", "formatter"])
|
|
79
|
+
def test_failed_output_does_not_change_registered_defaults(
|
|
80
|
+
isolated_output_formats, failure_stage
|
|
81
|
+
):
|
|
82
|
+
defaults = {"label": "registered"}
|
|
83
|
+
|
|
84
|
+
def fail(data, headers, **_):
|
|
85
|
+
raise ValueError("cannot format this input")
|
|
86
|
+
|
|
87
|
+
def render(data, headers, label, **_):
|
|
88
|
+
if label == "temporary":
|
|
89
|
+
return fail(data, headers)
|
|
90
|
+
return iter([label])
|
|
91
|
+
|
|
92
|
+
TabularOutputFormatter.register_new_formatter(
|
|
93
|
+
"failing-call-options", render, kwargs=defaults
|
|
94
|
+
)
|
|
95
|
+
formatter = TabularOutputFormatter("failing-call-options")
|
|
96
|
+
preprocessors = (fail,) if failure_stage == "preprocessor" else ()
|
|
97
|
+
with pytest.raises(ValueError, match="cannot format this input"):
|
|
98
|
+
formatter.format_output([], [], preprocessors=preprocessors, label="temporary")
|
|
99
|
+
|
|
100
|
+
assert defaults == {"label": "registered"}
|
|
101
|
+
assert list(formatter.format_output([], [])) == ["registered"]
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "2.15.3"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{cli_helpers-2.15.3 → cli_helpers-2.15.4}/cli_helpers/tabular_output/delimited_output_adapter.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{cli_helpers-2.15.3 → cli_helpers-2.15.4}/cli_helpers/tabular_output/vertical_table_adapter.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{cli_helpers-2.15.3 → cli_helpers-2.15.4}/tests/tabular_output/test_delimited_output_adapter.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{cli_helpers-2.15.3 → cli_helpers-2.15.4}/tests/tabular_output/test_vertical_table_adapter.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|