Make flake8 part of test suite
This commit is contained in:
parent
6292bda8aa
commit
92817d5f4d
@ -6,3 +6,4 @@ python:
|
||||
- '2.6'
|
||||
script:
|
||||
- python setup.py test
|
||||
- flake8 --ignore=E501,E123,E124,E126,E127,E128 dataset test
|
||||
|
||||
@ -8,7 +8,6 @@ from dataset.persistence.util import sqlite_datetime_fix
|
||||
from dataset.persistence.database import Database
|
||||
from dataset.persistence.table import Table
|
||||
from dataset.freeze.app import freeze
|
||||
from sqlalchemy import Integer, Text
|
||||
|
||||
__all__ = ['Database', 'Table', 'freeze', 'connect']
|
||||
|
||||
|
||||
@ -33,7 +33,7 @@ def freeze(result, format='csv', filename='freeze.csv',
|
||||
|
||||
result = db['person'].all()
|
||||
dataset.freeze(result, format='json', filename='all-persons.json')
|
||||
|
||||
|
||||
If ``result`` is a table (rather than a result set), all records in
|
||||
the table are exported (as if ``result.all()`` had been called).
|
||||
|
||||
@ -59,7 +59,7 @@ def freeze(result, format='csv', filename='freeze.csv',
|
||||
|
||||
*json*
|
||||
A JSON file containing a list of dictionaries for each row
|
||||
in the table. If a ``callback`` is given, JSON with padding
|
||||
in the table. If a ``callback`` is given, JSON with padding
|
||||
(JSONP) will be generated.
|
||||
|
||||
*tabson*
|
||||
|
||||
@ -82,8 +82,7 @@ class Export(object):
|
||||
@property
|
||||
def skip(self):
|
||||
return self.get_bool('skip')
|
||||
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
return self.get('name', self.get('query'))
|
||||
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import os
|
||||
import logging
|
||||
import re
|
||||
import locale
|
||||
|
||||
@ -69,8 +68,7 @@ class Serializer(object):
|
||||
|
||||
@property
|
||||
def wrap(self):
|
||||
return self.export.get_bool('wrap',
|
||||
default=self.mode=='list')
|
||||
return self.export.get_bool('wrap', default=self.mode == 'list')
|
||||
|
||||
def serialize(self):
|
||||
self.init()
|
||||
|
||||
@ -21,4 +21,3 @@ class TabsonSerializer(JSONSerializer):
|
||||
if meta is not None:
|
||||
result['meta'] = meta
|
||||
return result
|
||||
|
||||
|
||||
@ -11,9 +11,9 @@ except ImportError:
|
||||
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.pool import NullPool
|
||||
from sqlalchemy.schema import MetaData, Column, Index
|
||||
from sqlalchemy.schema import MetaData, Column
|
||||
from sqlalchemy.schema import Table as SQLATable
|
||||
from sqlalchemy import Integer, Text, String
|
||||
from sqlalchemy import Integer, String
|
||||
|
||||
from alembic.migration import MigrationContext
|
||||
from alembic.operations import Operations
|
||||
@ -107,10 +107,8 @@ class Database(object):
|
||||
|
||||
@property
|
||||
def tables(self):
|
||||
""" Get a listing of all tables that exist in the database.
|
||||
|
||||
>>> print db.tables
|
||||
set([u'user', u'action'])
|
||||
"""
|
||||
Get a listing of all tables that exist in the database.
|
||||
"""
|
||||
return list(
|
||||
set(self.metadata.tables.keys()) | set(self._tables.keys())
|
||||
|
||||
@ -24,9 +24,6 @@ class Table(object):
|
||||
def columns(self):
|
||||
"""
|
||||
Get a listing of all columns that exist in the table.
|
||||
|
||||
>>> print 'age' in table.columns
|
||||
True
|
||||
"""
|
||||
return set(self.table.columns.keys())
|
||||
|
||||
@ -90,7 +87,7 @@ class Table(object):
|
||||
self._ensure_columns(row, types=types)
|
||||
self.table.insert().execute(chunk)
|
||||
self._check_dropped()
|
||||
|
||||
|
||||
chunk = []
|
||||
for i, row in enumerate(rows, start=1):
|
||||
chunk.append(row)
|
||||
@ -100,7 +97,6 @@ class Table(object):
|
||||
|
||||
if chunk:
|
||||
_process_chunk(chunk)
|
||||
|
||||
|
||||
def update(self, row, keys, ensure=True, types={}):
|
||||
"""
|
||||
@ -122,7 +118,7 @@ class Table(object):
|
||||
if not isinstance(keys, (list, tuple)):
|
||||
keys = [keys]
|
||||
self._check_dropped()
|
||||
if not keys or len(keys)==len(row):
|
||||
if not keys or len(keys) == len(row):
|
||||
return False
|
||||
clause = [(u, row.get(u)) for u in keys]
|
||||
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
#coding: utf-8
|
||||
import re
|
||||
from unicodedata import normalize as ucnorm, category
|
||||
|
||||
SLUG_REMOVE = re.compile(r'[,\s\.\(\)/\\;:]*')
|
||||
|
||||
|
||||
class DatasetException(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class FreezeException(DatasetException):
|
||||
pass
|
||||
|
||||
|
||||
2
setup.py
2
setup.py
@ -35,7 +35,7 @@ setup(
|
||||
'python-slugify >= 0.0.6',
|
||||
"PyYAML >= 3.10"
|
||||
] + py26_dependency,
|
||||
tests_require=[],
|
||||
tests_require=['flake8'],
|
||||
test_suite='test',
|
||||
entry_points={
|
||||
'console_scripts': [
|
||||
|
||||
@ -8,7 +8,6 @@ from dataset import connect
|
||||
from dataset.util import DatasetException
|
||||
|
||||
from .sample_data import TEST_DATA, TEST_CITY_1
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
|
||||
|
||||
class DatabaseTestCase(unittest.TestCase):
|
||||
@ -53,7 +52,7 @@ class DatabaseTestCase(unittest.TestCase):
|
||||
|
||||
table.insert({
|
||||
'string_id': 'foobar'})
|
||||
assert table.find_one(string_id = 'foobar')['string_id'] == 'foobar'
|
||||
assert table.find_one(string_id='foobar')['string_id'] == 'foobar'
|
||||
|
||||
def test_create_table_custom_id2(self):
|
||||
pid = "string_id"
|
||||
@ -64,19 +63,19 @@ class DatabaseTestCase(unittest.TestCase):
|
||||
|
||||
table.insert({
|
||||
'string_id': 'foobar'})
|
||||
assert table.find_one(string_id = 'foobar')['string_id'] == 'foobar'
|
||||
assert table.find_one(string_id='foobar')['string_id'] == 'foobar'
|
||||
|
||||
def test_create_table_custom_id3(self):
|
||||
pid = "int_id"
|
||||
table = self.db.create_table("foo4", primary_id = pid)
|
||||
table = self.db.create_table("foo4", primary_id=pid)
|
||||
assert table.table.exists()
|
||||
assert len(table.table.columns) == 1, table.table.columns
|
||||
assert pid in table.table.c, table.table.c
|
||||
|
||||
table.insert({'int_id': 123})
|
||||
table.insert({'int_id': 124})
|
||||
assert table.find_one(int_id = 123)['int_id'] == 123
|
||||
assert table.find_one(int_id = 124)['int_id'] == 124
|
||||
assert table.find_one(int_id=123)['int_id'] == 123
|
||||
assert table.find_one(int_id=124)['int_id'] == 124
|
||||
self.assertRaises(IntegrityError, lambda: table.insert({'int_id': 123}))
|
||||
|
||||
def test_create_table_shorthand1(self):
|
||||
@ -88,8 +87,8 @@ class DatabaseTestCase(unittest.TestCase):
|
||||
|
||||
table.insert({'int_id': 123})
|
||||
table.insert({'int_id': 124})
|
||||
assert table.find_one(int_id = 123)['int_id'] == 123
|
||||
assert table.find_one(int_id = 124)['int_id'] == 124
|
||||
assert table.find_one(int_id=123)['int_id'] == 123
|
||||
assert table.find_one(int_id=124)['int_id'] == 124
|
||||
self.assertRaises(IntegrityError, lambda: table.insert({'int_id': 123}))
|
||||
|
||||
def test_create_table_shorthand2(self):
|
||||
@ -101,7 +100,7 @@ class DatabaseTestCase(unittest.TestCase):
|
||||
|
||||
table.insert({
|
||||
'string_id': 'foobar'})
|
||||
assert table.find_one(string_id = 'foobar')['string_id'] == 'foobar'
|
||||
assert table.find_one(string_id='foobar')['string_id'] == 'foobar'
|
||||
|
||||
def test_create_table_shorthand3(self):
|
||||
pid = "string_id"
|
||||
@ -112,7 +111,7 @@ class DatabaseTestCase(unittest.TestCase):
|
||||
|
||||
table.insert({
|
||||
'string_id': 'foobar'})
|
||||
assert table.find_one(string_id = 'foobar')['string_id'] == 'foobar'
|
||||
assert table.find_one(string_id='foobar')['string_id'] == 'foobar'
|
||||
|
||||
def test_load_table(self):
|
||||
tbl = self.db.load_table('weather')
|
||||
@ -138,7 +137,7 @@ class TableTestCase(unittest.TestCase):
|
||||
'temperature': -10,
|
||||
'place': 'Berlin'}
|
||||
)
|
||||
assert len(self.tbl) == len(TEST_DATA)+1, len(self.tbl)
|
||||
assert len(self.tbl) == len(TEST_DATA) + 1, len(self.tbl)
|
||||
assert self.tbl.find_one(id=last_id)['place'] == 'Berlin'
|
||||
|
||||
def test_upsert(self):
|
||||
@ -148,17 +147,17 @@ class TableTestCase(unittest.TestCase):
|
||||
'place': 'Berlin'},
|
||||
['place']
|
||||
)
|
||||
assert len(self.tbl) == len(TEST_DATA)+1, len(self.tbl)
|
||||
assert len(self.tbl) == len(TEST_DATA) + 1, len(self.tbl)
|
||||
self.tbl.upsert({
|
||||
'date': datetime(2011, 1, 2),
|
||||
'temperature': -10,
|
||||
'place': 'Berlin'},
|
||||
['place']
|
||||
)
|
||||
assert len(self.tbl) == len(TEST_DATA)+1, len(self.tbl)
|
||||
assert len(self.tbl) == len(TEST_DATA) + 1, len(self.tbl)
|
||||
|
||||
def test_upsert_all_key(self):
|
||||
for i in range(0,2):
|
||||
for i in range(0, 2):
|
||||
self.tbl.upsert({
|
||||
'date': datetime(2011, 1, 2),
|
||||
'temperature': -10,
|
||||
@ -172,7 +171,7 @@ class TableTestCase(unittest.TestCase):
|
||||
'temperature': -10,
|
||||
'place': 'Berlin'}
|
||||
)
|
||||
assert len(self.tbl) == len(TEST_DATA)+1, len(self.tbl)
|
||||
assert len(self.tbl) == len(TEST_DATA) + 1, len(self.tbl)
|
||||
self.tbl.delete(place='Berlin')
|
||||
assert len(self.tbl) == len(TEST_DATA), len(self.tbl)
|
||||
self.tbl.delete()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user