params 0.0.9 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,3 @@
1
- module BBFS
2
- module Params
3
- VERSION = "0.0.9" # Parser updated in params.rb
4
- end
1
+ module Params
2
+ VERSION = "1.0.0"
5
3
  end
@@ -6,275 +6,273 @@ require 'yaml'
6
6
 
7
7
  require_relative '../../lib/params.rb'
8
8
 
9
- module BBFS
10
- module Params
11
- # make private methods or Params public for testing capability.
12
- public_class_method :print_global_parameters, :parse_command_line_arguments, \
9
+ module Params
10
+ # make private methods or Params public for testing capability.
11
+ public_class_method :print_global_parameters, :parse_command_line_arguments, \
13
12
  :raise_error_if_param_exists, :raise_error_if_param_does_not_exist, \
14
13
  :read_yml_params, :override_param
15
14
 
16
- module Spec
17
-
18
- describe 'Params::parameter' do
19
-
20
- it 'should define a new parameters' do
21
- Params.string 'par_str', 'sss' ,'desc_str'
22
- Params.integer 'par_int',1 , 'desc_int'
23
- Params.float 'par_float',2.6 , 'desc_float'
24
- Params.boolean 'par_true', true, 'desc_true'
25
- Params.boolean 'par_false',false , 'desc_false'
26
- Params['par_str'].should eq 'sss'
27
- Params['par_int'].should eq 1
28
- Params['par_float'].should eq 2.6
29
- Params['par_true'].should eq true
30
- Params['par_false'].should eq false
31
- end
32
-
33
- it 'should raise an error for wrong parameter type definition.' do
34
- expect { Params::Param.new 'bad_type', nil, 'non_existing_type', 'desc_bad_type' }.should raise_error
35
- end
36
-
37
- it 'should raise an error when trying to define twice the same parameter' do
38
- Params.string 'only_once', '1st' ,''
39
- expect { Params.string 'only_once', '2nd' ,'' }.to raise_error \
15
+ module Spec
16
+
17
+ describe 'Params::parameter' do
18
+
19
+ it 'should define a new parameters' do
20
+ Params.string 'par_str', 'sss' ,'desc_str'
21
+ Params.integer 'par_int',1 , 'desc_int'
22
+ Params.float 'par_float',2.6 , 'desc_float'
23
+ Params.boolean 'par_true', true, 'desc_true'
24
+ Params.boolean 'par_false',false , 'desc_false'
25
+ Params['par_str'].should eq 'sss'
26
+ Params['par_int'].should eq 1
27
+ Params['par_float'].should eq 2.6
28
+ Params['par_true'].should eq true
29
+ Params['par_false'].should eq false
30
+ end
31
+
32
+ it 'should raise an error for wrong parameter type definition.' do
33
+ expect { Params::Param.new 'bad_type', 5, 'non_existing_type', 'desc_bad_type' }.to raise_error
34
+ end
35
+
36
+ it 'should raise an error when trying to define twice the same parameter' do
37
+ Params.string 'only_once', '1st' ,''
38
+ expect { Params.string 'only_once', '2nd' ,'' }.to raise_error \
40
39
  "Parameter:'only_once', can only be defined once."
41
- end
42
40
  end
41
+ end
43
42
 
44
- describe 'Params::read_yml_params' do
45
- it 'should raise error when yml parameter is not defined' do
46
- expect { Params::read_yml_params StringIO.new 'not_defined: 10' }.to raise_error \
43
+ describe 'Params::read_yml_params' do
44
+ it 'should raise error when yml parameter is not defined' do
45
+ expect { Params::read_yml_params StringIO.new 'not_defined: 10' }.to raise_error \
47
46
  "Parameter:'not_defined' has not been defined and can not be overridden. " \
48
47
  "It should first be defined through Param module methods:" \
