More specific raise reason

This commit is contained in:
2021-04-02 19:16:09 +02:00
parent f002247885
commit 952ffecf17

13
test.py
View File

@@ -1,3 +1,4 @@
from argparse import ArgumentError, ArgumentTypeError
import unittest import unittest
from typing import List from typing import List
@@ -14,23 +15,21 @@ class TestArgClass(unittest.TestCase):
assert A.parse_args(['--arg1', 'hello']) == A(arg1='hello') assert A.parse_args(['--arg1', 'hello']) == A(arg1='hello')
@unittest.expectedFailure
def test__required_argument_missing(self): def test__required_argument_missing(self):
@argclass @argclass
class A: class A:
arg1: str arg1: str
A.parse_args([]) self.assertRaises(SystemExit, A.parse_args, [])
@unittest.expectedFailure
def test__required_argument_wrong_given(self): def test__required_argument_wrong_given(self):
@argclass @argclass
class A: class A:
arg1: str arg1: str
A.parse_args(['--arg2', 'hello']) self.assertRaises(SystemExit, A.parse_args, ['--arg2', 'hello'])
def test__optional_argument_missing(self): def test__optional_argument_missing(self):
@@ -48,14 +47,13 @@ class TestArgClass(unittest.TestCase):
assert A.parse_args(['--arg2', 'welt']) == A(arg2='welt') assert A.parse_args(['--arg2', 'welt']) == A(arg2='welt')
@unittest.expectedFailure
def test__optional_argument_wrong_given(self): def test__optional_argument_wrong_given(self):
@argclass @argclass
class A: class A:
arg2: str = 'world' arg2: str = 'world'
A.parse_args(['--arg3', 'welt']) self.assertRaises(SystemExit, A.parse_args, ['--arg3', 'welt'])
def test__boolean_true(self): def test__boolean_true(self):
@@ -81,14 +79,13 @@ class TestArgClass(unittest.TestCase):
assert A.parse_args(['--arg4', '42']) == A(arg4=42) assert A.parse_args(['--arg4', '42']) == A(arg4=42)
@unittest.expectedFailure
def test__int_malformed(self): def test__int_malformed(self):
@argclass @argclass
class A: class A:
arg4: int arg4: int
A.parse_args(['--arg4', '4e2']) self.assertRaises(SystemExit, A.parse_args, ['--arg4', '4e2'])
def test__list(self): def test__list(self):