예제 #1
0
 def test_other_type_as_template(self):
     class MyClass(object):
         pass
     typ = confuse.as_template(MyClass)
     self.assertIsInstance(typ, confuse.TypeTemplate)
     self.assertEqual(typ.typ, MyClass)
     self.assertEqual(typ.default, confuse.REQUIRED)
예제 #2
0
 def inject_base_config(cls):
     """Inject default values from base config to allow player-specific overrides"""
     base_config = config['players'].get(Monitor.CONFIG_TEMPLATE)
     base_template = confuse.as_template(base_config)
     template = getattr(cls, 'CONFIG_TEMPLATE', {})
     updated = {**base_template.subtemplates, **template}
     cls.CONFIG_TEMPLATE = updated
예제 #3
0
    def test_other_type_as_template(self):
        class MyClass(object):
            pass

        typ = confuse.as_template(MyClass)
        self.assertIsInstance(typ, confuse.TypeTemplate)
        self.assertEqual(typ.typ, MyClass)
        self.assertEqual(typ.default, confuse.REQUIRED)
예제 #4
0
 def test_nested_dict_as_template(self):
     typ = confuse.as_template({'outer': {'inner': 2}})
     self.assertIsInstance(typ, confuse.MappingTemplate)
     self.assertIsInstance(typ.subtemplates['outer'],
                           confuse.MappingTemplate)
     self.assertIsInstance(typ.subtemplates['outer'].subtemplates['inner'],
                           confuse.Integer)
     self.assertEqual(
         typ.subtemplates['outer'].subtemplates['inner'].default, 2)
예제 #5
0
 def test_nested_dict_as_template(self):
     typ = confuse.as_template({'outer': {'inner': 2}})
     self.assertIsInstance(typ, confuse.MappingTemplate)
     self.assertIsInstance(typ.subtemplates['outer'],
                           confuse.MappingTemplate)
     self.assertIsInstance(typ.subtemplates['outer'].subtemplates['inner'],
                           confuse.Integer)
     self.assertEqual(typ.subtemplates['outer'].subtemplates['inner']
                      .default, 2)
예제 #6
0
def optional(optional_type, default=None):
    """Create a confuse-compatible type for optional values.

    Parameters
    ----------
    optional_type : type
        type of the optional value
    default : optional
        default value if not specified
    Returns
    -------
    template: type
        optional type template
    """
    template = confuse.as_template(optional_type)
    template.default = default
    return template
예제 #7
0
 def test_float_type_as_tempalte(self):
     typ = confuse.as_template(float)
     self.assertIsInstance(typ, confuse.Number)
     self.assertEqual(typ.default, confuse.REQUIRED)
예제 #8
0
 def test_required_as_template(self):
     typ = confuse.as_template(confuse.REQUIRED)
     self.assertIs(type(typ), confuse.Template)
     self.assertEqual(typ.default, confuse.REQUIRED)
예제 #9
0
 def test_concrete_string_as_template(self):
     typ = confuse.as_template('foo')
     self.assertIsInstance(typ, confuse.String)
     self.assertEqual(typ.default, 'foo')
예제 #10
0
 def test_list_as_template(self):
     typ = confuse.as_template(list())
     self.assertIsInstance(typ, confuse.OneOf)
     self.assertEqual(typ.default, confuse.REQUIRED)
예제 #11
0
 def test_dict_as_template(self):
     typ = confuse.as_template({'key': 9})
     self.assertIsInstance(typ, confuse.MappingTemplate)
     self.assertIsInstance(typ.subtemplates['key'], confuse.Integer)
     self.assertEqual(typ.subtemplates['key'].default, 9)
예제 #12
0
 def test_unicode_type_as_template(self):
     typ = confuse.as_template(unicode)  # noqa ignore=F821
     self.assertIsInstance(typ, confuse.String)
     self.assertEqual(typ.default, confuse.REQUIRED)
예제 #13
0
 def test_plain_string_as_template(self):
     typ = confuse.as_template(str)
     self.assertIsInstance(typ, confuse.String)
     self.assertEqual(typ.default, confuse.REQUIRED)
예제 #14
0
 def test_plain_int_as_template(self):
     typ = confuse.as_template(int)
     self.assertIsInstance(typ, confuse.Integer)
     self.assertEqual(typ.default, confuse.REQUIRED)
예제 #15
0
 def test_set_as_template(self):
     typ = confuse.as_template(set())
     self.assertIsInstance(typ, confuse.Choice)
예제 #16
0
 def test_list_as_template(self):
     typ = confuse.as_template(list())
     self.assertIsInstance(typ, confuse.OneOf)
     self.assertEqual(typ.default, confuse.REQUIRED)
예제 #17
0
 def test_dict_as_template(self):
     typ = confuse.as_template({'key': 9})
     self.assertIsInstance(typ, confuse.MappingTemplate)
     self.assertIsInstance(typ.subtemplates['key'], confuse.Integer)
     self.assertEqual(typ.subtemplates['key'].default, 9)
