File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed
Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -42,8 +42,17 @@ def findCertFile(path):
4242 return name
4343 return None
4444
45+ def merge_defaults_and_args (defaults , args ):
46+ '''merge default config parameters with input parameters from the command line'''
47+ brConfig = {}
48+ brConfig = dict (defaults )
49+ args = vars (args )
50+ brConfig .update ({k : v for k , v in args .items () if v is not None })
51+ return brConfig
52+
4553
4654def parse_defaults_from_config_file (fileName = 'config.ini' ):
55+ '''parse default parameters from a config file'''
4756 defaults = {}
4857 dirname , filename = os .path .split (os .path .abspath (__file__ ))
4958 conf_file = os .path .join (dirname , fileName )
Original file line number Diff line number Diff line change 1- from source .confParser import parse_defaults_from_config_file
1+ from source .confParser import parse_defaults_from_config_file , merge_defaults_and_args , parse_cmd_args
2+ from nose .tools import with_setup
3+
4+
5+ def my_setup ():
6+ global a ,b ,c
7+ a = parse_defaults_from_config_file ()
8+ b ,c = parse_cmd_args ([])
29
310
411def test_case01 ():
@@ -27,3 +34,11 @@ def test_case04():
2734def test_case05 ():
2835 result = parse_defaults_from_config_file ()
2936 assert int (result ['port' ]) == 4242 and int (result ['serverPort' ]) == 9084
37+
38+
39+ @with_setup (my_setup )
40+ def test_case06 ():
41+ result = merge_defaults_and_args (a , b )
42+ assert len (result .keys ()) > 0
43+ assert 'port' in result .keys ()
44+ assert 'serverPort' in result .keys ()
You can’t perform that action at this time.
0 commit comments