49
- "Params.string, Params.integer, Params.float or Params.boolean."
50
- end
51
-
52
- it 'Will test yml parameter loading' do
53
- # string to other. Will not raise error. Instead a cast is made.
54
- Params.string('tmp4str', 'string_value', 'tmp4 def')
55
- expect { Params::read_yml_params StringIO.new 'tmp4str: strr' }.to_not raise_error
56
- expect { Params::read_yml_params StringIO.new 'tmp4str: 4' }.to_not raise_error
57
- expect { Params::read_yml_params StringIO.new 'tmp4str: 4.5' }.to_not raise_error
58
- expect { Params::read_yml_params StringIO.new 'tmp4str: true' }.to_not raise_error
59
- expect { Params::read_yml_params StringIO.new 'tmp4str: false' }.to_not raise_error
60
-
61
- # override integer with other types.
62
- Params.integer('tmp4int', 1, 'tmp4 def')
63
- expect { Params::read_yml_params StringIO.new 'tmp4int: strr' }.to raise_error \
48
+ "Params.string, Params.path, Params.integer, Params.float or Params.boolean."
49
+ end
50
+
51
+ it 'Will test yml parameter loading' do
52
+ # string to other. Will not raise error. Instead a cast is made.
53
+ Params.string('tmp4str', 'string_value', 'tmp4 def')
54
+ expect { Params::read_yml_params StringIO.new 'tmp4str: strr' }.to_not raise_error
55
+ expect { Params::read_yml_params StringIO.new 'tmp4str: 4' }.to_not raise_error
56
+ expect { Params::read_yml_params StringIO.new 'tmp4str: 4.5' }.to_not raise_error
57
+ expect { Params::read_yml_params StringIO.new 'tmp4str: true' }.to_not raise_error
58
+ expect { Params::read_yml_params StringIO.new 'tmp4str: false' }.to_not raise_error
59
+
60
+ # override integer with other types.
61
+ Params.integer('tmp4int', 1, 'tmp4 def')
62
+ expect { Params::read_yml_params StringIO.new 'tmp4int: strr' }.to raise_error \
64
63
  "Parameter:'tmp4int' type:'Integer' but value type to override " \
65
64
  "is:'String'."
66
- expect { Params::read_yml_params StringIO.new 'tmp4int: 4' }.to_not raise_error
67
- expect { Params::read_yml_params StringIO.new 'tmp4int: 4.5' }.to raise_error \
65
+ expect { Params::read_yml_params StringIO.new 'tmp4int: 4' }.to_not raise_error
66
+ expect { Params::read_yml_params StringIO.new 'tmp4int: 4.5' }.to raise_error \
68
67
  "Parameter:'tmp4int' type:'Integer' but value type to override " \
69
68
  "is:'Float'."
70
- expect { Params::read_yml_params StringIO.new 'tmp4int: true' }.to raise_error \
69
+ expect { Params::read_yml_params StringIO.new 'tmp4int: true' }.to raise_error \
71
70
  "Parameter:'tmp4int' type:'Integer' but value type to override " \
72
71
  "is:'TrueClass'."
73
- expect { Params::read_yml_params StringIO.new 'tmp4int: false' }.to raise_error \
72
+ expect { Params::read_yml_params StringIO.new 'tmp4int: false' }.to raise_error \
74
73
  "Parameter:'tmp4int' type:'Integer' but value type to override " \
75
74
  "is:'FalseClass'."
76
75
 
77
- # override float with other types.
78
- Params.float('tmp4float', 1.1, 'tmp4 def')
79
- expect { Params::read_yml_params StringIO.new 'tmp4float: strr' }.to raise_error \
76
+ # override float with other types.
77
+ Params.float('tmp4float', 1.1, 'tmp4 def')
78
+ expect { Params::read_yml_params StringIO.new 'tmp4float: strr' }.to raise_error \
80
79
  "Parameter:'tmp4float' type:'Float' but value type to override " \
81
80
  "is:'String'."
