Repository: openaddresses/machine
Pull request #525 (2017-01-21 17:38:58)

Add North America, non-U.S. extract
Followup to https://github.com/openaddresses/machine/issues/519.


Patch:
diff --git a/openaddr/ci/collect.py b/openaddr/ci/collect.py
index 763dcb3..b6614ff 100644
--- a/openaddr/ci/collect.py
+++ b/openaddr/ci/collect.py
@@ -404,5 +404,16 @@ def is_south_america(result):
 
     return False
 
+def is_north_america(result):
+    for iso in ('ai', 'ag', 'aw', 'bs', 'bb', 'bz', 'bm', 'bq', 'vg', 'ca',
+                'ky', 'cr', 'cu', 'cw', 'dm', 'do', 'sv', 'gl', 'gd', 'gp',
+                'gt', 'ht', 'hn', 'jm', 'mq', 'mx', 'pm', 'ms', 'cw', 'kn',
+                'ni', 'pa', 'pr', 'bq', 'bq', 'sx', 'kn', 'lc', 'pm', 'vc',
+                'tt', 'tc', 'vi'):
+        if _is_country(iso, result):
+            return True
+
+    return False
+
 if __name__ == '__main__':
     exit(main())
diff --git a/openaddr/ci/schema.pgsql b/openaddr/ci/schema.pgsql
index 0ae3a4c..bf2c883 100644
--- a/openaddr/ci/schema.pgsql
+++ b/openaddr/ci/schema.pgsql
@@ -66,7 +66,7 @@ CREATE TABLE runs
 );
 
 CREATE TYPE zip_collection AS ENUM ('global', 'us_northeast', 'us_midwest',
-    'us_south', 'us_west', 'europe', 'asia', 'south_america');
+    'us_south', 'us_west', 'europe', 'asia', 'south_america', 'north_america');
 CREATE TYPE zip_licensing AS ENUM ('', 'sa');
 
 CREATE TABLE zips
diff --git a/openaddr/ci/templates/index.html b/openaddr/ci/templates/index.html
index 88a2a79..9fc53c2 100644
--- a/openaddr/ci/templates/index.html
+++ b/openaddr/ci/templates/index.html
@@ -139,10 +139,16 @@
     </tr>
     <tr>
         <td>South America</td>
-        <td><a href="https://www.countries-ofthe-world.com/countries-of-south-america.html">List of countries in South America</a></td>
+        <td><a href="https://www.countries-ofthe-world.com/countries-of-south-america.html">Countries in South America</a></td>
         <td>{% set key = ('south_america', '') %}{% include "index-zip.html" %}</td>
         <td>{% set key = ('south_america', 'sa') %}{% include "index-zip.html" %}</td>
     </tr>
+    <tr>
+        <td>North America (except U.S.)</td>
+        <td><a href="https://www.countries-ofthe-world.com/countries-of-north-america.html">Countries in North America</a></td>
+        <td>{% set key = ('north_america', '') %}{% include "index-zip.html" %}</td>
+        <td>{% set key = ('north_america', 'sa') %}{% include "index-zip.html" %}</td>
+    </tr>
 </table>
 <p>
     <button onclick="choosemap('https://s3.amazonaws.com/{{ s3_bucket }}/render-world.png')">Show World</button>


Test patch:
diff --git a/openaddr/tests/ci.py b/openaddr/tests/ci.py
index 87b0ee6..123c4be 100644
--- a/openaddr/tests/ci.py
+++ b/openaddr/tests/ci.py
@@ -45,7 +45,7 @@ from ..ci.objects import (
 
 from ..ci.collect import (
     is_us_northeast, is_us_midwest, is_us_south, is_us_west, is_europe, is_asia,
-    is_south_america, add_source_to_zipfile, CollectorPublisher,
+    is_south_america, is_north_america, add_source_to_zipfile, CollectorPublisher,
     prepare_collections, add_csv_to_zipfile, write_to_s3, MULTIPART_CHUNK_SIZE
     )
 
@@ -3605,7 +3605,8 @@ class TestCollect (unittest.TestCase):
         '''
         '''
         _ = None
-        test_funcs = is_us_northeast, is_us_midwest, is_us_south, is_us_west, is_europe, is_asia, is_south_america
+        test_funcs = is_us_northeast, is_us_midwest, is_us_south, is_us_west, \
+                     is_europe, is_asia, is_south_america, is_north_america
         
         for abbr in ('ct', 'me', 'ma', 'nh', 'ri', 'vt', 'nj', 'ny', 'pa'):
             for source_base in ('us/{}'.format(abbr), 'us/{}.---'.format(abbr), 'us/{}/---'.format(abbr)):
@@ -3682,6 +3683,19 @@ class TestCollect (unittest.TestCase):
                     if test_func is not is_south_america:
                         self.assertFalse(test_func(result), '{}("{}") should be false'.format(test_func.__name__, source_base))
 
+        for iso in ('ai', 'ag', 'aw', 'bs', 'bb', 'bz', 'bm', 'bq', 'vg', 'ca',
+                    'ky', 'cr', 'cu', 'cw', 'dm', 'do', 'sv', 'gl', 'gd', 'gp',
+                    'gt', 'ht', 'hn', 'jm', 'mq', 'mx', 'pm', 'ms', 'cw', 'kn',
+                    'ni', 'pa', 'pr', 'bq', 'bq', 'sx', 'kn', 'lc', 'pm', 'vc',
+                    'tt', 'tc', 'vi'):
+            for source_base in (iso, '{}.---'.format(iso), '{}/---'.format(iso)):
+                result = LocalProcessedResult(source_base, None, RunState(None), None)
+                self.assertTrue(is_north_america(result), 'is_north_america("{}") should be true'.format(source_base))
+            
+                for test_func in test_funcs:
+                    if test_func is not is_north_america:
+                        self.assertFalse(test_func(result), '{}("{}") should be false'.format(test_func.__name__, source_base))
+
     def test_add_source_to_zipfile(self):
         '''
         '''