File: test_settings.py

package info (click to toggle)
python-pyramid 1.10.2+dfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 4,052 kB
  • sloc: python: 42,982; makefile: 41
file content (86 lines) | stat: -rw-r--r-- 2,428 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import unittest


class Test_asbool(unittest.TestCase):
    def _callFUT(self, s):
        from pyramid.settings import asbool

        return asbool(s)

    def test_s_is_None(self):
        result = self._callFUT(None)
        self.assertEqual(result, False)

    def test_s_is_True(self):
        result = self._callFUT(True)
        self.assertEqual(result, True)

    def test_s_is_False(self):
        result = self._callFUT(False)
        self.assertEqual(result, False)

    def test_s_is_true(self):
        result = self._callFUT('True')
        self.assertEqual(result, True)

    def test_s_is_false(self):
        result = self._callFUT('False')
        self.assertEqual(result, False)

    def test_s_is_yes(self):
        result = self._callFUT('yes')
        self.assertEqual(result, True)

    def test_s_is_on(self):
        result = self._callFUT('on')
        self.assertEqual(result, True)

    def test_s_is_1(self):
        result = self._callFUT(1)
        self.assertEqual(result, True)


class Test_aslist_cronly(unittest.TestCase):
    def _callFUT(self, val):
        from pyramid.settings import aslist_cronly

        return aslist_cronly(val)

    def test_with_list(self):
        result = self._callFUT(['abc', 'def'])
        self.assertEqual(result, ['abc', 'def'])

    def test_with_string(self):
        result = self._callFUT('abc def')
        self.assertEqual(result, ['abc def'])

    def test_with_string_crsep(self):
        result = self._callFUT(' abc\n def')
        self.assertEqual(result, ['abc', 'def'])


class Test_aslist(unittest.TestCase):
    def _callFUT(self, val, **kw):
        from pyramid.settings import aslist

        return aslist(val, **kw)

    def test_with_list(self):
        result = self._callFUT(['abc', 'def'])
        self.assertEqual(list(result), ['abc', 'def'])

    def test_with_string(self):
        result = self._callFUT('abc def')
        self.assertEqual(result, ['abc', 'def'])

    def test_with_string_crsep(self):
        result = self._callFUT(' abc\n def')
        self.assertEqual(result, ['abc', 'def'])

    def test_with_string_crsep_spacesep(self):
        result = self._callFUT(' abc\n def ghi')
        self.assertEqual(result, ['abc', 'def', 'ghi'])

    def test_with_string_crsep_spacesep_no_flatten(self):
        result = self._callFUT(' abc\n def ghi ', flatten=False)
        self.assertEqual(result, ['abc', 'def ghi'])