82
- expect { Params::read_yml_params StringIO.new 'tmp4float: 4' }.to_not raise_error
83
- expect { Params::read_yml_params StringIO.new 'tmp4float: 4.5' }.to_not raise_error
84
- expect { Params::read_yml_params StringIO.new 'tmp4float: true' }.to raise_error \
81
+ expect { Params::read_yml_params StringIO.new 'tmp4float: 4' }.to_not raise_error
82
+ expect { Params::read_yml_params StringIO.new 'tmp4float: 4.5' }.to_not raise_error
83
+ expect { Params::read_yml_params StringIO.new 'tmp4float: true' }.to raise_error \
85
84
  "Parameter:'tmp4float' type:'Float' but value type to override " \
86
85
  "is:'TrueClass'."
87
- expect { Params::read_yml_params StringIO.new 'tmp4float: false' }.to raise_error \
86
+ expect { Params::read_yml_params StringIO.new 'tmp4float: false' }.to raise_error \
88
87
  "Parameter:'tmp4float' type:'Float' but value type to override " \
89
88
  "is:'FalseClass'."
90
- # override boolean with other types.
91
- Params.boolean('tmp4true', true, 'tmp4 def')
92
- expect { Params::read_yml_params StringIO.new 'tmp4true: strr' }.to raise_error \
89
+ # override boolean with other types.
90
+ Params.boolean('tmp4true', true, 'tmp4 def')
91
+ expect { Params::read_yml_params StringIO.new 'tmp4true: strr' }.to raise_error \
93
92
  "Parameter:'tmp4true' type:'Boolean' but value type to override " \
94
93
  "is:'String'."
95
- expect { Params::read_yml_params StringIO.new 'tmp4true: 4' }.to raise_error \
94
+ expect { Params::read_yml_params StringIO.new 'tmp4true: 4' }.to raise_error \
96
95
  "Parameter:'tmp4true' type:'Boolean' but value type to override " \
97
96
  "is:'Fixnum'."
98
- expect { Params::read_yml_params StringIO.new 'tmp4true: 4.5' }.to raise_error \
97
+ expect { Params::read_yml_params StringIO.new 'tmp4true: 4.5' }.to raise_error \
99
98
  "Parameter:'tmp4true' type:'Boolean' but value type to override " \
100
99
  "is:'Float'."
101
- expect { Params::read_yml_params StringIO.new 'tmp4true: true' }.to_not raise_error
102
- expect { Params.read_yml_params StringIO.new 'tmp4true: false' }.to_not raise_error
100
+ expect { Params::read_yml_params StringIO.new 'tmp4true: true' }.to_not raise_error
101
+ expect { Params.read_yml_params StringIO.new 'tmp4true: false' }.to_not raise_error
103
102
 
104
- Params.boolean('tmp4False', true, 'tmp4 def')
105
- expect { Params.read_yml_params StringIO.new 'tmp4False: strr' }.to raise_error \
103
+ Params.boolean('tmp4False', true, 'tmp4 def')
104
+ expect { Params.read_yml_params StringIO.new 'tmp4False: strr' }.to raise_error \
106
105
  "Parameter:'tmp4False' type:'Boolean' but value type to override " \
107
106
  "is:'String'."
108
- expect { Params.read_yml_params StringIO.new 'tmp4False: 4' }.to raise_error \
107
+ expect { Params.read_yml_params StringIO.new 'tmp4False: 4' }.to raise_error \
109
108
  "Parameter:'tmp4False' type:'Boolean' but value type to override " \
110
109
  "is:'Fixnum'."
111
- expect { Params.read_yml_params StringIO.new 'tmp4False: 4.5' }.to raise_error \
110
+ expect { Params.read_yml_params StringIO.new 'tmp4False: 4.5' }.to raise_error \
112
111
  "Parameter:'tmp4False' type:'Boolean' but value type to override " \
113
112
  "is:'Float'."
