From 85170dfb584798b19245459a1f2ea89deef42a09 Mon Sep 17 00:00:00 2001 From: Konsta Vesterinen Date: Tue, 16 Dec 2014 15:41:46 +0200 Subject: [PATCH 1/4] Make aggregates fully support column aliases --- tests/__init__.py | 5 +++++ tests/aggregate/test_m2m_m2m.py | 1 + 2 files changed, 6 insertions(+) diff --git a/tests/__init__.py b/tests/__init__.py index 0fedbd6..f609a17 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -17,6 +17,10 @@ def count_sql_calls(conn, cursor, statement, parameters, context, executemany): conn.query_count += 1 except AttributeError: conn.query_count = 0 + try: + conn.queries.append(statement) + except AttributeError: + conn.queries = [statement] warnings.simplefilter('error', sa.exc.SAWarning) @@ -55,6 +59,7 @@ class TestCase(object): def teardown_method(self, method): aggregates.manager.reset() self.session.close_all() + self.connection.queries = [] if self.create_tables: self.Base.metadata.drop_all(self.connection) self.connection.close() diff --git a/tests/aggregate/test_m2m_m2m.py b/tests/aggregate/test_m2m_m2m.py index 1fee8c3..4f58d8c 100644 --- a/tests/aggregate/test_m2m_m2m.py +++ b/tests/aggregate/test_m2m_m2m.py @@ -76,5 +76,6 @@ class TestAggregateManyToManyAndManyToMany(TestCase): catalog2 = self.Catalog(products=products) self.session.add(catalog) self.session.commit() + print self.connection.queries[-1] assert catalog.category_count == 1 assert catalog2.category_count == 1 From de9dc676be7fb16c7e3af1a5c527b019601207bc Mon Sep 17 00:00:00 2001 From: Konsta Vesterinen Date: Tue, 16 Dec 2014 15:46:27 +0200 Subject: [PATCH 2/4] Add dependency test matrix --- .travis.yml | 7 ++++++- setup.py | 6 +++--- tests/__init__.py | 5 ----- tests/aggregate/test_m2m_m2m.py | 1 - 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/.travis.yml b/.travis.yml index fdbdf2b..1f731b5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,7 +13,12 @@ python: - 3.3 - 3.4 +env: + - EXTRAS=test + - EXTRAS=test_all + install: - - pip install -e ".[test]" + - pip install -e .[$EXTRAS] + script: - py.test diff --git a/setup.py b/setup.py index a531dfd..fa822fa 100644 --- a/setup.py +++ b/setup.py @@ -36,7 +36,6 @@ extras_require = { 'pytz>=2014.2', 'python-dateutil>=2.2', 'pymysql', - 'colour>=0.0.4' ], 'anyjson': ['anyjson>=0.3.3'], 'babel': ['Babel>=1.3'], @@ -53,9 +52,10 @@ extras_require = { # Add all optional dependencies to testing requirements. +test_all = [] for name, requirements in extras_require.items(): - if name != 'test': - extras_require['test'] += requirements + test_all += requirements +extras_require['test_all'] = test_all setup( diff --git a/tests/__init__.py b/tests/__init__.py index f609a17..0fedbd6 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -17,10 +17,6 @@ def count_sql_calls(conn, cursor, statement, parameters, context, executemany): conn.query_count += 1 except AttributeError: conn.query_count = 0 - try: - conn.queries.append(statement) - except AttributeError: - conn.queries = [statement] warnings.simplefilter('error', sa.exc.SAWarning) @@ -59,7 +55,6 @@ class TestCase(object): def teardown_method(self, method): aggregates.manager.reset() self.session.close_all() - self.connection.queries = [] if self.create_tables: self.Base.metadata.drop_all(self.connection) self.connection.close() diff --git a/tests/aggregate/test_m2m_m2m.py b/tests/aggregate/test_m2m_m2m.py index 4f58d8c..1fee8c3 100644 --- a/tests/aggregate/test_m2m_m2m.py +++ b/tests/aggregate/test_m2m_m2m.py @@ -76,6 +76,5 @@ class TestAggregateManyToManyAndManyToMany(TestCase): catalog2 = self.Catalog(products=products) self.session.add(catalog) self.session.commit() - print self.connection.queries[-1] assert catalog.category_count == 1 assert catalog2.category_count == 1 From 241210c900bf89e1fe39cd7b98c702140dc7e5b3 Mon Sep 17 00:00:00 2001 From: Konsta Vesterinen Date: Tue, 16 Dec 2014 18:22:13 +0200 Subject: [PATCH 3/4] Skip weekday type tests if babel not installed --- sqlalchemy_utils/types/weekdays.py | 14 ++++++++++++++ tests/types/test_weekdays.py | 6 ++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/sqlalchemy_utils/types/weekdays.py b/sqlalchemy_utils/types/weekdays.py index 9c19ee3..6b1d269 100644 --- a/sqlalchemy_utils/types/weekdays.py +++ b/sqlalchemy_utils/types/weekdays.py @@ -1,5 +1,11 @@ +babel = None +try: + import babel +except ImportError: + pass import six from sqlalchemy import types +from sqlalchemy_utils.exceptions import ImproperlyConfigured from sqlalchemy_utils.primitives import WeekDay, WeekDays from .scalar_coercible import ScalarCoercible from .bit import BitType @@ -48,6 +54,14 @@ class WeekDaysType(types.TypeDecorator, ScalarCoercible): impl = BitType(WeekDay.NUM_WEEK_DAYS) + def __init__(self, *args, **kwargs): + if babel is None: + raise ImproperlyConfigured( + "'babel' package is required to use 'WeekDaysType'" + ) + + super(WeekDaysType, self).__init__(*args, **kwargs) + @property def comparator_factory(self): return self.impl.comparator_factory diff --git a/tests/types/test_weekdays.py b/tests/types/test_weekdays.py index 1dac33c..afdedbb 100644 --- a/tests/types/test_weekdays.py +++ b/tests/types/test_weekdays.py @@ -1,16 +1,18 @@ -from babel import Locale +import pytest import sqlalchemy as sa from sqlalchemy_utils.types import WeekDaysType +from sqlalchemy_utils.types.weekdays import babel from sqlalchemy_utils.primitives import WeekDays from sqlalchemy_utils import i18n from tests import TestCase +@pytest.mark.skipif('babel is None') class WeekDaysTypeTestCase(TestCase): def setup_method(self, method): TestCase.setup_method(self, method) - i18n.get_locale = lambda: Locale('en') + i18n.get_locale = lambda: babel.Locale('en') def create_models(self): class Schedule(self.Base): From 56bbf96f7a7d8469ceac35056de211157b9f17ff Mon Sep 17 00:00:00 2001 From: Konsta Vesterinen Date: Tue, 16 Dec 2014 18:38:50 +0200 Subject: [PATCH 4/4] Make infinity dependency optional for range type tests --- tests/types/test_int_range.py | 3 ++- tests/types/test_numeric_range.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/types/test_int_range.py b/tests/types/test_int_range.py index 9c5b33c..eed5b7e 100644 --- a/tests/types/test_int_range.py +++ b/tests/types/test_int_range.py @@ -1,12 +1,13 @@ from pytest import mark import sqlalchemy as sa intervals = None +inf = -1 try: import intervals + from infinity import inf except ImportError: pass from tests import TestCase -from infinity import inf from sqlalchemy_utils import IntRangeType diff --git a/tests/types/test_numeric_range.py b/tests/types/test_numeric_range.py index 7007adf..26ec82f 100644 --- a/tests/types/test_numeric_range.py +++ b/tests/types/test_numeric_range.py @@ -6,10 +6,10 @@ import sqlalchemy as sa intervals = None try: import intervals + from infinity import inf except ImportError: pass from tests import TestCase -from infinity import inf from sqlalchemy_utils import NumericRangeType