Skip to content

Commit

Permalink
Fix test cases for Python 2
Browse files Browse the repository at this point in the history
  • Loading branch information
thombashi committed Jun 16, 2019
1 parent d36f0f7 commit 8bf019a
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions test/test_argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from __future__ import unicode_literals

import sys
from argparse import ArgumentError, ArgumentParser, ArgumentTypeError

import pytest
Expand All @@ -23,15 +24,16 @@ def test_exception(self, value):
parser = ArgumentParser()
parser.add_argument("filename", type=filename)

try:
parser.parse_args([value])
except SystemExit as e:
assert isinstance(e.__context__, ArgumentError)
else:
raise RuntimeError()
if sys.version_info[0] >= 3:
try:
parser.parse_args([value])
except SystemExit as e:
assert isinstance(e.__context__, ArgumentError)
else:
raise RuntimeError()

with pytest.raises(ArgumentTypeError):
filename(value)
with pytest.raises(ArgumentTypeError):
filename(value)


class Test_argparse_filepath_validator(object):
Expand All @@ -48,12 +50,13 @@ def test_exception(self, value):
parser = ArgumentParser()
parser.add_argument("filepath", type=filepath)

try:
parser.parse_args([value])
except SystemExit as e:
assert isinstance(e.__context__, ArgumentError)
else:
raise RuntimeError()
if sys.version_info[0] >= 3:
try:
parser.parse_args([value])
except SystemExit as e:
assert isinstance(e.__context__, ArgumentError)
else:
raise RuntimeError()

with pytest.raises(ArgumentTypeError):
filepath(value)

0 comments on commit 8bf019a

Please sign in to comment.