114
- expect { Params.read_yml_params StringIO.new 'tmp4False: true' }.to_not raise_error
115
- expect { Params.read_yml_params StringIO.new 'tmp4False: false' }.to_not raise_error
116
-
117
- end
118
-
119
- it 'should raise error when yml file format is bad' do
120
- expect { Params.read_yml_params StringIO.new 'bad yml format' }.to raise_error
121
- end
122
-
123
- it 'should override defined values with yml values' do
124
- Params.string('tmp5str', 'aaa', 'tmp5 def')
125
- Params.integer('tmp5int', 11, 'tmp5 def')
126
- Params.float('tmp5float', 11.11, 'tmp5 def')
127
- Params.boolean('tmp5true', true, 'tmp5 def')
128
- Params.boolean('tmp5false', false, 'tmp5 def')
129
- Params.read_yml_params StringIO.new "tmp5str: bbb\ntmp5int: 12\ntmp5float: 12.12\n"
130
- Params.read_yml_params StringIO.new "tmp5true: false\ntmp5false: true\n"
131
- Params['tmp5str'].should eq 'bbb'
132
- Params['tmp5int'].should eq 12
133
- Params['tmp5float'].should eq 12.12
134
- Params['tmp5true'].should eq false
135
- Params['tmp5false'].should eq true
136
- end
113
+ expect { Params.read_yml_params StringIO.new 'tmp4False: true' }.to_not raise_error
114
+ expect { Params.read_yml_params StringIO.new 'tmp4False: false' }.to_not raise_error
115
+
116
+ end
117
+
118
+ it 'should raise error when yml file format is bad' do
119
+ expect { Params.read_yml_params StringIO.new '"bad yml format' }.to raise_error
120
+ end
121
+
122
+ it 'should override defined values with yml values' do
123
+ Params.string('tmp5str', 'aaa', 'tmp5 def')
124
+ Params.integer('tmp5int', 11, 'tmp5 def')
125
+ Params.float('tmp5float', 11.11, 'tmp5 def')
126
+ Params.boolean('tmp5true', true, 'tmp5 def')
127
+ Params.boolean('tmp5false', false, 'tmp5 def')
128
+ Params.read_yml_params StringIO.new "tmp5str: bbb\ntmp5int: 12\ntmp5float: 12.12\n"
129
+ Params.read_yml_params StringIO.new "tmp5true: false\ntmp5false: true\n"
130
+ Params['tmp5str'].should eq 'bbb'
131
+ Params['tmp5int'].should eq 12
132
+ Params['tmp5float'].should eq 12.12
133
+ Params['tmp5true'].should eq false
134
+ Params['tmp5false'].should eq true
135
+ end
136
+ end
137
+
138
+ describe 'Params.parse_command_line_arguments' do
139
+ it 'should raise error when command line parameter is not defined' do
140
+ expect { Params.parse_command_line_arguments ['--new_param=9]'] }.to raise_error
137
141
  end
138
142
 
