Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async #8

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[run]
omit =
utilery/worker.py
utilery/serve.py
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ __pycache__
local.py
*.egg-info
.coverage
.cache/
bench.txt
htmlcov/
1 change: 0 additions & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
[pytest]
addopts = --cov=utilery/
omit=utilery/serve.py
5 changes: 3 additions & 2 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pytest==2.7.2
pytest-cov==2.1.0
pytest
pytest-cov
pytest-asyncio
11 changes: 6 additions & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
asyncpg==0.12.0
mapbox-vector-tile==1.2.0
mercantile==0.10.0
protobuf==3.4.0
PyYAML==3.11
git+https://github.com/mapzen/mapbox-vector-tile
mercantile==0.8.2
protobuf==3.0.0a3
psycopg2==2.6.1
Werkzeug==0.10.4
roll==0.2.0
ujson==1.35
21 changes: 15 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
"Micro vector tile manufacturing from PostGIS."

from setuptools import setup, find_packages
from codecs import open # To use a consistent encoding
from os import path

import utilery
VERSION = (0, 0, 1)

__author__ = 'Yohan Boniface'
__contact__ = "[email protected]"
__homepage__ = "https://github.com/tilery/utilery"
__version__ = ".".join(map(str, VERSION))


here = path.abspath(path.dirname(__file__))

Expand All @@ -14,17 +22,18 @@
def is_pkg(line):
return line and not line.startswith(('--', 'git', '#'))


with open('requirements.txt', encoding='utf-8') as reqs:
install_requires = [l for l in reqs.read().split('\n') if is_pkg(l)]

setup(
name='utilery',
version=utilery.__version__,
description=utilery.__doc__,
version=__version__,
description=__doc__,
long_description=long_description,
url=utilery.__homepage__,
author=utilery.__author__,
author_email=utilery.__contact__,
url=__homepage__,
author=__author__,
author_email=__contact__,
license='WTFPL',

# See https://pypi.python.org/pypi?%3Aaction=list_classifiers
Expand Down
42 changes: 10 additions & 32 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,19 @@
from copy import deepcopy
import os
from pathlib import Path

import pytest
from werkzeug.test import Client
from werkzeug.wrappers import BaseResponse

from .utils import copy

# Do not import anything that can import config before we can patch it.


class TestPlugin(object):

def on_before_load(self, config):
config.BEFORE_LOAD = True

def on_load(self, config, recipes):
assert config.BEFORE_LOAD
config.LOAD = True


def pytest_configure(config):
path = Path(str(config.rootdir)) / 'utilery/config/test.py'
config.OLD_UTILERY_SETTINGS = os.environ.get('UTILERY_SETTINGS')
os.environ['UTILERY_SETTINGS'] = str(path)
from utilery import config as uconfig
uconfig.RECIPES = []
uconfig.PLUGINS = [TestPlugin]
from utilery import core
from utilery.models import Recipe
core.RECIPES['default'] = Recipe({
Expand All @@ -47,11 +34,19 @@ def pytest_unconfigure(config):
os.environ['UTILERY_SETTINGS'] = config.OLD_UTILERY_SETTINGS or ''


@pytest.yield_fixture
def app():
from utilery.views import app as myapp
hooks = deepcopy(myapp.hooks)
yield myapp
myapp.hooks = hooks


@pytest.fixture
def fetchall(monkeypatch):

def _(result, check=None):
def func(*args, **kwargs):
async def func(*args, **kwargs):
if check:
check(*args, **kwargs)
return result
Expand All @@ -60,12 +55,6 @@ def func(*args, **kwargs):
return _


@pytest.fixture
def client():
from utilery.views import app
return Client(app, BaseResponse)


class MonkeyPatchWrapper(object):
def __init__(self, monkeypatch, wrapped_object):
super().__setattr__('monkeypatch', monkeypatch)
Expand Down Expand Up @@ -110,14 +99,3 @@ def layer(recipes):
recipes['default'] = recipe
layer = recipe.layers['mylayer']
return layer


@pytest.fixture
def plugins(monkeypatch):
from utilery.plugins import Plugins

# Reset plugins.
monkeypatch.setattr(Plugins, '_registry', [])
monkeypatch.setattr(Plugins, '_hooks', {})

return lambda p: Plugins.register_plugin(p)
28 changes: 14 additions & 14 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

def test_basic_recipe():
recipe = Recipe({
"name": "myrecipe",
"layers": [{
"name": "mylayer",
"queries": [{
"sql": "SELECT * FROM table"
'name': 'myrecipe',
'layers': [{
'name': 'mylayer',
'queries': [{
'sql': 'SELECT * FROM table'
}]
}]
})
Expand All @@ -18,19 +18,19 @@ def test_basic_recipe():

def test_query_inherit_from_parents():
recipe = Recipe({
"name": "myrecipe",
"srid": 3857,
"buffer": 256,
"layers": [{
"name": "mylayer",
"buffer": 128,
"queries": [{
"sql": "SELECT * FROM table"
'name': 'myrecipe',
'srid': 3857,
'buffer': 256,
'layers': [{
'name': 'mylayer',
'buffer': 128,
'queries': [{
'sql': 'SELECT * FROM table'
}]
}]
})
query = recipe.layers['mylayer'].queries[0]
assert query.sql == "SELECT * FROM table"
assert query.sql == 'SELECT * FROM table'
assert query.buffer == 128
assert query.srid == 3857
assert query.unknown is None
Loading