1
# -*- coding: utf-8 -*-
2
# -----------------------------------------------------------------------------
3
# Gettings Things Gnome! - a personal organizer for the GNOME desktop
4
# Copyright (c) 2008-2009 - Lionel Dricot & Bertrand Rousseau
6
# This program is free software: you can redistribute it and/or modify it under
7
# the terms of the GNU General Public License as published by the Free Software
8
# Foundation, either version 3 of the License, or (at your option) any later
11
# This program is distributed in the hope that it will be useful, but WITHOUT
12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16
# You should have received a copy of the GNU General Public License along with
17
# this program. If not, see <http://www.gnu.org/licenses/>.
18
# -----------------------------------------------------------------------------
21
Tests for the TwoKeyDict class
27
from GTG.tools.twokeydict import TwoKeyDict
31
class TestTwoKeyDict(unittest.TestCase):
33
Tests for the TwoKeyDict object.
37
def test_add_and_gets(self):
39
Test for the __init__, _get_by_first, _get_by_second function
41
triplets = [(uuid.uuid4(), uuid.uuid4(), uuid.uuid4()) \
43
tw_dict = TwoKeyDict(*triplets)
44
for triplet in triplets:
45
self.assertEqual(tw_dict._get_by_primary(triplet[0]), triplet[2])
46
self.assertEqual(tw_dict._get_by_secondary(triplet[1]), triplet[2])
48
def test_remove_by_first_or_second(self):
50
Test for removing triplets form the TwoKeyDict
52
triplet_first = (1, 'I', 'one')
53
triplet_second = (2, 'II', 'two')
54
tw_dict = TwoKeyDict(triplet_first, triplet_second)
55
tw_dict._remove_by_primary(triplet_first[0])
56
tw_dict._remove_by_secondary(triplet_second[1])
60
tw_dict._get_by_primary(triplet_first[0])
64
tw_dict._get_by_secondary(triplet_second[0])
68
tw_dict._get_by_secondary(triplet_first[1])
72
tw_dict._get_by_secondary(triplet_second[1])
75
self.assertEqual(missing_first, 2)
76
self.assertEqual(missing_second, 2)
77
#check for memory leaks
79
for key in tw_dict._primary_to_value.iterkeys():
81
self.assertEqual(dict_len, 0)
83
def test_get_primary_and_secondary_key(self):
85
Test for fetching the objects stored in the TwoKeyDict
87
triplets = [(uuid.uuid4(), uuid.uuid4(), uuid.uuid4()) \
89
tw_dict = TwoKeyDict(*triplets)
90
for triplet in triplets:
91
self.assertEqual(tw_dict._get_secondary_key(triplet[0]), \
93
self.assertEqual(tw_dict._get_primary_key(triplet[1]), \
97
return unittest.TestLoader().loadTestsFromTestCase(TestTwoKeyDict)