Add black to CI/CD (#1)
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Reviewed-on: https://git.deguo.duckdns.org/pavel/argclass/pulls/1 Co-authored-by: Pavel Lutskov <pavel.lutskov@gmail.com> Co-committed-by: Pavel Lutskov <pavel.lutskov@gmail.com>
This commit is contained in:
54
test.py
54
test.py
@@ -6,17 +6,14 @@ from argclass import argclass
|
||||
|
||||
|
||||
class TestArgClass(unittest.TestCase):
|
||||
|
||||
def test__required_argument(self):
|
||||
|
||||
@argclass
|
||||
class A:
|
||||
arg1: str
|
||||
|
||||
assert A.parse_args(['--arg1', 'hello']) == A(arg1='hello')
|
||||
assert A.parse_args(["--arg1", "hello"]) == A(arg1="hello")
|
||||
|
||||
def test__required_argument_missing(self):
|
||||
|
||||
@argclass
|
||||
class A:
|
||||
arg1: str
|
||||
@@ -24,101 +21,86 @@ class TestArgClass(unittest.TestCase):
|
||||
self.assertRaises(SystemExit, A.parse_args, [])
|
||||
|
||||
def test__required_argument_wrong_given(self):
|
||||
|
||||
@argclass
|
||||
class A:
|
||||
arg1: str
|
||||
|
||||
self.assertRaises(SystemExit, A.parse_args, ['--arg2', 'hello'])
|
||||
self.assertRaises(SystemExit, A.parse_args, ["--arg2", "hello"])
|
||||
|
||||
def test__optional_argument_missing(self):
|
||||
|
||||
@argclass
|
||||
class A:
|
||||
arg2: str = 'world'
|
||||
arg2: str = "world"
|
||||
|
||||
assert A.parse_args([]) == A(arg2='world')
|
||||
assert A.parse_args([]) == A(arg2="world")
|
||||
|
||||
def test__optional_argument_given(self):
|
||||
|
||||
@argclass
|
||||
class A:
|
||||
arg2: str = 'world'
|
||||
arg2: str = "world"
|
||||
|
||||
assert A.parse_args(['--arg2', 'welt']) == A(arg2='welt')
|
||||
assert A.parse_args(["--arg2", "welt"]) == A(arg2="welt")
|
||||
|
||||
def test__optional_argument_wrong_given(self):
|
||||
|
||||
@argclass
|
||||
class A:
|
||||
arg2: str = 'world'
|
||||
arg2: str = "world"
|
||||
|
||||
self.assertRaises(SystemExit, A.parse_args, ['--arg3', 'welt'])
|
||||
self.assertRaises(SystemExit, A.parse_args, ["--arg3", "welt"])
|
||||
|
||||
def test__boolean_true(self):
|
||||
|
||||
@argclass
|
||||
class A:
|
||||
arg3: bool
|
||||
|
||||
assert A.parse_args(['--arg3']) == A(arg3=True)
|
||||
assert A.parse_args(["--arg3"]) == A(arg3=True)
|
||||
|
||||
def test__boolean_false(self):
|
||||
|
||||
@argclass
|
||||
class A:
|
||||
arg3: bool
|
||||
|
||||
assert A.parse_args(['--no-arg3']) == A(arg3=False)
|
||||
assert A.parse_args(["--no-arg3"]) == A(arg3=False)
|
||||
|
||||
def test__int(self):
|
||||
|
||||
@argclass
|
||||
class A:
|
||||
arg4: int
|
||||
|
||||
assert A.parse_args(['--arg4', '42']) == A(arg4=42)
|
||||
assert A.parse_args(["--arg4", "42"]) == A(arg4=42)
|
||||
|
||||
def test__int_malformed(self):
|
||||
|
||||
@argclass
|
||||
class A:
|
||||
arg4: int
|
||||
|
||||
self.assertRaises(SystemExit, A.parse_args, ['--arg4', '4e2'])
|
||||
self.assertRaises(SystemExit, A.parse_args, ["--arg4", "4e2"])
|
||||
|
||||
def test__list(self):
|
||||
|
||||
@argclass
|
||||
class A:
|
||||
arg5: List
|
||||
|
||||
assert (
|
||||
A.parse_args(['--arg5', 'hello', 'world'])
|
||||
==
|
||||
A(arg5=['hello', 'world'])
|
||||
assert A.parse_args(["--arg5", "hello", "world"]) == A(
|
||||
arg5=["hello", "world"]
|
||||
)
|
||||
|
||||
def test__list_str(self):
|
||||
|
||||
@argclass
|
||||
class A:
|
||||
arg5: List[str]
|
||||
|
||||
assert (
|
||||
A.parse_args(['--arg5', 'hello', 'world'])
|
||||
==
|
||||
A(arg5=['hello', 'world'])
|
||||
assert A.parse_args(["--arg5", "hello", "world"]) == A(
|
||||
arg5=["hello", "world"]
|
||||
)
|
||||
|
||||
def test__list_int(self):
|
||||
|
||||
@argclass
|
||||
class A:
|
||||
arg5: List[int]
|
||||
|
||||
assert A.parse_args(['--arg5', '23', '42']) == A(arg5=[23, 42])
|
||||
assert A.parse_args(["--arg5", "23", "42"]) == A(arg5=[23, 42])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user