Beispiel #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)
Beispiel #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))
Beispiel #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))
Beispiel #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))
Beispiel #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))
Beispiel #6
0
 class Foo(Model):
     __hide_unset__ = True
     optional_attribute = Attribute(str, optional=True)
Beispiel #7
0
 class Foo(Model):
     non_attribute = 'bar'
     attribute = Attribute(str)
Beispiel #8
0
 class UUT(Model):
     name = Attribute(str)
     number = Attribute(int)
     null = Attribute(str, optional=True)
     default_false = Attribute(bool, fallback=False)
Beispiel #9
0
 class Foo(Model):
     a = Attribute(str)
Beispiel #10
0
class Script(Model):
    __hide_unset__ = True
    name = Attribute(str)
    path = Attribute(str)
    source = Attribute(str, optional=True)
    command = Attribute(str, optional=True)
Beispiel #11
0
 class Data(Model):
     date = Attribute(parse_date)
Beispiel #12
0
 class Data2(Model):
     model_value = Attribute(Data1)
Beispiel #13
0
 class Data1(Model):
     value = Attribute(str)
Beispiel #14
0
 def test_attribute_should_raise_when_type_is_none(self):
     with self.assertRaises(ValueError):
         Attribute(None)
Beispiel #15
0
 def test_named_attributes(self):
     uut = Attribute(str, name='@foobar')
     self.assertEqual(uut('def').name, '@foobar')
Beispiel #16
0
        class Foo(Model):
            __ignore_unknown__ = False

            data = Attribute(str)
Beispiel #17
0
 class Data(Model):
     name = Attribute(str)
     some_value = Attribute(str, optional=True)
     another_value = Attribute(int, fallback=0)
Beispiel #18
0
 class Data3(Model):
     data1 = Attribute(list_type(Data1))
     data2 = Attribute(Data2)
Beispiel #19
0
 class Foo(Model):
     a = Attribute(int)
     b = Attribute(str)
     c = Attribute(bool)
Beispiel #20
0
 class Foo(Model):
     a = Attribute(str, alias='b')
Beispiel #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=[])
Beispiel #22
0
 def test_attribute_should_not_be_nullifiable_by_default(self):
     with self.assertRaises(ValueError):
         Attribute(str)(None)