File: defaults.py

package info (click to toggle)
python-gpyconf 0.2-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd, stretch
  • size: 416 kB
  • ctags: 590
  • sloc: python: 1,980; makefile: 87; sh: 4
file content (44 lines) | stat: -rw-r--r-- 1,294 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# Tests wether all fields handle default values correctly.

import unittest
import gpyconf

class DefaultTestConf(gpyconf.Configuration):
    foo = gpyconf.fields.BooleanField(default=True)
    bar = gpyconf.fields.CharField(default='Hello')
    blubb = gpyconf.fields.FileField(default='file:///home/user/foo')
    peng = gpyconf.fields.IntegerField(default=42, min=11, max=121)
    multi = gpyconf.fields.MultiOptionField(default='foo', options=(
        ('foo', 'Foobar'),
        ('bar', 'Bar')
    ))


class DefaultTest(unittest.TestCase):
    def setUp(self):
        self.conf = DefaultTestConf()

    def runTest(self, new=True):
        from urlparse import urlparse

        for var, default in {
            'foo' : True,
            'bar' : 'Hello',
            'blubb' : urlparse('file:///home/user/foo'),
            'peng' : 42
        }.iteritems():
            self.assertEqual(getattr(self.conf, var), default)

        if new:
            for var, new in {
                'foo' : False,
                'bar' : 'Hi there',
                'blubb' : 'blaaah',
                'peng' : 45
            }.iteritems():
                setattr(self.conf, var, new)
            self.conf.reset()
            self.runTest(new=False)

if __name__ == '__main__':
    unittest.main()