From b7a856ae6ce32ea4f626e07bf8c2163161a520ec Mon Sep 17 00:00:00 2001 From: Konsta Vesterinen Date: Tue, 17 Mar 2015 14:14:07 +0200 Subject: [PATCH] Add flake8 to test matrix --- .travis.yml | 1 + setup.py | 1 + sqlalchemy_utils/__init__.py | 109 +++---------------- sqlalchemy_utils/exceptions.py | 4 +- sqlalchemy_utils/functions/__init__.py | 49 +-------- sqlalchemy_utils/relationships/__init__.py | 4 +- sqlalchemy_utils/types/phone_number.py | 6 +- sqlalchemy_utils/types/url.py | 4 +- tests/aggregate/test_m2m.py | 4 +- tests/aggregate/test_o2m_o2m_o2m.py | 1 + tests/functions/__init__.py | 7 -- tests/functions/test_database.py | 2 +- tests/functions/test_get_query_entities.py | 5 +- tests/relationships/test_select_aggregate.py | 6 +- tests/test_expression_parser.py | 2 +- tests/test_generates.py | 1 - tests/types/test_color.py | 5 +- tests/types/test_encrypted.py | 2 +- tests/types/test_int_range.py | 2 +- tests/types/test_json.py | 1 + tests/types/test_password.py | 9 +- tests/types/test_phonenumber.py | 9 +- tests/types/test_timezone.py | 5 - 23 files changed, 57 insertions(+), 182 deletions(-) diff --git a/.travis.yml b/.travis.yml index a8eb786..c665e30 100644 --- a/.travis.yml +++ b/.travis.yml @@ -33,4 +33,5 @@ install: - pip install -e .[$EXTRAS] script: + - flake8 sqlalchemy_utils tests - py.test diff --git a/setup.py b/setup.py index 69374ce..1c7112e 100644 --- a/setup.py +++ b/setup.py @@ -36,6 +36,7 @@ extras_require = { 'pytz>=2014.2', 'python-dateutil>=2.2', 'pymysql', + 'flake8>=2.4.0' ], 'anyjson': ['anyjson>=0.3.3'], 'babel': ['Babel>=1.3'], diff --git a/sqlalchemy_utils/__init__.py b/sqlalchemy_utils/__init__.py index 4432a4f..f6f5e3d 100644 --- a/sqlalchemy_utils/__init__.py +++ b/sqlalchemy_utils/__init__.py @@ -1,16 +1,16 @@ -from .aggregates import aggregated -from .asserts import ( +from .aggregates import aggregated # noqa +from .asserts import ( # noqa assert_min_value, assert_max_length, assert_max_value, assert_nullable, assert_non_nullable ) -from .batch import batch_fetch, with_backrefs -from .decorators import generates -from .exceptions import ImproperlyConfigured -from .expression_parser import ExpressionParser -from .functions import ( +from .batch import batch_fetch, with_backrefs # noqa +from .decorators import generates # noqa +from .exceptions import ImproperlyConfigured # noqa +from .expression_parser import ExpressionParser # noqa +from .functions import ( # noqa analyze, create_database, create_mock_engine, @@ -44,18 +44,18 @@ from .functions import ( sort_query, table_name, ) -from .i18n import TranslationHybrid -from .listeners import ( +from .i18n import TranslationHybrid # noqa +from .listeners import ( # noqa auto_delete_orphans, coercion_listener, force_auto_coercion, force_instant_defaults ) -from .generic import generic_relationship -from .proxy_dict import ProxyDict, proxy_dict -from .observer import observes -from .query_chain import QueryChain -from .types import ( +from .generic import generic_relationship # noqa +from .proxy_dict import ProxyDict, proxy_dict # noqa +from .observer import observes # noqa +from .query_chain import QueryChain # noqa +from .types import ( # noqa ArrowType, Choice, ChoiceType, @@ -85,86 +85,7 @@ from .types import ( UUIDType, WeekDaysType ) -from .models import Timestamp +from .models import Timestamp # noqa __version__ = '0.29.8' - - -__all__ = ( - aggregated, - analyze, - assert_max_length, - assert_non_nullable, - assert_nullable, - auto_delete_orphans, - batch_fetch, - coercion_listener, - create_database, - create_mock_engine, - database_exists, - dependent_objects, - drop_database, - escape_like, - force_auto_coercion, - force_instant_defaults, - generates, - generic_relationship, - get_bind, - get_column_key, - get_columns, - get_declarative_base, - get_hybrid_properties, - get_mapper, - get_query_entities, - get_primary_keys, - get_referencing_foreign_keys, - get_tables, - group_foreign_keys, - has_changes, - has_index, - identity, - instrumented_list, - is_loaded, - merge_references, - mock_engine, - naturally_equivalent, - proxy_dict, - render_expression, - render_statement, - sort_query, - table_name, - with_backrefs, - ArrowType, - Choice, - ChoiceType, - ColorType, - Country, - CountryType, - DateRangeType, - DateTimeRangeType, - EmailType, - EncryptedType, - ExpressionParser, - ImproperlyConfigured, - InstrumentedList, - IntRangeType, - IPAddressType, - JSONType, - LocaleType, - NumericRangeType, - Password, - PasswordType, - PhoneNumber, - PhoneNumberType, - ProxyDict, - QueryChain, - ScalarListException, - ScalarListType, - Timestamp, - TimezoneType, - TSVectorType, - URLType, - UUIDType, - WeekDaysType, -) diff --git a/sqlalchemy_utils/exceptions.py b/sqlalchemy_utils/exceptions.py index 6744366..2d84f14 100644 --- a/sqlalchemy_utils/exceptions.py +++ b/sqlalchemy_utils/exceptions.py @@ -1,5 +1,7 @@ -"""Global SQLAlchemy-Utils exception classes. """ +Global SQLAlchemy-Utils exception classes. +""" + class ImproperlyConfigured(Exception): """ diff --git a/sqlalchemy_utils/functions/__init__.py b/sqlalchemy_utils/functions/__init__.py index 0aa9fe0..edc6270 100644 --- a/sqlalchemy_utils/functions/__init__.py +++ b/sqlalchemy_utils/functions/__init__.py @@ -1,11 +1,11 @@ -from .mock import create_mock_engine, mock_engine -from .render import render_expression, render_statement -from .sort_query import ( +from .mock import create_mock_engine, mock_engine # noqa +from .render import render_expression, render_statement # noqa +from .sort_query import ( # noqa make_order_by_deterministic, sort_query, QuerySorterException ) -from .database import ( +from .database import ( # noqa analyze, create_database, database_exists, @@ -16,7 +16,7 @@ from .database import ( is_auto_assigned_date_column, json_sql ) -from .foreign_keys import ( +from .foreign_keys import ( # noqa dependent_objects, get_referencing_foreign_keys, group_foreign_keys, @@ -24,7 +24,7 @@ from .foreign_keys import ( merge_references, non_indexed_foreign_keys, ) -from .orm import ( +from .orm import ( # noqa get_bind, get_class_by_table, get_column_key, @@ -43,40 +43,3 @@ from .orm import ( quote, table_name, ) - -__all__ = ( - 'create_database', - 'create_mock_engine', - 'database_exists', - 'dependent_objects', - 'drop_database', - 'escape_like', - 'get_bind', - 'get_class_by_table', - 'get_columns', - 'get_declarative_base', - 'get_hybrid_properties', - 'get_mapper', - 'get_query_entities', - 'get_primary_keys', - 'get_referencing_foreign_keys', - 'get_tables', - 'getdotattr', - 'group_foreign_keys', - 'has_changes', - 'identity', - 'is_loaded', - 'is_auto_assigned_date_column', - 'is_indexed_foreign_key', - 'json_sql', - 'make_order_by_deterministic', - 'mock_engine', - 'naturally_equivalent', - 'non_indexed_foreign_keys', - 'QuerySorterException', - 'quote', - 'render_expression', - 'render_statement', - 'sort_query', - 'table_name', -) diff --git a/sqlalchemy_utils/relationships/__init__.py b/sqlalchemy_utils/relationships/__init__.py index 9f4a56f..5bec6f5 100644 --- a/sqlalchemy_utils/relationships/__init__.py +++ b/sqlalchemy_utils/relationships/__init__.py @@ -1,2 +1,2 @@ -from .chained_join import chained_join -from .select_aggregate import select_aggregate +from .chained_join import chained_join # noqa +from .select_aggregate import select_aggregate # noqa diff --git a/sqlalchemy_utils/types/phone_number.py b/sqlalchemy_utils/types/phone_number.py index 762c459..3dd1409 100644 --- a/sqlalchemy_utils/types/phone_number.py +++ b/sqlalchemy_utils/types/phone_number.py @@ -1,4 +1,3 @@ -import six from sqlalchemy import types from sqlalchemy_utils.exceptions import ImproperlyConfigured from sqlalchemy_utils.utils import str_coercible @@ -46,8 +45,9 @@ class PhoneNumber(BasePhoneNumber): italian_leading_zero=self._phone_number.italian_leading_zero, raw_input=self._phone_number.raw_input, country_code_source=self._phone_number.country_code_source, - preferred_domestic_carrier_code= - self._phone_number.preferred_domestic_carrier_code + preferred_domestic_carrier_code=( + self._phone_number.preferred_domestic_carrier_code + ) ) self.national = phonenumbers.format_number( self._phone_number, diff --git a/sqlalchemy_utils/types/url.py b/sqlalchemy_utils/types/url.py index 6dd6d68..68d5042 100644 --- a/sqlalchemy_utils/types/url.py +++ b/sqlalchemy_utils/types/url.py @@ -29,8 +29,8 @@ class URLType(types.TypeDecorator, ScalarCoercible): user = User(website=u'www.example.com') - # website is coerced to furl object, hence all nice furl operations come - # available + # website is coerced to furl object, hence all nice furl operations + # come available user.website.args['some_argument'] = '12' print user.website diff --git a/tests/aggregate/test_m2m.py b/tests/aggregate/test_m2m.py index 181d978..a63f02a 100644 --- a/tests/aggregate/test_m2m.py +++ b/tests/aggregate/test_m2m.py @@ -7,7 +7,9 @@ class TestAggregatesWithManyToManyRelationships(TestCase): dns = 'postgres://postgres@localhost/sqlalchemy_utils_test' def create_models(self): - user_group = sa.Table('user_group', self.Base.metadata, + user_group = sa.Table( + 'user_group', + self.Base.metadata, sa.Column('user_id', sa.Integer, sa.ForeignKey('user.id')), sa.Column('group_id', sa.Integer, sa.ForeignKey('group.id')) ) diff --git a/tests/aggregate/test_o2m_o2m_o2m.py b/tests/aggregate/test_o2m_o2m_o2m.py index 6dcc0e9..672045b 100644 --- a/tests/aggregate/test_o2m_o2m_o2m.py +++ b/tests/aggregate/test_o2m_o2m_o2m.py @@ -3,6 +3,7 @@ import sqlalchemy as sa from sqlalchemy_utils import aggregated from tests import TestCase + class Test3LevelDeepOneToMany(TestCase): dns = 'postgres://postgres@localhost/sqlalchemy_utils_test' diff --git a/tests/functions/__init__.py b/tests/functions/__init__.py index ad6e251..e69de29 100644 --- a/tests/functions/__init__.py +++ b/tests/functions/__init__.py @@ -1,7 +0,0 @@ -import sqlalchemy as sa -from tests import TestCase -from sqlalchemy_utils.functions import ( - render_statement, - render_expression, - mock_engine -) diff --git a/tests/functions/test_database.py b/tests/functions/test_database.py index 49c13f1..f72bd6b 100644 --- a/tests/functions/test_database.py +++ b/tests/functions/test_database.py @@ -5,7 +5,7 @@ from flexmock import flexmock from pytest import mark pymysql = None try: - import pymysql + import pymysql # noqa except ImportError: pass diff --git a/tests/functions/test_get_query_entities.py b/tests/functions/test_get_query_entities.py index 398ee00..448779c 100644 --- a/tests/functions/test_get_query_entities.py +++ b/tests/functions/test_get_query_entities.py @@ -91,7 +91,10 @@ class TestGetQueryEntities(TestCase): ).label('number_of_articles') query = self.session.query(self.Article, number_of_articles) - assert list(get_query_entities(query)) == [self.Article, number_of_articles] + assert list(get_query_entities(query)) == [ + self.Article, + number_of_articles + ] def test_aliased_entity(self): alias = sa.orm.aliased(self.Article) diff --git a/tests/relationships/test_select_aggregate.py b/tests/relationships/test_select_aggregate.py index b0f76ef..88d201f 100644 --- a/tests/relationships/test_select_aggregate.py +++ b/tests/relationships/test_select_aggregate.py @@ -1,11 +1,7 @@ import sqlalchemy as sa from sqlalchemy_utils.aggregates import select_aggregate from tests import TestCase -from tests.mixins import ( - ThreeLevelDeepManyToMany, - ThreeLevelDeepOneToMany, - ThreeLevelDeepOneToOne, -) +from tests.mixins import ThreeLevelDeepManyToMany def normalize(sql): diff --git a/tests/test_expression_parser.py b/tests/test_expression_parser.py index 672de92..42a3b3c 100644 --- a/tests/test_expression_parser.py +++ b/tests/test_expression_parser.py @@ -40,7 +40,7 @@ class TestExpressionParser(TestCase): assert str(expr) == 'category.name IN (:name_1, :name_2)' def test_boolean_expression(self): - expr = self.parser(self.User.name == False) + expr = self.parser(self.User.name == False) # noqa assert str(expr) == 'category.name = 0' def test_label(self): diff --git a/tests/test_generates.py b/tests/test_generates.py index 1629c75..532c62b 100644 --- a/tests/test_generates.py +++ b/tests/test_generates.py @@ -119,7 +119,6 @@ class TestGeneratesWithSourcePath(DeepPathGeneratesTestCase): def copy_locale(self, document): return document.locale - self.Document = Document self.Section = Section self.SubSection = SubSection diff --git a/tests/types/test_color.py b/tests/types/test_color.py index 5af476b..37366f0 100644 --- a/tests/types/test_color.py +++ b/tests/types/test_color.py @@ -1,12 +1,11 @@ from flexmock import flexmock from pytest import mark import sqlalchemy as sa -from sqlalchemy_utils import ColorType -from sqlalchemy_utils.types import color +from sqlalchemy_utils import ColorType, types # noqa from tests import TestCase -@mark.skipif('color.python_colour_type is None') +@mark.skipif('types.color.python_colour_type is None') class TestColorType(TestCase): def create_models(self): class Document(self.Base): diff --git a/tests/types/test_encrypted.py b/tests/types/test_encrypted.py index d5ca19c..7b28866 100644 --- a/tests/types/test_encrypted.py +++ b/tests/types/test_encrypted.py @@ -4,7 +4,7 @@ import pytest from pytest import mark cryptography = None try: - import cryptography + import cryptography # noqa except ImportError: pass diff --git a/tests/types/test_int_range.py b/tests/types/test_int_range.py index eed5b7e..a547d52 100644 --- a/tests/types/test_int_range.py +++ b/tests/types/test_int_range.py @@ -35,7 +35,7 @@ class NumberRangeTestCase(TestCase): def test_nullify_range(self): building = self.create_building(None) - assert building.persons_at_night == None + assert building.persons_at_night is None def test_update_with_none(self): interval = intervals.IntInterval('(,)') diff --git a/tests/types/test_json.py b/tests/types/test_json.py index 5115883..ab4939a 100644 --- a/tests/types/test_json.py +++ b/tests/types/test_json.py @@ -52,6 +52,7 @@ class JSONTestCase(TestCase): class TestSqliteJSONType(JSONTestCase): pass + @mark.skipif('json.json is None') class TestPostgresJSONType(JSONTestCase): dns = 'postgres://postgres@localhost/sqlalchemy_utils_test' diff --git a/tests/types/test_password.py b/tests/types/test_password.py index e779402..8f28133 100644 --- a/tests/types/test_password.py +++ b/tests/types/test_password.py @@ -2,11 +2,10 @@ from pytest import mark import sqlalchemy as sa from tests import TestCase from sqlalchemy import inspect -from sqlalchemy_utils.types import password -from sqlalchemy_utils import Password, PasswordType +from sqlalchemy_utils import Password, PasswordType, types # noqa -@mark.skipif('password.passlib is None') +@mark.skipif('types.password.passlib is None') class TestPasswordType(TestCase): def create_models(self): class User(self.Base): @@ -142,12 +141,12 @@ class TestPasswordType(TestCase): obj.password = None assert obj.password is None - assert obj.password == None + assert obj.password == None # noqa obj.password = 'b' assert obj.password is not None - assert obj.password != None + assert obj.password != None # noqa def test_check_and_update_persist(self): """ diff --git a/tests/types/test_phonenumber.py b/tests/types/test_phonenumber.py index 7de20cf..fbeb1db 100644 --- a/tests/types/test_phonenumber.py +++ b/tests/types/test_phonenumber.py @@ -3,11 +3,10 @@ import sqlalchemy as sa from pytest import mark from tests import TestCase -from sqlalchemy_utils import PhoneNumberType, PhoneNumber -from sqlalchemy_utils.types import phone_number +from sqlalchemy_utils import PhoneNumberType, PhoneNumber, types # noqa -@mark.skipif('phone_number.phonenumbers is None') +@mark.skipif('types.phone_number.phonenumbers is None') class TestPhoneNumber(object): def setup_method(self, method): self.valid_phone_numbers = [ @@ -48,13 +47,13 @@ class TestPhoneNumber(object): def test_phone_number_str_repr(self): number = PhoneNumber('+358401234567') if six.PY2: - assert unicode(number) == number.national + assert unicode(number) == number.national # noqa assert str(number) == number.national.encode('utf-8') else: assert str(number) == number.national -@mark.skipif('phone_number.phonenumbers is None') +@mark.skipif('types.phone_number.phonenumbers is None') class TestPhoneNumberType(TestCase): def create_models(self): diff --git a/tests/types/test_timezone.py b/tests/types/test_timezone.py index c147636..0110be7 100644 --- a/tests/types/test_timezone.py +++ b/tests/types/test_timezone.py @@ -1,12 +1,7 @@ -from pytest import mark -import six import sqlalchemy as sa from sqlalchemy_utils.types import timezone from tests import TestCase -import dateutil -import pytz - class TestTimezoneType(TestCase): def create_models(self):