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):
42
42
return name
43
43
return None
44
44
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
+
45
53
46
54
def parse_defaults_from_config_file (fileName = 'config.ini' ):
55
+ '''parse default parameters from a config file'''
47
56
defaults = {}
48
57
dirname , filename = os .path .split (os .path .abspath (__file__ ))
49
58
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 ([])
2
9
3
10
4
11
def test_case01 ():
@@ -27,3 +34,11 @@ def test_case04():
27
34
def test_case05 ():
28
35
result = parse_defaults_from_config_file ()
29
36
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