Merge "Test and refactor argument parsing"

This commit is contained in:
Jenkins 2016-05-12 16:33:07 +00:00 committed by Gerrit Code Review
commit 6112be5294
2 changed files with 19 additions and 3 deletions

View File

@ -22,6 +22,7 @@ import netaddr
import os
import Queue
import random
import sys
import tarfile
import uuid
import yaml
@ -86,7 +87,7 @@ class MultipleIpForHostError(Exception):
return self.message
def args():
def args(arg_list):
"""Setup argument Parsing."""
parser = argparse.ArgumentParser(
usage='%(prog)s',
@ -105,7 +106,7 @@ def args():
action='store_true'
)
return vars(parser.parse_args())
return vars(parser.parse_args(arg_list))
def get_ip_address(name, ip_q):
@ -1142,6 +1143,6 @@ def main(all_args):
return dynamic_inventory_json
if __name__ == '__main__':
all_args = args()
all_args = args(sys.argv[1:])
output = main(all_args)
print(output)

View File

@ -47,6 +47,21 @@ def get_inventory():
cleanup()
class TestArgParser(unittest.TestCase):
def test_no_args(self):
arg_dict = di.args([])
self.assertEqual(arg_dict['config'], None)
self.assertEqual(arg_dict['list'], False)
def test_list_arg(self):
arg_dict = di.args(['--list'])
self.assertEqual(arg_dict['list'], True)
def test_config_arg(self):
arg_dict = di.args(['--config', '/etc/openstack_deploy'])
self.assertEqual(arg_dict['config'], '/etc/openstack_deploy')
class TestAnsibleInventoryFormatConstraints(unittest.TestCase):
inventory = None