From af8b18503d14533564894b3eb1f88b3ed78dd337 Mon Sep 17 00:00:00 2001 From: joncrall Date: Mon, 24 Apr 2023 10:33:27 -0400 Subject: [PATCH] Move alias test to core --- jsonargparse_tests/test_alias.py | 10 ---------- jsonargparse_tests/test_core.py | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 10 deletions(-) delete mode 100644 jsonargparse_tests/test_alias.py diff --git a/jsonargparse_tests/test_alias.py b/jsonargparse_tests/test_alias.py deleted file mode 100644 index a4ddb144..00000000 --- a/jsonargparse_tests/test_alias.py +++ /dev/null @@ -1,10 +0,0 @@ -def test_alias(): - import jsonargparse - parser = jsonargparse.ArgumentParser() - parser.add_argument('--foo', '--bar') - parsed = parser.parse_string('foo: "aaa"') - assert parsed.foo == 'aaa' - parsed = parser.parse_string('bar: "bbb"') - assert parsed.foo == 'bbb' - parsed = parser.parse_args(['--bar', 'ccc']) - assert parsed.foo == 'ccc' diff --git a/jsonargparse_tests/test_core.py b/jsonargparse_tests/test_core.py index b76dfe14..e4c8fc61 100755 --- a/jsonargparse_tests/test_core.py +++ b/jsonargparse_tests/test_core.py @@ -1223,5 +1223,22 @@ def test_add_multiple_config_arguments_error(self): parser.add_argument('--cfg2', action=ActionConfigFile) + def test_parser_alias(self): + import jsonargparse + + # Create a parser where --bar is an alias for --foo + parser = jsonargparse.ArgumentParser() + parser.add_argument('--foo', '--bar') + + parsed = parser.parse_string('foo: "aaa"') + assert parsed.foo == 'aaa' + + parsed = parser.parse_string('bar: "bbb"') + assert parsed.foo == 'bbb' + + parsed = parser.parse_args(['--bar', 'ccc']) + assert parsed.foo == 'ccc' + + if __name__ == '__main__': unittest.main(verbosity=2)