Repository: mapbox/untiler

Issue:
Tests broken on master
Tests fail on Python 3.6 - see [this Travis run](https://travis-ci.org/mapbox/untiler/builds/229187081).

<details>
<summaryFailure</summary>
<pre>
    def test_extract_mbtiles():
        with TestTiler() as tt:
            testpath = tt.path
            testmbtiles = os.path.join(os.path.dirname(__file__), 'fixtures/testtiles.mbtiles')
            runner = CliRunner()
            result = runner.invoke(cli, [
                'streammbtiles', testmbtiles, testpath, '-z', '16', '-x', '-s',
                '{z}-{x}-{y}-mbtiles.tif', '--co', 'compress=lzw'])
            assert result.exit_code == 0
            expected_checksums = [[13858, 8288, 51489, 31223], [17927, 52775, 411, 9217]]
            for o, c in zip(result.output.rstrip().split('\n'), expected_checksums):
                with rio.open(o) as src:
                    checksums = [src.checksum(i) for i in src.indexes]
>                   assert checksums == c
E                   assert [17927, 52775, 411, 9217] == [13858, 8288, 51489, 31223]
E                     At index 0 diff: 17927 != 13858
E                     Use -v to get the full diff
</pre>
</details>

<br />

Noticed this while working on the [autodeploy branch](https://github.com/mapbox/untiler/tree/autodeploy). Initially thought this was failing due to changes I'd made, but I think this is some sort of config/dependency rot that's happening otherwise.

Comments:

Patch:
diff --git a/.travis.yml b/.travis.yml
index 96731bd..1a637a5 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -3,54 +3,27 @@ language: python
 sudo: false
 
 cache:
-  # Apparently if you override the install command that silently disables the
-  # cache: pip support. This is less than ideal and I've opened up
-  # travis-ci/travis-ci#3239 to hopefully get that addressed. For now I'll
-  # manually add the pip cache directory to the build cache.
   directories:
     - ~/.cache/pip
 
 env:
   global:
-    # These two environment variables could be set by Travis itself, or Travis
-    # could configure itself in /etc/, ~/, or inside of the virtual
-    # environments. In any case if these two values get configured then end
-    # users only need to enable the pip cache and manually run pip wheel before
-    # running pip install.
     - PIP_WHEEL_DIR=$HOME/.cache/pip/wheels
     - PIP_FIND_LINKS=file://$HOME/.cache/pip/wheels
 
 python:
-  - "2.7"
   - "3.6"
-
-addons:
-  apt:
-    packages:
-    - libgdal1h
-    - gdal-bin
-    - libgdal-dev
-    - libatlas-dev
-    - libatlas-base-dev
-    - liblapack-dev
-    - gfortran
-    - libgmp-dev
-    - libmpfr-dev
+  - "3.7"
 
 before_install:
   - pip install -U pip
-  - pip install wheel
+  - pip install -r requirements.txt
 
 install:
-  - "pip wheel -r requirements.txt"
-  # Actually install our dependencies now, this will pull from the directory
-  # that the first command placed the Wheels into.
-  - "pip install --no-binary rasterio -r requirements.txt"
-  - "pip install coveralls"
-  - "pip install -e .[test]"
+  - pip install -e .[test]
 
 script:
-  - py.test --cov untiler --cov-report term-missing
+  - python -m pytest --cov untiler --cov-report term-missing
 
 after_success:
-  - coveralls
+  - coveralls
\ No newline at end of file
diff --git a/requirements.txt b/requirements.txt
index d5a62da..7b32ce5 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,3 +1,3 @@
-rasterio==1.0a8
+rasterio==1.1.2
 mercantile
 mbutil
diff --git a/untiler/scripts/tile_utils.py b/untiler/scripts/tile_utils.py
index 3620675..486f1ea 100644
--- a/untiler/scripts/tile_utils.py
+++ b/untiler/scripts/tile_utils.py
@@ -148,7 +148,7 @@ def parse_template(template):
         if len(separator) != 2 or separator[0] != separator[1]:
             raise ValueError('Too many / not matching separators!')
     
-        return valPattern.sub('\d+', template), valPattern.sub('%s', template), separator[0]
+        return valPattern.sub(r"\\d+", template), valPattern.sub("%s", template), separator[0]
     else:
         raise ValueError('Invalid template "%s"' % (template))
 


Test patch:
diff --git a/tests/test_cli.py b/tests/test_cli.py
index 41dc1d7..5ab5c93 100644
--- a/tests/test_cli.py
+++ b/tests/test_cli.py
@@ -7,7 +7,7 @@ import mercantile
 import numpy as np
 import pytest
 import rasterio as rio
-
+import sqlite3
 from untiler.scripts.cli import cli
 
 
@@ -88,7 +88,8 @@ def test_cli_streamdir_mixed_ok_poo():
         tmp = testtiles.path
         runner = CliRunner()
         result = runner.invoke(cli, ['streamdir', tmp, tmp, '-c', '14', '-t', 'poo/{z}/{z}/{z}.jpg'])
-        assert result.exit_code == -1
+
+        assert result.exc_info[0] == ValueError
 
 
 def test_cli_baddir_fails():
@@ -139,11 +140,15 @@ def test_extract_mbtiles():
             'streammbtiles', testmbtiles, testpath, '-z', '16', '-x', '-s',
             '{z}-{x}-{y}-mbtiles.tif', '--co', 'compress=lzw'])
         assert result.exit_code == 0
+
         expected_checksums = [[13858, 8288, 51489, 31223], [17927, 52775, 411, 9217]]
-        for o, c in zip(result.output.rstrip().split('\n'), expected_checksums):
+        checksums = []
+
+        for o in result.output.rstrip().split('\n'):
             with rio.open(o) as src:
-                checksums = [src.checksum(i) for i in src.indexes]
-                assert checksums == c
+                checksums.append([src.checksum(i) for i in src.indexes])
+
+        assert sorted(checksums) == sorted(expected_checksums)
 
 
 def test_extract_mbtiles_fails():
@@ -151,7 +156,9 @@ def test_extract_mbtiles_fails():
         testpath = tt.path
         testmbtiles = os.path.join(os.path.dirname(__file__), 'fixtures/bad.mbtiles')
         runner = CliRunner()
+
         result = runner.invoke(cli, [
             'streammbtiles', testmbtiles, testpath, '-z', '16', '-x', '-s',
             '{z}-{x}-{y}-mbtiles.tif', '--co', 'compress=lzw'])
-        assert result.exit_code == -1
+
+        assert result.exc_info[0] == sqlite3.OperationalError
diff --git a/tests/test_untiler_funcs.py b/tests/test_untiler_funcs.py
index 9a0cf25..a5d30bf 100644
--- a/tests/test_untiler_funcs.py
+++ b/tests/test_untiler_funcs.py
@@ -105,7 +105,7 @@ def expectedTileList():
         return np.array(json.load(ofile))
 
 def test_parse_tiles(inputTilenames, expectedTileList):
-    matchTemplate = '3857_9_83_202_20130517_242834/jpg/\d+/\d+/\d+.jpg'
+    matchTemplate = r'3857_9_83_202_20130517_242834/jpg/\d+/\d+/\d+.jpg'
 
     tiler = tile_utils.TileUtils()