From 2bfc40d21d1faf8f03b6d4dc9688d5fe01c667bf Mon Sep 17 00:00:00 2001 From: Konsta Vesterinen Date: Wed, 5 Mar 2014 15:47:49 +0200 Subject: [PATCH] Fix py33 support --- sqlalchemy_utils/generic.py | 8 ++++---- tests/generic_relationship/__init__.py | 3 ++- tests/generic_relationship/test_composite_keys.py | 3 ++- tests/generic_relationship/test_hybrid_properties.py | 3 ++- .../generic_relationship/test_single_table_inheritance.py | 3 ++- 5 files changed, 12 insertions(+), 8 deletions(-) diff --git a/sqlalchemy_utils/generic.py b/sqlalchemy_utils/generic.py index 4c88075..1360a35 100644 --- a/sqlalchemy_utils/generic.py +++ b/sqlalchemy_utils/generic.py @@ -74,7 +74,7 @@ class GenericAttributeImpl(attributes.ScalarAttributeImpl): pk = mapper.identity_key_from_instance(initiator)[1] # Set the identifier and the discriminator. - discriminator = unicode(class_.__name__) + discriminator = six.text_type(class_.__name__) for index, id in enumerate(self.parent_token.id): dict_[id.key] = pk[index] @@ -144,7 +144,7 @@ class GenericRelationshipProperty(MapperProperty): self._parentmapper = parentmapper def __eq__(self, other): - discriminator = unicode(type(other).__name__) + discriminator = six.text_type(type(other).__name__) q = self.property._discriminator_col == discriminator other_id = identity(other) for index, id in enumerate(self.property._id_cols): @@ -158,9 +158,9 @@ class GenericRelationshipProperty(MapperProperty): mapper = sa.inspect(other) # Iterate through the weak sequence in order to get the actual # mappers - class_names = [unicode(other.__name__)] + class_names = [six.text_type(other.__name__)] class_names.extend([ - unicode(submapper.class_.__name__) + six.text_type(submapper.class_.__name__) for submapper in mapper._inheriting_mappers ]) diff --git a/tests/generic_relationship/__init__.py b/tests/generic_relationship/__init__.py index 0956591..caabb0c 100644 --- a/tests/generic_relationship/__init__.py +++ b/tests/generic_relationship/__init__.py @@ -1,4 +1,5 @@ from __future__ import unicode_literals +import six from tests import TestCase @@ -16,7 +17,7 @@ class GenericRelationshipTestCase(TestCase): event = self.Event() event.object_id = user.id - event.object_type = unicode(type(user).__name__) + event.object_type = six.text_type(type(user).__name__) assert event.object is None diff --git a/tests/generic_relationship/test_composite_keys.py b/tests/generic_relationship/test_composite_keys.py index b933738..6528e37 100644 --- a/tests/generic_relationship/test_composite_keys.py +++ b/tests/generic_relationship/test_composite_keys.py @@ -1,4 +1,5 @@ from __future__ import unicode_literals +import six import sqlalchemy as sa from sqlalchemy_utils import generic_relationship from tests.generic_relationship import GenericRelationshipTestCase @@ -52,7 +53,7 @@ class TestGenericRelationship(GenericRelationshipTestCase): event = self.Event() event.object_id = user.id - event.object_type = unicode(type(user).__name__) + event.object_type = six.text_type(type(user).__name__) event.object_code = user.code assert event.object is None diff --git a/tests/generic_relationship/test_hybrid_properties.py b/tests/generic_relationship/test_hybrid_properties.py index a2b845a..564e23a 100644 --- a/tests/generic_relationship/test_hybrid_properties.py +++ b/tests/generic_relationship/test_hybrid_properties.py @@ -1,4 +1,5 @@ from __future__ import unicode_literals +import six import sqlalchemy as sa from sqlalchemy.ext.hybrid import hybrid_property from sqlalchemy_utils import generic_relationship @@ -55,7 +56,7 @@ class TestGenericRelationship(TestCase): event = self.Event(transaction_id=1) event.object_id = user.id - event.object_type = unicode(type(user).__name__) + event.object_type = six.text_type(type(user).__name__) assert event.object is None self.session.add(event) diff --git a/tests/generic_relationship/test_single_table_inheritance.py b/tests/generic_relationship/test_single_table_inheritance.py index 417329a..ac9ad14 100644 --- a/tests/generic_relationship/test_single_table_inheritance.py +++ b/tests/generic_relationship/test_single_table_inheritance.py @@ -1,4 +1,5 @@ from __future__ import unicode_literals +import six import sqlalchemy as sa from sqlalchemy_utils import generic_relationship from tests import TestCase @@ -54,7 +55,7 @@ class TestGenericRelationship(TestCase): event = self.Event() event.object_id = manager.id - event.object_type = unicode(type(manager).__name__) + event.object_type = six.text_type(type(manager).__name__) assert event.object is None