summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorEric N. Vander Weele <ericvw@gmail.com>2019-08-30 15:17:16 -0400
committerEric N. Vander Weele <ericvw@gmail.com>2019-08-31 00:10:46 -0400
commitaadd09dd8bd91092b22b24b860d4ff2476313b1c (patch)
treeb8007cd8068739a67f84fbd6eb9d52d3916574dd /tests
parentb231c10016fa50faf7ea87b2e0530655c2184bf4 (diff)
downloadflake8-aadd09dd8bd91092b22b24b860d4ff2476313b1c.tar.gz
Set configuration file-provided values via ArgumentParser.set_defaults()
When calling `ArgumentParser.parse_args()` with the `namespace` argument, command-line options are just added to the namespace without going through any of the argument parsing and type conversion logic (e.g., the `type` keyword argument of `ArgumentParser.add_argument()`). In other words, it is assumed that a namespace is well-formed from a previous invocation of `ArgumentParser.parse_args()`. The `values` parameter is intended to be values already-provided from configuration files. To take advantage of the logic defined by `ArgumentParser.add_argument()`, utilize `ArgumentParser.set_defaults()` instead.
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/test_option_manager.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/tests/unit/test_option_manager.py b/tests/unit/test_option_manager.py
index b6ea55c..859dca1 100644
--- a/tests/unit/test_option_manager.py
+++ b/tests/unit/test_option_manager.py
@@ -29,6 +29,14 @@ def test_parse_args_forwarding_default_values(optmanager):
assert options.foo == 'bar'
+def test_parse_args_forwarding_type_coercion(optmanager):
+ """Verify default provided values are type converted from add_option."""
+ optmanager.add_option('--foo', type=int)
+ namespace = argparse.Namespace(foo='5')
+ options, args = optmanager.parse_args([], namespace)
+ assert options.foo == 5
+
+
def test_add_option_short_option_only(optmanager):
"""Verify the behaviour of adding a short-option only."""
assert optmanager.options == []