~jzhuge/configglue/short_name_for_inischema_2

« back to all changes in this revision

Viewing changes to configglue/tests/test_schema.py

  • Committer: Tarmac
  • Author(s): Ricardo Kirkner
  • Date: 2014-03-23 22:41:16 UTC
  • mfrom: (112.1.1 trunk)
  • Revision ID: tarmac-20140323224116-w8jl0ahk8hbp59lu
[r=ricardokirkner,tenuki] use stricter hashing functions to avoid potential pitfall

Show diffs side-by-side

added added

removed removed

Lines of Context:
134
134
        self.assertEqual(MySchema(), MySchema())
135
135
        self.assertNotEqual(MySchema(), OtherSchema())
136
136
 
 
137
    def test_same_hash_if_equal(self):
 
138
        class MySchema(Schema):
 
139
            foo = IntOption()
 
140
 
 
141
        my_schema = MySchema()
 
142
        other_schema = MySchema()
 
143
        self.assertEqual(my_schema, other_schema)
 
144
        self.assertEqual(hash(my_schema), hash(other_schema))
 
145
 
137
146
 
138
147
class TestSchemaHelpers(unittest.TestCase):
139
148
    def test_get_config_objects(self):
194
203
        del opt2.name
195
204
        self.assertNotEqual(opt1, opt2)
196
205
 
 
206
    def test_same_hash_if_equal(self):
 
207
        opt1 = IntOption(name='opt1')
 
208
        opt2 = IntOption(name='opt1')
 
209
 
 
210
        self.assertEqual(opt1, opt2)
 
211
        self.assertEqual(hash(opt1), hash(opt2))
 
212
 
197
213
    def test_validate(self):
198
214
        """Test Option default validate behaviour."""
199
215
        opt = self.cls()
379
395
        self.assertEqual(option1, option1)
380
396
        self.assertNotEqual(option1, option2)
381
397
 
 
398
    def test_same_hash_if_equal(self):
 
399
        option1 = StringOption()
 
400
        option2 = StringOption()
 
401
 
 
402
        self.assertEqual(option1, option2)
 
403
        self.assertEqual(hash(option1), hash(option2))
 
404
 
382
405
 
383
406
class TestIntOption(unittest.TestCase):
384
407
    cls = IntOption
651
674
        self.assertNotEqual(option1, option6)
652
675
        self.assertNotEqual(option1, option7)
653
676
 
 
677
    def test_same_hash_if_equal(self):
 
678
        option1 = ListOption()
 
679
        option2 = ListOption(item=StringOption())
 
680
 
 
681
        self.assertEqual(option1, option2)
 
682
        self.assertEqual(hash(option1), hash(option2))
 
683
 
654
684
    def test_to_string_when_json(self):
655
685
        option = ListOption()
656
686
        result = option.to_string(['1', '2', '3'])
739
769
        self.assertEqual(option1, option1)
740
770
        self.assertNotEqual(option1, option2)
741
771
 
 
772
    def test_same_hash_if_equal(self):
 
773
        option1 = TupleOption(length=2)
 
774
        option2 = TupleOption(length=2)
 
775
 
 
776
        self.assertEqual(option1, option2)
 
777
        self.assertEqual(hash(option1), hash(option2))
 
778
 
742
779
 
743
780
class TestDictOption(unittest.TestCase):
744
781
    cls = DictOption
1108
1145
        self.assertEqual(option1, option4)
1109
1146
        self.assertNotEqual(option1, option5)
1110
1147
 
 
1148
    def test_same_hash_if_equal(self):
 
1149
        option1 = DictOption()
 
1150
        option2 = DictOption(item=StringOption())
 
1151
 
 
1152
        self.assertEqual(option1, option2)
 
1153
        self.assertEqual(hash(option1), hash(option2))
 
1154
 
1111
1155
    def test_to_string_when_json(self):
1112
1156
        option = DictOption()
1113
1157
        result = option.to_string({'foo': '1'})
1238
1282
        self.assertNotEqual(section1, section3)
1239
1283
        self.assertNotEqual(section1, section4)
1240
1284
 
 
1285
    def test_same_hash_if_equal(self):
 
1286
        section1 = self.cls()
 
1287
        section2 = self.cls()
 
1288
 
 
1289
        self.assertEqual(section1, section2)
 
1290
        self.assertEqual(hash(section1), hash(section2))
 
1291
 
1241
1292
    def test_repr(self):
1242
1293
        """Test Section repr."""
1243
1294
        section1 = self.cls()