|
18 | 18 |
|
19 | 19 | import logging |
20 | 20 | from os import path as op |
| 21 | +from io import StringIO |
21 | 22 | import os |
22 | 23 | import subprocess |
23 | 24 | import sys |
@@ -193,6 +194,27 @@ def run_import(cls, params, filename): |
193 | 194 | raise RuntimeError("Import failed.") |
194 | 195 |
|
195 | 196 |
|
| 197 | + @classmethod |
| 198 | + def import_from_string(cls, content, format='opl'): |
| 199 | + cmdline = [CONFIG['executable']] |
| 200 | + params = cls.get_def_params() + cls.extra_params |
| 201 | + if not '-d' in params and not '--database' in params: |
| 202 | + cmdline.extend(('-d', CONFIG['test_database'])) |
| 203 | + cmdline.extend(params) |
| 204 | + cmdline.extend(('-r', format, '-')) |
| 205 | + logging.info("Executing command: {}".format(' '.join(cmdline))) |
| 206 | + |
| 207 | + proc = subprocess.Popen(cmdline, stdin=subprocess.PIPE, |
| 208 | + stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
| 209 | + |
| 210 | + (outp, err) = proc.communicate(input=content.encode('utf-8')) |
| 211 | + |
| 212 | + if proc.returncode == 0: |
| 213 | + logging.debug(err.decode('utf-8')) |
| 214 | + else: |
| 215 | + logging.warning(err.decode('utf-8')) |
| 216 | + raise RuntimeError("Import failed.") |
| 217 | + |
196 | 218 | def assert_count(self, count, table, where=None): |
197 | 219 | if self.schema: |
198 | 220 | table = self.schema + '.' + table |
@@ -873,3 +895,21 @@ class TestDBOutputSchema(BaseUpdateRunnerWithOutputSchema, unittest.TestCase, |
873 | 895 | PgsqlBaseTests): |
874 | 896 | extra_params = ['--slim', '--output-pgsql-schema=osm'] |
875 | 897 |
|
| 898 | +# Bad data tests |
| 899 | + |
| 900 | +class TestBadOSMData(BaseRunner, unittest.TestCase): |
| 901 | + |
| 902 | + extra_params = ['--slim'] |
| 903 | + |
| 904 | + def test_large_relation(self): |
| 905 | + content = StringIO() |
| 906 | + content.write('n1 x45 y34\n') |
| 907 | + content.write('r1 Ttype=multipolygon M') |
| 908 | + for _ in range(33000): |
| 909 | + content.write('n1@,') |
| 910 | + content.write('n1@') |
| 911 | + self.import_from_string(content.getvalue()) |
| 912 | + |
| 913 | + self.assert_count(1, 'planet_osm_nodes') |
| 914 | + self.assert_count(0, 'planet_osm_rels') |
| 915 | + |
0 commit comments