Example #1
0
class Source(Model):
    __hide_unset__ = True
    name = Attribute(str)
    url = Attribute(str)
    user = Attribute(str, optional=True)
    password = Attribute(str, optional=True)
    branch = Attribute(str, optional=True)
Example #2
0
    def test_attribute_should_cast_value_to_given_type(self):
        try:
            uut = Attribute(str, fallback='test')
            self.assertEqual(uut(12).value, '12')

            uut = Attribute(int, fallback='test')
            self.assertEqual(uut(12).value, 12)
        except ValueError as e:
            self.fail(
                'creation of attribute failed in spite of "fallback" set: ' +
                str(e))
Example #3
0
    def test_attribute_should_be_nullifiable_if_specified(self):
        uut = Attribute(str, optional=True)

        try:
            self.assertIsNone(uut(None).value)
        except ValueError as e:
            self.fail(
                'creation of attribute failed in spite of "optional" set to True: '
                + str(e))
Example #4
0
    def test_attribute_should_use_fallback_if_specified(self):
        uut = Attribute(str, fallback='test')

        try:
            self.assertEqual(uut(None).value, 'test')
        except ValueError as e:
            self.fail(
                'creation of attribute failed in spite of fallback being given: '
                + str(e))
Example #5
0
    def test_attribute_should_call_fallback_if_function(self):
        def test_function():
            return 'test'

        uut = Attribute(str, fallback=test_function)

        try:
            self.assertEqual(uut(None).value, 'test')
        except ValueError as e:
            self.fail(
                'creation of attribute failed in spite of fallback function being given: '
                + str(e))
Example #6
0
 class Foo(Model):
     __hide_unset__ = True
     optional_attribute = Attribute(str, optional=True)
Example #7
0
 class Foo(Model):
     non_attribute = 'bar'
     attribute = Attribute(str)
Example #8
0
 class UUT(Model):
     name = Attribute(str)
     number = Attribute(int)
     null = Attribute(str, optional=True)
     default_false = Attribute(bool, fallback=False)
Example #9
0
 class Foo(Model):
     a = Attribute(str)
Example #10
0
class Script(Model):
    __hide_unset__ = True
    name = Attribute(str)
    path = Attribute(str)
    source = Attribute(str, optional=True)
    command = Attribute(str, optional=True)
Example #11
0
 class Data(Model):
     date = Attribute(parse_date)
Example #12
0
 class Data2(Model):
     model_value = Attribute(Data1)
Example #13
0
 class Data1(Model):
     value = Attribute(str)
Example #14
0
 def test_attribute_should_raise_when_type_is_none(self):
     with self.assertRaises(ValueError):
         Attribute(None)
Example #15
0
 def test_named_attributes(self):
     uut = Attribute(str, name='@foobar')
     self.assertEqual(uut('def').name, '@foobar')
Example #16
0
        class Foo(Model):
            __ignore_unknown__ = False

            data = Attribute(str)
Example #17
0
 class Data(Model):
     name = Attribute(str)
     some_value = Attribute(str, optional=True)
     another_value = Attribute(int, fallback=0)
Example #18
0
 class Data3(Model):
     data1 = Attribute(list_type(Data1))
     data2 = Attribute(Data2)
Example #19
0
 class Foo(Model):
     a = Attribute(int)
     b = Attribute(str)
     c = Attribute(bool)
Example #20
0
 class Foo(Model):
     a = Attribute(str, alias='b')
Example #21
0
class Config(Model):
    __hide_unset__ = True
    path = Attribute(str)
    script_dir = Attribute(str)
    scripts = Attribute(list_type(Script), fallback=[])
    sources = Attribute(list_type(Source), fallback=[])
Example #22
0
 def test_attribute_should_not_be_nullifiable_by_default(self):
     with self.assertRaises(ValueError):
         Attribute(str)(None)