Skip to content

Commit

Permalink
Fix linters (#179)
Browse files Browse the repository at this point in the history
* fix lints

* fix linters

* install requirements
  • Loading branch information
jettify committed Aug 4, 2018
1 parent 34baa87 commit f15cab3
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 20 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Expand Up @@ -18,9 +18,11 @@ install:
- pip install coverage
- pip install pytest
- pip install pytest-cov
- pip install -r requirements-dev.txt
- pip install codecov

script:
- make flake
- make docker_build
- make docker_cov

Expand Down
5 changes: 4 additions & 1 deletion Makefile
Expand Up @@ -3,7 +3,10 @@
FLAGS=


flake:
checkrst:
python setup.py check --restructuredtext

flake: checkrst
flake8 aioodbc tests examples setup.py

test: flake
Expand Down
2 changes: 1 addition & 1 deletion examples/example_complex_queries.py
Expand Up @@ -38,7 +38,7 @@ async def test_error_without_context_managers(loop=None):
await cur.execute("SELECT 42 AS;")
rows = await cur.fetchall()
print(rows)
except:
except Exception:
pass
finally:
await cur.close()
Expand Down
11 changes: 11 additions & 0 deletions requirements-dev.txt
@@ -1,6 +1,17 @@
coverage==4.5.1
aiodocker==0.13.0
flake8==3.5.0
flake8-blind-except==0.1.1
flake8-bugbear==18.2.0
flake8-builtins-unleashed==1.3.1
flake8-class-newline==1.6.0
flake8-comprehensions==1.4.1
flake8-debugger==3.1.0
flake8-mock==0.3
flake8-mutable==1.2.0
flake8-mypy==17.8.0
flake8-pyi==18.3.1
flake8-tuple==0.2.13
ipdb==0.11
ipython==6.4.0
pyodbc==4.0.23
Expand Down
2 changes: 2 additions & 0 deletions setup.py
Expand Up @@ -15,6 +15,7 @@
def read(f):
return open(os.path.join(os.path.dirname(__file__), f)).read().strip()


extras_require = {}


Expand All @@ -30,6 +31,7 @@ def read_version():
else:
raise RuntimeError('Cannot find version in aioodbc/__init__.py')


classifiers = [
'License :: OSI Approved :: Apache Software License',
'Intended Audience :: Developers',
Expand Down
29 changes: 16 additions & 13 deletions tests/conftest.py
@@ -1,7 +1,6 @@
import asyncio
import gc
import os
import socket
import time
import uuid
from concurrent.futures import ThreadPoolExecutor
Expand Down Expand Up @@ -81,15 +80,17 @@ async def pg_server(loop, host, docker, session_id):
await container.start()
port = (await container.port(5432))[0]['HostPort']

pg_params = dict(database='postgres',
user='postgres',
password='mysecretpassword',
host=host,
port=port)
pg_params = {
'database': 'postgres',
'user': 'postgres',
'password': 'mysecretpassword',
'host': host,
'port': port
}
delay = 0.001
dsn = create_pg_dsn(pg_params)
last_error = None
for i in range(100):
for _ in range(100):
try:
conn = pyodbc.connect(dsn)
cur = conn.cursor()
Expand Down Expand Up @@ -141,15 +142,17 @@ async def mysql_server(loop, host, docker, session_id):
)
await container.start()
port = (await container.port(3306))[0]['HostPort']
mysql_params = dict(database='aioodbc',
user='aioodbc',
password='mysecretpassword',
host=host,
port=port)
mysql_params = {
'database': 'aioodbc',
'user': 'aioodbc',
'password': 'mysecretpassword',
'host': host,
'port': port
}
delay = 0.001
dsn = create_mysql_dsn(mysql_params)
last_error = None
for i in range(100):
for _ in range(100):
try:
conn = pyodbc.connect(dsn)
cur = conn.cursor()
Expand Down
12 changes: 7 additions & 5 deletions tests/test_pool.py
Expand Up @@ -5,6 +5,7 @@
from aioodbc import Pool, Connection
from pyodbc import Error


@pytest.mark.asyncio
async def test_create_pool(loop, pool_maker, dsn):
pool = await pool_maker(loop, dsn=dsn)
Expand Down Expand Up @@ -258,6 +259,7 @@ async def test_pool_with_connection_recycling(loop, pool_maker, dsn):

assert conn1 is not conn2


@pytest.mark.asyncio
async def test_concurrency(loop, pool_maker, dsn):
pool = await pool_maker(loop, dsn=dsn, minsize=2, maxsize=4)
Expand Down Expand Up @@ -395,7 +397,8 @@ async def test_close_with_acquired_connections(loop, pool_maker, dsn):
@pytest.mark.parametrize('db', pytest.db_list)
@pytest.mark.asyncio
async def test_pool_with_executor(loop, pool_maker, dsn, executor):
pool = await pool_maker(loop, executor=executor, dsn=dsn, minsize=2, maxsize=2)
pool = await pool_maker(
loop, executor=executor, dsn=dsn, minsize=2, maxsize=2)

conn = await pool.acquire()
try:
Expand Down Expand Up @@ -437,7 +440,7 @@ async def test_pool_context_manager2(loop, pool):
@pytest.mark.parametrize('db', pytest.db_list)
@pytest.mark.asyncio
async def test_all_context_managers(dsn, loop, executor):
kw = dict(dsn=dsn, loop=loop, executor=executor)
kw = {'dsn': dsn, 'loop': loop, 'executor': executor}
async with aioodbc.create_pool(**kw) as pool:
async with pool.acquire() as conn:
async with conn.cursor() as cur:
Expand Down Expand Up @@ -475,16 +478,15 @@ async def aexit_conntex_managet(conn):
async with conn.cursor() as cur:
await cur.execute("SELECT v FROM cmt1 WHERE n=2;")
row = await cur.fetchone()
assert row == None
assert row is None

async with conn.cursor() as cur:
await cur.execute("DROP TABLE cmt1;")

conn = await connection_maker(autocommit=False)
assert not conn.autocommit
await aexit_conntex_managet(conn)

conn = await connection_maker(autocommit=True)
assert conn.autocommit
await aexit_conntex_managet(conn)

0 comments on commit f15cab3

Please sign in to comment.