~bertrand-rousseau/gtg/new-task-list-layout

« back to all changes in this revision

Viewing changes to GTG/tests/test_twokeydict.py

  • Committer: Bertrand Rousseau
  • Date: 2012-07-13 17:24:28 UTC
  • mfrom: (1178.1.28 trunk)
  • mto: (1178.1.30 trunk)
  • mto: This revision was merged to the branch mainline in revision 1183.
  • Revision ID: bertrand.rousseau@gmail.com-20120713172428-ou3ic646fccov41d
Merge with trunk. Fixes conflict with CHANGELOG.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
# this program.  If not, see <http://www.gnu.org/licenses/>.
18
18
# -----------------------------------------------------------------------------
19
19
 
20
 
'''
21
 
Tests for the TwoKeyDict class
22
 
'''
 
20
""" Tests for the TwoKeyDict class """
23
21
 
24
22
import unittest
25
23
import uuid
27
25
from GTG.tools.twokeydict import TwoKeyDict
28
26
 
29
27
 
30
 
 
31
28
class TestTwoKeyDict(unittest.TestCase):
32
 
    '''
33
 
    Tests for the TwoKeyDict object.
34
 
    '''
 
29
    """ Tests for the TwoKeyDict object. """
35
30
 
36
 
    
37
31
    def test_add_and_gets(self):
38
 
        '''
39
 
        Test for the __init__, _get_by_first, _get_by_second function
40
 
        '''
41
 
        triplets = [(uuid.uuid4(), uuid.uuid4(), uuid.uuid4()) \
 
32
        """ Test for the __init__, _get_by_first, _get_by_second function """
 
33
        triplets = [(uuid.uuid4(), uuid.uuid4(), uuid.uuid4())
42
34
                    for a in xrange(10)]
43
35
        tw_dict = TwoKeyDict(*triplets)
44
36
        for triplet in triplets:
46
38
            self.assertEqual(tw_dict._get_by_secondary(triplet[1]), triplet[2])
47
39
 
48
40
    def test_remove_by_first_or_second(self):
49
 
        '''
50
 
        Test for removing triplets form the TwoKeyDict
51
 
        '''
 
41
        """ Test for removing triplets form the TwoKeyDict """
52
42
        triplet_first = (1, 'I', 'one')
53
43
        triplet_second = (2, 'II', 'two')
54
44
        tw_dict = TwoKeyDict(triplet_first, triplet_second)
81
71
        self.assertEqual(dict_len, 0)
82
72
 
83
73
    def test_get_primary_and_secondary_key(self):
84
 
        '''
85
 
        Test for fetching the objects stored in the TwoKeyDict
86
 
        '''
87
 
        triplets = [(uuid.uuid4(), uuid.uuid4(), uuid.uuid4()) \
88
 
                    for a in xrange(10)]
 
74
        """ Test for fetching the objects stored in the TwoKeyDict """
 
75
        triplets = [(uuid.uuid4(), uuid.uuid4(), uuid.uuid4())
 
76
                        for a in xrange(10)]
89
77
        tw_dict = TwoKeyDict(*triplets)
90
78
        for triplet in triplets:
91
 
            self.assertEqual(tw_dict._get_secondary_key(triplet[0]), \
 
79
            self.assertEqual(tw_dict._get_secondary_key(triplet[0]),
92
80
                             triplet[1])
93
 
            self.assertEqual(tw_dict._get_primary_key(triplet[1]), \
 
81
            self.assertEqual(tw_dict._get_primary_key(triplet[1]),
94
82
                             triplet[0])
95
83
 
96
84
    def test_missing_and_then_add(self):
105
93
        tw_dict.add((local_id, remote_id, value))
106
94
        self.assertEqual(remote_id, tw_dict._get_secondary_key(local_id))
107
95
 
 
96
 
108
97
def test_suite():
109
98
    return unittest.TestLoader().loadTestsFromTestCase(TestTwoKeyDict)
110