Esempio n. 1
0
 def test_missing_config(self):
     with self.assertRaises(ConfigError):
         parse_settings(
             ArgsMock(),
             {},
             [('int', nodefault, int)]
         )
Esempio n. 2
0
    def test_bad_type(self):
        with self.assertRaises(ConfigError):
            parse_settings(
                ArgsMock(),
                {'bool': 'not-bool'},
                [('bool', nodefault, bool)]
            )

        with self.assertRaises(ConfigError):
            parse_settings(
                ArgsMock(),
                {'int': 'not-int'},
                [('int', nodefault, int)]
            )
Esempio n. 3
0
    def setUp(self):
        self.args = ArgsMock(
            bool1=True,
            bool2=False,
            int1=10,
            float1=100.,
            str1="str1",
        )

        self.config = {
            'bool3': '1',
            'bool4': 'yes',
            'bool5': 'on',
            'bool6': 'true',
            'bool7': '0',
            'bool8': 'no',
            'bool9': 'off',
            'bool10': 'false',
            'int2': '20',
            'float2': '200.',
            'str2': 'str2'
        }

        self.spec = [
            ('bool1', nodefault, bool),
            ('bool2', nodefault, bool),
            ('bool3', nodefault, bool),
            ('bool4', nodefault, bool),
            ('bool5', nodefault, bool),
            ('bool6', nodefault, bool),
            ('bool7', nodefault, bool),
            ('bool8', nodefault, bool),
            ('bool9', nodefault, bool),
            ('bool10', nodefault, bool),
            ('bool11', False, bool),
            ('int1', nodefault, int),
            ('int2', nodefault, int),
            ('int3', 30, int),
            ('float1', nodefault, float),
            ('float2', nodefault, float),
            ('float3', 300., float),
            ('str1', nodefault, str),
            ('str2', nodefault, str),
            ('str3', 'str3', str),
        ]

        self.cfg = parse_settings(self.args, self.config, self.spec)