python3:tests: Fix Python 3 test issues
[Samba.git] / python / samba / tests / dcerpc / misc.py
blob2ec095063e94a5c349814b609ae9027abd867147
1 # Unix SMB/CIFS implementation.
2 # Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 """Tests for samba.dcerpc.misc."""
20 from samba.dcerpc import misc
21 import samba.tests
22 from samba.compat import PY3
24 text1 = "76f53846-a7c2-476a-ae2c-20e2b80d7b34"
25 text2 = "344edffa-330a-4b39-b96e-2c34da52e8b1"
28 if PY3:
29 # cmp() exists only in Python 2
30 def cmp(a, b):
31 return (a > b) - (a < b)
34 class GUIDTests(samba.tests.TestCase):
36 def test_str(self):
37 guid = misc.GUID(text1)
38 self.assertEquals(text1, str(guid))
40 def test_repr(self):
41 guid = misc.GUID(text1)
42 self.assertEquals("GUID('%s')" % text1, repr(guid))
44 def test_compare_different(self):
45 guid1 = misc.GUID(text1)
46 guid2 = misc.GUID(text2)
47 self.assertFalse(guid1 == guid2)
48 self.assertGreater(guid1, guid2)
49 self.assertTrue(cmp(guid1, guid2) > 0)
51 def test_compare_same(self):
52 guid1 = misc.GUID(text1)
53 guid2 = misc.GUID(text1)
54 self.assertTrue(guid1 == guid2)
55 self.assertEquals(guid1, guid2)
56 self.assertEquals(0, cmp(guid1, guid2))
59 class PolicyHandleTests(samba.tests.TestCase):
61 def test_init(self):
62 x = misc.policy_handle(text1, 1)
63 self.assertEquals(1, x.handle_type)
64 self.assertEquals(text1, str(x.uuid))
66 def test_repr(self):
67 x = misc.policy_handle(text1, 42)
68 self.assertEquals("policy_handle(%d, '%s')" % (42, text1), repr(x))
70 def test_str(self):
71 x = misc.policy_handle(text1, 42)
72 self.assertEquals("%d, %s" % (42, text1), str(x))