Sean Gillies ∙ Mapbox
GeoRodeo 2015 ∙ Austin ∙ May 22
"""script.py: print 'Spam and Eggs'."""
def get_msg():
return "Spam and Egs"
# This is a test.
def test_get_msg():
assert get_msg() == "Spam and Eggs"
if __name__ == '__main__':
print(get_msg())
$ py.test script.py
=================================== FAILURES ===================================
_________________________________ test_get_msg _________________________________
def test_get_msg():
> assert get_msg() == "Spam and Eggs"
E assert 'Spam and Egs' == 'Spam and Eggs'
E - Spam and Egs
E + Spam and Eggs
E ? +
script.py:10: AssertionError
=========================== 1 failed in 0.01 seconds ===========================
$ py.test script.py --cov script --cov-report=term-missing
============================= test session starts ==============================
platform darwin -- Python 2.7.9 -- py-1.4.26 -- pytest-2.6.4
plugins: cov
collected 1 items
script.py .
--------------- coverage: platform darwin, python 2.7.9-final-0 ----------------
Name Stmts Miss Cover Missing
--------------------------------------
script 6 1 83% 14
=========================== 1 passed in 0.01 seconds ===========================
# C style.
nums = []
for i in range(100):
nums.append(i)
vs
# Python style.
nums = [i for i in range(100)]
$ python -m timeit -s "ns=[]" "for i in xrange(1000): ns.append(i)"
10000 loops, best of 3: 76.4 usec per loop
vs
$ python -m timeit -s "ns=[i for i in xrange(1000)]"
100000000 loops, best of 3: 0.0108 usec per loop
# Initialized with -s "a = list(range(100000))"
$ python -m timeit "[val + 5 for val in a]"
100 loops, best of 3: 4.99 msec per loop
# Initialiazed with
# -s "import numpy; a = list(range(100000)); a = numpy.array(a)"
$ python -m timeit "a+5"
10000 loops, best of 3: 69.9 usec per loop
from multiprocessing import Pool
def f(x):
return x*x
if __name__ == '__main__':
with Pool(5) as p:
print(p.map(f, [1, 2, 3]))
See https://github.com/mapbox/rio-mbtiles for a raster tiling example.
$ virtualenv venv
$ source venv/bin/activate
(venv)$ pip install -r requirements.txt
$ docker run -itd --name tfrs \
> -v "/Users/sean/code/rasterio/tests/data:/mnt/data:ro" \
> mapbox/travis-frs:pre0 /bin/bash
87d7321ad492574f82c7957670c15e0067d4fcd5b3dd803bc3cef6fadd2e0aeb
$ docker exec tfrs rio shapes --mask /mnt/data/RGB.byte.tif \
> | geojsonio
entry_points={'pytest11': ['pytest_cov = pytest_cov']},