1#
2# Copyright OpenEmbedded Contributors
3#
4# SPDX-License-Identifier: MIT
5#
6
7from unittest.case import TestCase
8from oe.maketype import create
9
10class TestBooleanType(TestCase):
11    def test_invalid(self):
12        self.assertRaises(ValueError, create, '', 'boolean')
13        self.assertRaises(ValueError, create, 'foo', 'boolean')
14        self.assertRaises(TypeError, create, object(), 'boolean')
15
16    def test_true(self):
17        self.assertTrue(create('y', 'boolean'))
18        self.assertTrue(create('yes', 'boolean'))
19        self.assertTrue(create('1', 'boolean'))
20        self.assertTrue(create('t', 'boolean'))
21        self.assertTrue(create('true', 'boolean'))
22        self.assertTrue(create('TRUE', 'boolean'))
23        self.assertTrue(create('truE', 'boolean'))
24
25    def test_false(self):
26        self.assertFalse(create('n', 'boolean'))
27        self.assertFalse(create('no', 'boolean'))
28        self.assertFalse(create('0', 'boolean'))
29        self.assertFalse(create('f', 'boolean'))
30        self.assertFalse(create('false', 'boolean'))
31        self.assertFalse(create('FALSE', 'boolean'))
32        self.assertFalse(create('faLse', 'boolean'))
33
34    def test_bool_equality(self):
35        self.assertEqual(create('n', 'boolean'), False)
36        self.assertNotEqual(create('n', 'boolean'), True)
37        self.assertEqual(create('y', 'boolean'), True)
38        self.assertNotEqual(create('y', 'boolean'), False)
39
40class TestList(TestCase):
41    def assertListEqual(self, value, valid, sep=None):
42        obj = create(value, 'list', separator=sep)
43        self.assertEqual(obj, valid)
44        if sep is not None:
45            self.assertEqual(obj.separator, sep)
46        self.assertEqual(str(obj), obj.separator.join(obj))
47
48    def test_list_nosep(self):
49        testlist = ['alpha', 'beta', 'theta']
50        self.assertListEqual('alpha beta theta', testlist)
51        self.assertListEqual('alpha  beta\ttheta', testlist)
52        self.assertListEqual('alpha', ['alpha'])
53
54    def test_list_usersep(self):
55        self.assertListEqual('foo:bar', ['foo', 'bar'], ':')
56        self.assertListEqual('foo:bar:baz', ['foo', 'bar', 'baz'], ':')
57