From fcb8196d3db5bc9eb5ada835acdddeb0c4b31774 Mon Sep 17 00:00:00 2001 From: Ivan Ladelshchikov Date: Tue, 6 Jun 2017 20:00:15 +0500 Subject: [PATCH] fix unicode params for Py2 --- src/infi/clickhouse_orm/fields.py | 4 ++-- src/infi/clickhouse_orm/system_models.py | 4 +++- tests/test_alias_fields.py | 2 +- tests/test_materialized_fields.py | 2 +- tests/test_system_models.py | 2 +- 5 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/infi/clickhouse_orm/fields.py b/src/infi/clickhouse_orm/fields.py index a136601..1d2d59a 100644 --- a/src/infi/clickhouse_orm/fields.py +++ b/src/infi/clickhouse_orm/fields.py @@ -18,9 +18,9 @@ class Field(object): def __init__(self, default=None, alias=None, materialized=None): assert (None, None) in {(default, alias), (alias, materialized), (default, materialized)}, \ "Only one of default, alias and materialized parameters can be given" - assert alias is None or isinstance(alias, str) and alias != "",\ + assert alias is None or isinstance(alias, string_types) and alias != "",\ "Alias field must be string field name, if given" - assert materialized is None or isinstance(materialized, str) and alias != "",\ + assert materialized is None or isinstance(materialized, string_types) and alias != "",\ "Materialized field must be string, if given" self.creation_counter = Field.creation_counter diff --git a/src/infi/clickhouse_orm/system_models.py b/src/infi/clickhouse_orm/system_models.py index 8c66550..c151302 100644 --- a/src/infi/clickhouse_orm/system_models.py +++ b/src/infi/clickhouse_orm/system_models.py @@ -2,6 +2,8 @@ This file contains system readonly models that can be got from database https://clickhouse.yandex/reference_en.html#System tables """ +from six import string_types + from .database import Database from .fields import * from .models import Model @@ -115,7 +117,7 @@ class SystemPart(Model): :return: A list of SystemPart objects """ assert isinstance(database, Database), "database must be database.Database class instance" - assert isinstance(conditions, str), "conditions must be a string" + assert isinstance(conditions, string_types), "conditions must be a string" if conditions: conditions += " AND" field_names = ','.join([f[0] for f in cls._fields]) diff --git a/tests/test_alias_fields.py b/tests/test_alias_fields.py index af7bbc8..e8d896f 100644 --- a/tests/test_alias_fields.py +++ b/tests/test_alias_fields.py @@ -60,7 +60,7 @@ class ModelWithAliasFields(Model): date_field = DateField() str_field = StringField() - alias_str = StringField(alias='str_field') + alias_str = StringField(alias=u'str_field') alias_int = Int32Field(alias='int_field') alias_date = DateField(alias='date_field') diff --git a/tests/test_materialized_fields.py b/tests/test_materialized_fields.py index 3151dc3..f877116 100644 --- a/tests/test_materialized_fields.py +++ b/tests/test_materialized_fields.py @@ -62,7 +62,7 @@ class ModelWithMaterializedFields(Model): mat_str = StringField(materialized='lower(str_field)') mat_int = Int32Field(materialized='abs(int_field)') - mat_date = DateField(materialized='toDate(date_time_field)') + mat_date = DateField(materialized=u'toDate(date_time_field)') engine = MergeTree('mat_date', ('mat_date',)) diff --git a/tests/test_system_models.py b/tests/test_system_models.py index 544713b..3e48b0c 100644 --- a/tests/test_system_models.py +++ b/tests/test_system_models.py @@ -40,7 +40,7 @@ class SystemPartTest(unittest.TestCase): def test_get_conditions(self): parts = list(SystemPart.get(self.database, conditions="table='testtable'")) self.assertEqual(len(parts), 1) - parts = list(SystemPart.get(self.database, conditions="table='othertable'")) + parts = list(SystemPart.get(self.database, conditions=u"table='othertable'")) self.assertEqual(len(parts), 0) def test_attach_detach(self):