Skip to content

Commit

Permalink
Alter the test in Python 3.6+
Browse files Browse the repository at this point in the history
  • Loading branch information
fahhem committed Jun 10, 2016
1 parent 0b9e482 commit 0f505ad
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions tests/test_validate.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import print_function, division
import sys
import pytest
from plumbum import cli
from plumbum.lib import captured_stdout
Expand Down Expand Up @@ -41,13 +42,13 @@ def main(selfy, x, y, *g):

assert Try.main.positional == [abs, str]
assert Try.main.positional_varargs == int

def test_defaults(self):
class Try(object):
@cli.positional(abs, str)
def main(selfy, x, y = 'hello'):
pass

assert Try.main.positional == [abs, str]


Expand All @@ -56,8 +57,8 @@ def test_prog(self, capsys):
class MainValidator(cli.Application):
@cli.positional(int, int, int)
def main(self, myint, myint2, *mylist):
print(repr(myint), myint2, mylist)
print(repr(myint), myint2, mylist)

_, rc = MainValidator.run(["prog", "1", "2", '3', '4', '5'], exit = False)
assert rc == 0
assert "1 2 (3, 4, 5)" == capsys.readouterr()[0].strip()
Expand All @@ -69,28 +70,32 @@ class MainValidator(cli.Application):
def main(self, myint, myint2, *mylist):
print(myint, myint2, mylist)
_, rc = MainValidator.run(["prog", "1.2", "2", '3', '4', '5'], exit = False)

assert rc == 2
value = capsys.readouterr()[0].strip()
assert "'int'>, not '1.2':" in value
assert " 'int'>, not '1.2':" in value
if sys.version_info.major == 3 and sys.version_info.minor >= 6:
assert "<class 'int' " in value
assert ">, not '1.2':" in value
else:
assert "'int'>, not '1.2':" in value
assert " 'int'>, not '1.2':" in value
assert '''ValueError("invalid literal for int() with base 10: '1.2'"''' in value

def test_defaults(self, capsys):
class MainValidator(cli.Application):
@cli.positional(int, int)
def main(self, myint, myint2=2):
print(repr(myint), repr(myint2))
print(repr(myint), repr(myint2))

_, rc = MainValidator.run(["prog", "1"], exit = False)
assert rc == 0
assert "1 2" == capsys.readouterr()[0].strip()

_, rc = MainValidator.run(["prog", "1", "3"], exit = False)
assert rc == 0
assert "1 3" == capsys.readouterr()[0].strip()


# Unfortionatly, Py3 anotations are a syntax error in Py2, so using exec to add test for Py3
if six.PY3:
exec("""
Expand Down

0 comments on commit 0f505ad

Please sign in to comment.