[test] deal with py3k's string types

Related to #267910.

authorJulien Cristau <julien.cristau@logilab.fr>
changesetc73195f81fcc
branchdefault
phasedraft
hiddenyes
parent revision#9899cf1d9446 [schema2sql] get range from six.moves
child revision#a320b7daf647 [test] don't rely on a particular ordering for unsorted lists
files modified by this revision
test/unittest_schema.py
# HG changeset patch
# User Julien Cristau <julien.cristau@logilab.fr>
# Date 1413464021 -7200
# Thu Oct 16 14:53:41 2014 +0200
# Node ID c73195f81fcc4625d18ba168517255461d50388a
# Parent 9899cf1d9446ae8bb242afe4f3523a620743926b
[test] deal with py3k's string types

Related to #267910.

diff --git a/test/unittest_schema.py b/test/unittest_schema.py
@@ -23,10 +23,12 @@
1  from logilab.common.testlib import TestCase, unittest_main
2 
3  from copy import copy, deepcopy
4  from tempfile import mktemp
5 
6 +from six import text_type
7 +
8  from yams import (BASE_TYPES, ValidationError, BadSchemaDefinition,
9                    register_base_type, unregister_base_type)
10  from yams.buildobjs import (register_base_types, make_type, _add_relation,
11                              EntityType, RelationType, RelationDefinition)
12  from yams.schema import Schema, RelationDefinitionSchema
@@ -120,11 +122,11 @@
13 
14  ATTRIBUTE_BAD_VALUES = (
15      ('Person', [('nom', 1), ('nom', u'tropcour'),
16                  ('nom', u'>10 mais  sup�rieur � < 20 , c\'est long'),
17                  ('sexe', u'F'), ('sexe', u'MorF'), ('sexe', 'F'),
18 -                ('promo', 'bon'), ('promo', 'uyou'),
19 +                ('promo', b'bon'), ('promo', 'uyou'),
20                  ('promo', u' pas bon du tout'),
21                  ('promo_format', u'text/something'),
22                  ('tel', 'notastring'),
23                  ('tel', 1000000),
24                  ('fax', 11),
@@ -450,42 +452,42 @@
25              # check attribute values one each time...
26              for item in val_list:
27                  with self.assertRaises(ValidationError) as cm:
28                      eschema.check(dict([item]))
29                  # check automatic call to translation works properly
30 -                unicode(cm.exception)
31 +                text_type(cm.exception)
32 
33      def test_validation_error_translation_1(self):
34          eschema = schema.eschema('Person')
35          with self.assertRaises(ValidationError) as cm:
36              eschema.check({'nom': 1, 'promo': 2})
37 -        cm.exception.translate(unicode)
38 +        cm.exception.translate(text_type)
39          self.assertEqual(cm.exception.errors,
40                           {'nom-subject': u'incorrect value (1) for type "String"',
41                            'promo-subject': u'incorrect value (2) for type "String"'})
42 
43      def test_validation_error_translation_2(self):
44          eschema = schema.eschema('Person')
45          with self.assertRaises(ValidationError) as cm:
46              eschema.check({'nom': u'x'*21, 'prenom': u'x'*65})
47 -        cm.exception.translate(unicode)
48 +        cm.exception.translate(text_type)
49          self.assertEqual(cm.exception.errors,
50                           {'nom-subject': u'value should have maximum size of 20 but found 21',
51                            'prenom-subject': u'value should have maximum size of 64 but found 65'})
52 
53      def test_validation_error_translation_3(self):
54          eschema = schema.eschema('Person')
55          with self.assertRaises(ValidationError) as cm:
56              eschema.check({'tel': 1000000, 'fax': 1000001})
57 -        cm.exception.translate(unicode)
58 +        cm.exception.translate(text_type)
59          self.assertEqual(cm.exception.errors,
60                           {'fax-subject': u'value 1000001 must be <= 999999',
61                            'tel-subject': u'value 1000000 must be <= 999999'})
62 
63      def test_validation_error_translation_4(self):
64          verr = ValidationError(1, {None: 'global message about eid %(eid)s'}, {'eid': 1})
65 -        verr.translate(unicode)
66 +        verr.translate(text_type)
67          self.assertEqual(verr.errors,
68                           {None: 'global message about eid 1'})
69 
70      def test_pickle(self):
71          """schema should be pickeable"""