Skip to content

Commit

Permalink
Merge pull request #468 from tomerfiliba/more-cli-set-validator-tests
Browse files Browse the repository at this point in the history
Additional cli set validator tests
  • Loading branch information
koreno committed Sep 23, 2019
2 parents 99e0cfa + ceba09c commit 86363a1
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ 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))

csv = cli.SwitchAttr(["--csv"], cli.Set("MIN", "MAX", int, csv=True))
num = cli.SwitchAttr(["--num"], cli.Set("MIN", "MAX", int))

def main(self, *args):
old = self.eggs
Expand Down Expand Up @@ -153,20 +155,38 @@ def test_okay(self):
assert rc == 0
assert inst.eggs == "7"

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

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

_, 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)
_, rc = SimpleApp.run(["foo", "--bacon=81", "--num=MAX"], exit = False)
assert rc == 0

_, rc = SimpleApp.run(["foo", "--bacon=81", "--num=MIN"], 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)
_, rc = SimpleApp.run(["foo", "--bacon=81", "--csv=xx"], exit = False)
assert rc == 2

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

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

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

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

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

0 comments on commit 86363a1

Please sign in to comment.