pytests: heed assertEquals deprecation warning en-masse
[samba.git] / buildtools / wafsamba / tests / test_utils.py
1 # Copyright (C) 2012 Jelmer Vernooij <jelmer@samba.org>
2
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU Lesser General Public License as published by
5 # the Free Software Foundation; either version 2.1 of the License, or
6 # (at your option) any later version.
7
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 # GNU Lesser General Public License for more details.
12
13 # You should have received a copy of the GNU Lesser General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
17 from wafsamba.tests import TestCase
18
19 from wafsamba.samba_utils import (
20     TO_LIST,
21     dict_concat,
22     subst_vars_error,
23     unique_list,
24     )
25
26 class ToListTests(TestCase):
27
28     def test_none(self):
29         self.assertEqual([], TO_LIST(None))
30
31     def test_already_list(self):
32         self.assertEqual(["foo", "bar", 1], TO_LIST(["foo", "bar", 1]))
33
34     def test_default_delimiter(self):
35         self.assertEqual(["foo", "bar"], TO_LIST("foo bar"))
36         self.assertEqual(["foo", "bar"], TO_LIST("  foo bar  "))
37         self.assertEqual(["foo ", "bar"], TO_LIST("  \"foo \" bar  "))
38
39     def test_delimiter(self):
40         self.assertEqual(["foo", "bar"], TO_LIST("foo,bar", ","))
41         self.assertEqual(["  foo", "bar  "], TO_LIST("  foo,bar  ", ","))
42         self.assertEqual(["  \" foo\"", " bar  "], TO_LIST("  \" foo\", bar  ", ","))
43
44
45 class UniqueListTests(TestCase):
46
47     def test_unique_list(self):
48         self.assertEqual(["foo", "bar"], unique_list(["foo", "bar", "foo"]))
49
50
51 class SubstVarsErrorTests(TestCase):
52
53     def test_valid(self):
54         self.assertEqual("", subst_vars_error("", {}))
55         self.assertEqual("FOO bar", subst_vars_error("${F} bar", {"F": "FOO"}))
56
57     def test_invalid(self):
58         self.assertRaises(KeyError, subst_vars_error, "${F}", {})
59
60
61 class DictConcatTests(TestCase):
62
63     def test_empty(self):
64         ret = {}
65         dict_concat(ret, {})
66         self.assertEqual({}, ret)
67
68     def test_same(self):
69         ret = {"foo": "bar"}
70         dict_concat(ret, {"foo": "bla"})
71         self.assertEqual({"foo": "bar"}, ret)
72
73     def test_simple(self):
74         ret = {"foo": "bar"}
75         dict_concat(ret, {"blie": "bla"})
76         self.assertEqual({"foo": "bar", "blie": "bla"}, ret)