author | Jonathan Harrington <jonathan.harrington@nokia.com> |
Wed, 11 Aug 2010 14:49:30 +0100 | |
changeset 4 | 468f4c8d3d5b |
permissions | -rw-r--r-- |
4
468f4c8d3d5b
Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff
changeset
|
1 |
# Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies). |
468f4c8d3d5b
Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff
changeset
|
2 |
# All rights reserved. |
468f4c8d3d5b
Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff
changeset
|
3 |
# This component and the accompanying materials are made available |
468f4c8d3d5b
Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff
changeset
|
4 |
# under the terms of the License "Eclipse Public License v1.0" |
468f4c8d3d5b
Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff
changeset
|
5 |
# which accompanies this distribution, and is available |
468f4c8d3d5b
Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff
changeset
|
6 |
# at the URL "http://www.eclipse.org/legal/epl-v10.html". |
468f4c8d3d5b
Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff
changeset
|
7 |
# |
468f4c8d3d5b
Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff
changeset
|
8 |
# Initial Contributors: |
468f4c8d3d5b
Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff
changeset
|
9 |
# Nokia Corporation - initial contribution. |
468f4c8d3d5b
Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff
changeset
|
10 |
# |
468f4c8d3d5b
Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff
changeset
|
11 |
# Contributors: |
468f4c8d3d5b
Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff
changeset
|
12 |
# |
468f4c8d3d5b
Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff
changeset
|
13 |
class MapEntry(object): |
468f4c8d3d5b
Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff
changeset
|
14 |
"Encapsulates a ditamap entry and allows them to be compared" |
468f4c8d3d5b
Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff
changeset
|
15 |
def __init__(self, tag, href=None, navtitle=None, children=[]): |
468f4c8d3d5b
Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff
changeset
|
16 |
self.tag = tag |
468f4c8d3d5b
Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff
changeset
|
17 |
self.href = href |
468f4c8d3d5b
Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff
changeset
|
18 |
self.navtitle = navtitle |
468f4c8d3d5b
Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff
changeset
|
19 |
self.children = children |
468f4c8d3d5b
Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff
changeset
|
20 |
|
468f4c8d3d5b
Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff
changeset
|
21 |
def __eq__(self, other): |
468f4c8d3d5b
Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff
changeset
|
22 |
if (other is None or not getattr(other, 'href') |
468f4c8d3d5b
Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff
changeset
|
23 |
or not getattr(other, 'navtitle') |
468f4c8d3d5b
Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff
changeset
|
24 |
or not getattr(other, 'tag')): |
468f4c8d3d5b
Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff
changeset
|
25 |
return False |
468f4c8d3d5b
Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff
changeset
|
26 |
return ( |
468f4c8d3d5b
Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff
changeset
|
27 |
self.tag == other.tag and |
468f4c8d3d5b
Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff
changeset
|
28 |
self.href == other.href and |
468f4c8d3d5b
Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff
changeset
|
29 |
self.navtitle == other.navtitle |
468f4c8d3d5b
Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff
changeset
|
30 |
) |
468f4c8d3d5b
Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff
changeset
|
31 |
|
468f4c8d3d5b
Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff
changeset
|
32 |
def __hash__(self): |
468f4c8d3d5b
Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff
changeset
|
33 |
return hash((self.tag, self.href, self.navtitle)) |
468f4c8d3d5b
Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff
changeset
|
34 |
|
468f4c8d3d5b
Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff
changeset
|
35 |
|
468f4c8d3d5b
Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff
changeset
|
36 |
################################################################ |
468f4c8d3d5b
Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff
changeset
|
37 |
# Unit test code |
468f4c8d3d5b
Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff
changeset
|
38 |
################################################################ |
468f4c8d3d5b
Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff
changeset
|
39 |
import unittest |
468f4c8d3d5b
Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff
changeset
|
40 |
|
468f4c8d3d5b
Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff
changeset
|
41 |
|
468f4c8d3d5b
Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff
changeset
|
42 |
class TestMapEntry(unittest.TestCase): |
468f4c8d3d5b
Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff
changeset
|
43 |
def test_i_correctly_handle_possible_erros_when_comparing(self): |
468f4c8d3d5b
Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff
changeset
|
44 |
map_a = MapEntry("a", "www.nokia.com", "Nokia") |
468f4c8d3d5b
Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff
changeset
|
45 |
self.assertFalse(map_a == None) |
468f4c8d3d5b
Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff
changeset
|
46 |
self.assertFalse(map_a == MapEntry("a", "www.nokia.com")) |
468f4c8d3d5b
Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff
changeset
|
47 |
|
468f4c8d3d5b
Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff
changeset
|
48 |
def test_i_correctly_compare_equal_map_entry_items(self): |
468f4c8d3d5b
Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff
changeset
|
49 |
map_a = MapEntry("a", "www.nokia.com", "Nokia") |
468f4c8d3d5b
Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff
changeset
|
50 |
map_b = MapEntry("a", "www.nokia.com", "Nokia") |
468f4c8d3d5b
Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff
changeset
|
51 |
self.assertTrue(map_a == map_b) |
468f4c8d3d5b
Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff
changeset
|
52 |
|
468f4c8d3d5b
Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff
changeset
|
53 |
def test_i_correctly_compare_unequal_map_entry_items(self): |
468f4c8d3d5b
Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff
changeset
|
54 |
map_a = MapEntry("a", "www.nokia.com", "Nokia") |
468f4c8d3d5b
Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff
changeset
|
55 |
map_b = MapEntry("a", "www.symbian.com", "Nokia") |
468f4c8d3d5b
Orb version 0.2.0
Jonathan Harrington <jonathan.harrington@nokia.com>
parents:
diff
changeset
|
56 |
self.assertFalse(map_a == map_b) |