139
- describe 'Params.parse_command_line_arguments' do
140
- it 'should raise error when command line parameter is not defined' do
141
- expect { Params.parse_command_line_arguments ['--new_param=9]'] }.to raise_error
142
- end
143
-
144
- it 'should parse parameter from command line.' do
145
- # Override string with types.
146
- Params.string('tmp6str', 'dummy', 'tmp6str def')
147
- expect { Params.parse_command_line_arguments ['--tmp6str=9'] }.to_not raise_error
148
- expect { Params.parse_command_line_arguments ['--tmp6str=8.1'] }.to_not raise_error
149
- expect { Params.parse_command_line_arguments ['--tmp6str=ff'] }.to_not raise_error
150
- expect { Params.parse_command_line_arguments ['--tmp6str=true'] }.to_not raise_error
151
- expect { Params.parse_command_line_arguments ['--tmp6str=false'] }.to_not raise_error
152
-
153
- # from fixnum to other types.
154
- Params.integer('tmp6', 8, 'tmp6 def')
155
- expect { Params.parse_command_line_arguments ['--tmp6=9'] }.to_not raise_error
156
- expect { Params.parse_command_line_arguments ['--tmp6=8.1'] }.to raise_error
157
- expect { Params.parse_command_line_arguments ['--tmp6=ff'] }.to raise_error
158
- expect { Params.parse_command_line_arguments ['--tmp6=true'] }.to raise_error
159
- expect { Params.parse_command_line_arguments ['--tmp6=false'] }.to raise_error
160
-
161
- # from float to other types.
162
- Params.float('tmp7', 8.9, 'tmp7 def')
163
- # Casting fix num to float
164
- expect { Params.parse_command_line_arguments ['--tmp7=9'] }.to_not raise_error
165
- expect { Params.parse_command_line_arguments ['--tmp7=3.4'] }.to_not raise_error
166
- expect { Params.parse_command_line_arguments ['--tmp7=ff'] }.to raise_error
167
- expect { Params.parse_command_line_arguments ['--tmp7=true'] }.to raise_error
168
- expect { Params.parse_command_line_arguments ['--tmp7=false'] }.to raise_error
169
-
170
- # from TrueClass to other types.
171
- Params.boolean('tmp8', true, 'tmp8 def')
172
- expect { Params.parse_command_line_arguments ['--tmp8=9'] }.to_not raise_error
173
- expect { Params.parse_command_line_arguments ['--tmp8=3.4'] }.to_not raise_error
174
- expect { Params.parse_command_line_arguments ['--tmp8=ff'] }.to_not raise_error
175
- expect { Params.parse_command_line_arguments ['--tmp8=true'] }.to_not raise_error
176
- expect { Params.parse_command_line_arguments ['--tmp8=false'] }.to_not raise_error
177
-
178
- # from FalseClass to other types.
179
- Params.boolean('tmp9', false, 'tmp9 def')
180
- expect { Params.parse_command_line_arguments ['--tmp9=9'] }.to_not raise_error
181
- expect { Params.parse_command_line_arguments ['--tmp9=3.4'] }.to_not raise_error
182
- expect { Params.parse_command_line_arguments ['--tmp9=ff'] }.to_not raise_error
183
- expect { Params.parse_command_line_arguments ['--tmp9=true'] }.to_not raise_error
184
- expect { Params.parse_command_line_arguments ['--tmp9=false'] }.to_not raise_error
185
- end
143
+ it 'should parse parameter from command line.' do
144
+ # Override string with types.
145
+ Params.string('tmp6str', 'dummy', 'tmp6str def')
146
+ expect { Params.parse_command_line_arguments ['--tmp6str=9'] }.to_not raise_error
147
+ expect { Params.parse_command_line_arguments ['--tmp6str=8.1'] }.to_not raise_error
148
+ expect { Params.parse_command_line_arguments ['--tmp6str=ff'] }.to_not raise_error
149
+ expect { Params.parse_command_line_arguments ['--tmp6str=true'] }.to_not raise_error
150
+ expect { Params.parse_command_line_arguments ['--tmp6str=false'] }.to_not raise_error
151
+
152
+ # from fixnum to other types.
153
+ Params.integer('tmp6', 8, 'tmp6 def')
154
+ expect { Params.parse_command_line_arguments ['--tmp6=9'] }.to_not raise_error
155
+ expect { Params.parse_command_line_arguments ['--tmp6=8.1'] }.to raise_error
156
+ expect { Params.parse_command_line_arguments ['--tmp6=ff'] }.to raise_error
157
+ expect { Params.parse_command_line_arguments ['--tmp6=true'] }.to raise_error
158
+ expect { Params.parse_command_line_arguments ['--tmp6=false'] }.to raise_error
159
+
160
+ # from float to other types.
161
+ Params.float('tmp7', 8.9, 'tmp7 def')
162
+ # Casting fix num to float
163
+ expect { Params.parse_command_line_arguments ['--tmp7=9'] }.to_not raise_error
164
+ expect { Params.parse_command_line_arguments ['--tmp7=3.4'] }.to_not raise_error
165
+ expect { Params.parse_command_line_arguments ['--tmp7=ff'] }.to raise_error
166
+ expect { Params.parse_command_line_arguments ['--tmp7=true'] }.to raise_error
167
+ expect { Params.parse_command_line_arguments ['--tmp7=false'] }.to raise_error
168
+
169
+ # from TrueClass to other types.
170
+ Params.boolean('tmp8', true, 'tmp8 def')
171
+ expect { Params.parse_command_line_arguments ['--tmp8=9'] }.to_not raise_error
172
+ expect { Params.parse_command_line_arguments ['--tmp8=3.4'] }.to_not raise_error
173
+ expect { Params.parse_command_line_arguments ['--tmp8=ff'] }.to_not raise_error
174
+ expect { Params.parse_command_line_arguments ['--tmp8=true'] }.to_not raise_error
175
+ expect { Params.parse_command_line_arguments ['--tmp8=false'] }.to_not raise_error
176
+
177
+ # from FalseClass to other types.
178
+ Params.boolean('tmp9', false, 'tmp9 def')
179
+ expect { Params.parse_command_line_arguments ['--tmp9=9'] }.to_not raise_error
180
+ expect { Params.parse_command_line_arguments ['--tmp9=3.4'] }.to_not raise_error
181
+ expect { Params.parse_command_line_arguments ['--tmp9=ff'] }.to_not raise_error
182
+ expect { Params.parse_command_line_arguments ['--tmp9=true'] }.to_not raise_error
183
+ expect { Params.parse_command_line_arguments ['--tmp9=false'] }.to_not raise_error
186
184
  end
