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