예제 #18
0
 def test_basestring_as_template(self):
     typ = confuse.as_template(basestring)  # noqa ignore=F821
     self.assertIsInstance(typ, confuse.String)
     self.assertEqual(typ.default, confuse.REQUIRED)
예제 #19
0
 def test_unicode_type_as_template(self):
     typ = confuse.as_template(unicode)  # noqa ignore=F821
     self.assertIsInstance(typ, confuse.String)
     self.assertEqual(typ.default, confuse.REQUIRED)
예제 #20
0
 def test_list_type_as_template(self):
     typ = confuse.as_template(list)
     self.assertIsInstance(typ, confuse.TypeTemplate)
     self.assertEqual(typ.typ, collections.Sequence)
     self.assertEqual(typ.default, confuse.REQUIRED)
예제 #21
0
 def test_none_as_template(self):
     typ = confuse.as_template(None)
     self.assertIs(type(typ), confuse.Template)
     self.assertEqual(typ.default, confuse.REQUIRED)
예제 #22
0
 def test_concrete_int_as_template(self):
     typ = confuse.as_template(2)
     self.assertIsInstance(typ, confuse.Integer)
     self.assertEqual(typ.default, 2)
예제 #23
0
 def test_dict_type_as_template(self):
     typ = confuse.as_template(dict)
     self.assertIsInstance(typ, confuse.TypeTemplate)
     self.assertEqual(typ.typ, collections.Mapping)
     self.assertEqual(typ.default, confuse.REQUIRED)
예제 #24
0
 def test_concrete_string_as_template(self):
     typ = confuse.as_template('foo')
     self.assertIsInstance(typ, confuse.String)
     self.assertEqual(typ.default, 'foo')
예제 #25
0
 def test_list_type_as_template(self):
     typ = confuse.as_template(list)
     self.assertIsInstance(typ, confuse.TypeTemplate)
     self.assertEqual(typ.typ, collections.Sequence)
     self.assertEqual(typ.default, confuse.REQUIRED)
예제 #26
0
 def test_basestring_as_template(self):
     typ = confuse.as_template(basestring)  # noqa ignore=F821
     self.assertIsInstance(typ, confuse.String)
     self.assertEqual(typ.default, confuse.REQUIRED)
예제 #27
0
 def test_set_type_as_template(self):
     typ = confuse.as_template(set)
     self.assertIsInstance(typ, confuse.TypeTemplate)
     self.assertEqual(typ.typ, set)
     self.assertEqual(typ.default, confuse.REQUIRED)
예제 #28
0
 def test_enum_type_as_template(self):
     typ = confuse.as_template(enum.Enum)
     self.assertIsInstance(typ, confuse.Choice)
예제 #29
0
 def test_concrete_float_as_template(self):
     typ = confuse.as_template(2.)
     self.assertIsInstance(typ, confuse.Number)
     self.assertEqual(typ.default, 2.)
예제 #30
0
 def test_set_as_template(self):
     typ = confuse.as_template(set())
     self.assertIsInstance(typ, confuse.Choice)
예제 #31
0
 def test_enum_type_as_template(self):
     typ = confuse.as_template(enum.Enum)
     self.assertIsInstance(typ, confuse.Choice)
예제 #32
0
 def test_float_type_as_tempalte(self):
     typ = confuse.as_template(float)
     self.assertIsInstance(typ, confuse.Number)
     self.assertEqual(typ.default, confuse.REQUIRED)
예제 #33
0
 def test_plain_int_as_template(self):
     typ = confuse.as_template(int)
     self.assertIsInstance(typ, confuse.Integer)
     self.assertEqual(typ.default, confuse.REQUIRED)
예제 #34
0
 def test_none_as_template(self):
     typ = confuse.as_template(None)
     self.assertIs(type(typ), confuse.Template)
     self.assertEqual(typ.default, None)
예제 #35
0
 def test_concrete_int_as_template(self):
     typ = confuse.as_template(2)
     self.assertIsInstance(typ, confuse.Integer)
     self.assertEqual(typ.default, 2)
예제 #36
0
 def test_set_type_as_template(self):
     typ = confuse.as_template(set)
     self.assertIsInstance(typ, confuse.TypeTemplate)
     self.assertEqual(typ.typ, set)
     self.assertEqual(typ.default, confuse.REQUIRED)
예제 #37
0
 def test_plain_string_as_template(self):
     typ = confuse.as_template(str)
     self.assertIsInstance(typ, confuse.String)
     self.assertEqual(typ.default, confuse.REQUIRED)
예제 #38
0
 def test_dict_type_as_template(self):
     typ = confuse.as_template(dict)
     self.assertIsInstance(typ, confuse.TypeTemplate)
     self.assertEqual(typ.typ, collections.Mapping)
     self.assertEqual(typ.default, confuse.REQUIRED)
예제 #39
0
def optional(type, default=None):
    template = confuse.as_template(type)
    template.default = default
    return template