185
+ end
187
186
 
188
- describe 'Params.init' do
189
- it 'should override command line arguments correctly.' do
190
- File.stub(:exist?).and_return false
191
- # Override string with types.
192
- Params.string('tmp6str2', 'dummy', 'tmp6str def')
193
- expect { Params.init ['--tmp6str2=9'] }.to_not raise_error
194
- expect { Params.init ['--tmp6str2=8.1'] }.to_not raise_error
195
- expect { Params.init ['--tmp6str2=ff'] }.to_not raise_error
196
- expect { Params.init ['--tmp6str2=true'] }.to_not raise_error
197
- expect { Params.init ['--tmp6str2=false'] }.to_not raise_error
198
-
199
- # from fixnum to other types.
200
- Params.integer('tmp6Fixnum2', 8, 'tmp6 def')
201
- expect { Params.init ['--tmp6Fixnum2=9'] }.to_not raise_error
202
- expect { Params.init ['--tmp6Fixnum2=8.1'] }.to raise_error
203
- expect { Params.init ['--tmp6Fixnum2=ff'] }.to raise_error
204
- expect { Params.init ['--tmp6Fixnum2=true'] }.to raise_error
205
- expect { Params.init ['--tmp6Fixnum2=false'] }.to raise_error
206
-
207
- # from float to other types.
208
- Params.float('tmp7float2', 8.9, 'tmp7 def')
209
- # Casting fix num to float
210
- expect { Params.init ['--tmp7float2=9'] }.to_not raise_error
211
- expect { Params.init ['--tmp7float2=3.4'] }.to_not raise_error
212
- expect { Params.init ['--tmp7float2=ff'] }.to raise_error
213
- expect { Params.init ['--tmp7float2=true'] }.to raise_error
214
- expect { Params.init ['--tmp7float2=false'] }.to raise_error
215
-
216
- # from TrueClass to other types.
217
- Params.boolean('tmp8true2', true, 'tmp8 def')
218
- expect { Params.init ['--tmp8true2=9'] }.to raise_error
219
- expect { Params.init ['--tmp8true2=3.4'] }.to raise_error
220
- expect { Params.init ['--tmp8true2=ff'] }.to raise_error
221
- expect { Params.init ['--tmp8true2=true'] }.to_not raise_error
222
- expect { Params.init ['--tmp8true2=false'] }.to_not raise_error
223
-
224
- # from FalseClass to other types.
225
- Params.boolean('tmp9false2', false, 'tmp9 def')
226
- expect { Params.init ['--tmp9false2=9'] }.to raise_error
227
- expect { Params.init ['--tmp9false2=3.4'] }.to raise_error
228
- expect { Params.init ['--tmp9false2=ff'] }.to raise_error
229
- expect { Params.init ['--tmp9false2=true'] }.to_not raise_error
230
- expect { Params.init ['--tmp9false2=false'] }.to_not raise_error
231
- end
232
-
233
- it 'should override defined values with command line values' do
234
- File.stub(:exist?).and_return false
235
- Params.string('tmp10str', 'aaa', 'tmp10 def')
236
- Params.integer('tmp10int', 11, 'tmp10 def')
237
- Params.float('tmp10float', 11.11, 'tmp10 def')
238
- Params.boolean('tmp10true', true, 'tmp10 def')
239
- Params.boolean('tmp10false', false, 'tmp10 def')
240
- Params.init ['--tmp10str=bbb', '--tmp10int=12', '--tmp10float=12.12', \
187
+ describe 'Params.init' do
188
+ it 'should override command line arguments correctly.' do
189
+ File.stub(:exist?).and_return false
190
+ # Override string with types.
191
+ Params.string('tmp6str2', 'dummy', 'tmp6str def')
192
+ expect { Params.init ['--tmp6str2=9'] }.to_not raise_error
193
+ expect { Params.init ['--tmp6str2=8.1'] }.to_not raise_error
194
+ expect { Params.init ['--tmp6str2=ff'] }.to_not raise_error
195
+ expect { Params.init ['--tmp6str2=true'] }.to_not raise_error
196
+ expect { Params.init ['--tmp6str2=false'] }.to_not raise_error
197
+
198
+ # from fixnum to other types.
199
+ Params.integer('tmp6Fixnum2', 8, 'tmp6 def')
200
+ expect { Params.init ['--tmp6Fixnum2=9'] }.to_not raise_error
201
+ expect { Params.init ['--tmp6Fixnum2=8.1'] }.to raise_error
202
+ expect { Params.init ['--tmp6Fixnum2=ff'] }.to raise_error
203
+ expect { Params.init ['--tmp6Fixnum2=true'] }.to raise_error
204
+ expect { Params.init ['--tmp6Fixnum2=false'] }.to raise_error
205
+
206
+ # from float to other types.
207
+ Params.float('tmp7float2', 8.9, 'tmp7 def')
208
+ # Casting fix num to float
209
+ expect { Params.init ['--tmp7float2=9'] }.to_not raise_error
210
+ expect { Params.init ['--tmp7float2=3.4'] }.to_not raise_error
211
+ expect { Params.init ['--tmp7float2=ff'] }.to raise_error
212
+ expect { Params.init ['--tmp7float2=true'] }.to raise_error
213
+ expect { Params.init ['--tmp7float2=false'] }.to raise_error
214
+
215
+ # from TrueClass to other types.
216
+ Params.boolean('tmp8true2', true, 'tmp8 def')
217
+ expect { Params.init ['--tmp8true2=9'] }.to raise_error
218
+ expect { Params.init ['--tmp8true2=3.4'] }.to raise_error
219
+ expect { Params.init ['--tmp8true2=ff'] }.to raise_error
220
+ expect { Params.init ['--tmp8true2=true'] }.to_not raise_error
221
+ expect { Params.init ['--tmp8true2=false'] }.to_not raise_error
222
+
223
+ # from FalseClass to other types.
224
+ Params.boolean('tmp9false2', false, 'tmp9 def')
225
+ expect { Params.init ['--tmp9false2=9'] }.to raise_error
226
+ expect { Params.init ['--tmp9false2=3.4'] }.to raise_error
227
+ expect { Params.init ['--tmp9false2=ff'] }.to raise_error
228
+ expect { Params.init ['--tmp9false2=true'] }.to_not raise_error
229
+ expect { Params.init ['--tmp9false2=false'] }.to_not raise_error
230
+ end
231
+
232
+ it 'should override defined values with command line values' do
233
+ File.stub(:exist?).and_return false
234
+ Params.string('tmp10str', 'aaa', 'tmp10 def')
235
+ Params.integer('tmp10int', 11, 'tmp10 def')
236
+ Params.float('tmp10float', 11.11, 'tmp10 def')
237
+ Params.boolean('tmp10true', true, 'tmp10 def')
238
+ Params.boolean('tmp10false', false, 'tmp10 def')
239
+ Params.init ['--tmp10str=bbb', '--tmp10int=12', '--tmp10float=12.12', \
241
240
  '--tmp10true=false', '--tmp10false=true']
242
- Params['tmp10str'].should eq 'bbb'
243
- Params['tmp10int'].should eq 12
244
- Params['tmp10float'].should eq 12.12
245
- Params['tmp10true'].should eq false
246
- Params['tmp10false'].should eq true
247
- end
248
-
249
- it 'init should override parameters with file and command' do
250
- Params.string('init_param', 'code', '')
251
- File.stub(:exist?).and_return true
252
- File.stub(:open).and_return StringIO.new 'init_param: yml'
253
- Params.init ['--conf_file=dummy_file', '--init_param=command-line']
254
- Params['init_param'].should eq 'command-line'
255
- end
256
-
257
- it 'init should override parameters with file only' do
258
- Params.string('init_param2', 'code', '')
259
- File.stub(:exist?).and_return true
260
- File.stub(:open).and_return StringIO.new 'init_param2: yml'
261
- Params.init ['--conf_file=dummy_file']
262
- Params['init_param2'].should eq 'yml'
263
- end
264
-
265
- it 'init should override parameters with command line only' do
266
- Params.string('init_param3', 'code', '')
267
- File.stub(:exist?).and_return false
268
- Params.init ['--init_param3=command-line']
269
- Params['init_param3'].should eq 'command-line'
270
- end
271
-
272
- it 'init should not override any parameters' do
273
- Params.string('init_param4', 'code', '')
274
- File.stub(:exist?).and_return false
275
- Params.init []
276
- Params['init_param4'].should eq 'code'
277
- end
241
+ Params['tmp10str'].should eq 'bbb'
242
+ Params['tmp10int'].should eq 12
243
+ Params['tmp10float'].should eq 12.12
244
+ Params['tmp10true'].should eq false
245
+ Params['tmp10false'].should eq true
246
+ end
247
+
248
+ it 'init should override parameters with file and command' do
249
+ Params.string('init_param', 'code', '')
250
+ File.stub(:exist?).and_return true
251
+ File.stub(:open).and_return StringIO.new 'init_param: yml'
252
+ Params.init ['--conf_file=dummy_file', '--init_param=command-line']
253
+ Params['init_param'].should eq 'command-line'
254
+ end
255
+
256
+ it 'init should override parameters with file only' do
257
+ Params.string('init_param2', 'code', '')
258
+ File.stub(:exist?).and_return true
259
+ File.stub(:open).and_return StringIO.new 'init_param2: yml'
260
+ Params.init ['--conf_file=dummy_file']
261
+ Params['init_param2'].should eq 'yml'
262
+ end
263
+
264
+ it 'init should override parameters with command line only' do
265
+ Params.string('init_param3', 'code', '')
266
+ File.stub(:exist?).and_return false
267
+ Params.init ['--init_param3=command-line']
268
+ Params['init_param3'].should eq 'command-line'
269
+ end
270
+
271
+ it 'init should not override any parameters' do
272
+ Params.string('init_param4', 'code', '')
273
+ File.stub(:exist?).and_return false
274
+ Params.init []
275
+ Params['init_param4'].should eq 'code'
278
276
  end
279
277
  end
280
278
  end