Skip to content

Commit

Permalink
Fix cli set validator (#467)
Browse files Browse the repository at this point in the history
* cli: added tests for cli.Set validator

* cli: bug fix for Set validator
  • Loading branch information
koreno authored and henryiii committed Sep 22, 2019
1 parent efa082c commit 99e0cfa
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion plumbum/cli/switches.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ def __init__(self, *values, **kwargs):

def __repr__(self):
return "{{{0}}}".format(", ".join(
v if isinstance(v, str) else v.__name__ for v in self.values.values()))
v if isinstance(v, str) else v.__name__ for v in self.values))

def __call__(self, value, check_csv=True):
if self.csv and check_csv:
Expand Down
14 changes: 14 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def bacon(self, param):
benedict = cli.CountOf(["--benedict"], help = """a very long help message with lots of
useless information that nobody would ever want to read, but heck, we need to test
text wrapping in help messages as well""")
num = cli.SwitchAttr(["--num"], cli.Set("MIN", "MAX", int, csv=True))

def main(self, *args):
old = self.eggs
Expand Down Expand Up @@ -95,6 +96,7 @@ class Sample(cli.Application):

foo = cli.SwitchAttr("--foo")


Sample.unbind_switches("--version")

class Mumble(cli.Application):
Expand Down Expand Up @@ -151,10 +153,22 @@ def test_okay(self):
assert rc == 0
assert inst.eggs == "7"

_, rc = SimpleApp.run(["foo", "--bacon=81", "--num=100"], exit = False)
assert rc == 0

_, rc = SimpleApp.run(["foo", "--bacon=81", "--num=MAX,MIN,100"], exit = False)
assert rc == 0

def test_failures(self):
_, rc = SimpleApp.run(["foo"], exit = False)
assert rc == 2

_, rc = SimpleApp.run(["foo", "--bacon=81", "--num=xx"], exit = False)
assert rc == 2

_, rc = SimpleApp.run(["foo", "--bacon=81", "--num=xx"], exit = False)
assert rc == 2

_, rc = SimpleApp.run(["foo", "--bacon=hello"], exit = False)
assert rc == 2

Expand Down

0 comments on commit 99e0cfa

Please sign in to comment.