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

add --field-prefix via click.option and update doc #124

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
5 changes: 2 additions & 3 deletions histoprint/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,8 @@ def fieldprefixer_callback(ctx, param, fields):
"field_prefix",
type=str,
multiple=False,
help="String to prepend to each argument passed to --field option following --field-prefix"
"\nE.g. `histoprint -f Muon_eta --field-prefix Tau_ -f eta -f phi` ... would refer to fields"
"\n\t`Muon_eta`, `Tau_eta` and `Tau_phi`'",
help="String to prepend to all values indicated with --field option, "
"ignores position where this and --field options are specified.",
Comment on lines +83 to +84
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
help="String to prepend to all values indicated with --field option, "
"ignores position where this and --field options are specified.",
help="String to prepend to all '--field' values",

Command line options usually do not care about order so mentioning it seems more confusing than helping.

Also need to update the README. I usually just copy the output of histoprint -h directly into it, so it is exactly the same.

)
@click.option(
"-C",
Expand Down
25 changes: 11 additions & 14 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import numpy as np
import pytest
from uhi.numpy_plottable import ensure_plottable_histogram
from click.testing import CliRunner

from histoprint.cli import histoprint as cli
import histoprint as hp


Expand Down Expand Up @@ -183,16 +185,12 @@ def test_rich_histogram():
rich.print(tab)


def cli_prefix_equivalence_test():
"""
verify that the --field-prefix behaves exactly as if
using full name of field in --field
"""
from click.testing import CliRunner

from histoprint.cli import histoprint as cli
def test_cli_opt_field_prefix():
"""Test equivalence of --field-prefix cli option to explicit prepend on --field."""

runner = CliRunner()

# tests for fields "two" and "three" since share prefix of "t"
res = runner.invoke(
cli,
[
Expand All @@ -204,22 +202,21 @@ def cli_prefix_equivalence_test():
"three",
],
)
assert res.exit_code == 0

res_prefixed = runner.invoke(
cli,
[
"-s",
"tests/data/histograms.root",
"-f",
"wo",
"--field-prefix",
"t",
"-f",
"hree",
"--field-prefix",
"t",
],
)
assert res_prefixed.exit_code == 0

# assert equivalent output
# assert succesful equivalent output
assert res.exit_code == 0
assert res_prefixed.exit_code == 0
assert res.output == res_prefixed.output