diff options
author | Patrick Totzke <patricktotzke@gmail.com> | 2017-11-05 17:51:05 +0000 |
---|---|---|
committer | Patrick Totzke <patricktotzke@gmail.com> | 2017-11-08 18:27:48 +0000 |
commit | ffcaa20e17283b23d6334b8a5039380571734cfb (patch) | |
tree | bcf22fd84081a72760e3497c8d48e6b4ac988821 | |
parent | 87225c353689f226fe0128b84ee60dd138c1bba2 (diff) |
add test for argparse validator
-rw-r--r-- | alot/commands/thread.py | 5 | ||||
-rw-r--r-- | tests/utils/argparse_test.py | 15 |
2 files changed, 18 insertions, 2 deletions
diff --git a/alot/commands/thread.py b/alot/commands/thread.py index 700149d9..dcce2edb 100644 --- a/alot/commands/thread.py +++ b/alot/commands/thread.py @@ -577,8 +577,9 @@ class ChangeDisplaymodeCommand(Command): elif self.indent == '-': newindent = tbuffer._indent_width - 1 else: - # argparse validation guarantees that self.indent is an integer - newindent = self.indent + # argparse validation guarantees that self.indent + # can be cast to an integer + newindent = int(self.indent) # make sure indent remains non-negative tbuffer._indent_width = max(newindent, 0) tbuffer.rebuild() diff --git a/tests/utils/argparse_test.py b/tests/utils/argparse_test.py index 91f8a3f4..ff339b26 100644 --- a/tests/utils/argparse_test.py +++ b/tests/utils/argparse_test.py @@ -163,3 +163,18 @@ class TestOptionalFileLike(unittest.TestCase): path = os.path.join(d, 'fifo') os.mkfifo(path) cargparse.optional_file_like(path) + + +class TestIntOrPlusOrMinus(unittest.TestCase): + """Tests for the is_int_or_pm validator.""" + + def test_int(self): + self.assertTrue(cargparse.is_int_or_pm('5')) + + def test_pm(self): + self.assertTrue(cargparse.is_int_or_pm('+')) + self.assertTrue(cargparse.is_int_or_pm('-')) + + def test_rubbish(self): + with self.assertRaises(cargparse.ValidationFailed): + cargparse.is_int_or_pm('XX') |