Handling merging multiple pbf files in map importing.

This commit is contained in:
Roland 2022-10-27 20:22:11 -06:00
parent 2b84831205
commit 6854fa3692
No known key found for this signature in database
GPG key ID: 9D6DBD3ACF11AB93
5 changed files with 201 additions and 101 deletions

View file

@ -5,14 +5,11 @@ import pytest
from modules.map import lib
def test_get_map_paths(test_directory):
pbf_dir = test_directory / 'map/pbf'
pbf_dir.mkdir(parents=True)
pbf = pbf_dir / 'map.osm.pbf'
pbf.touch()
dump = pbf_dir / 'map.dump'
dump.touch()
def test_get_map_paths(test_directory, make_files_structure):
pbf, dump = make_files_structure([
'map/pbf/map.osm.pbf',
'map/pbf/map.dump',
])
with mock.patch('modules.map.lib.subprocess.check_output') as mock_check_output:
mock_check_output.return_value = b'OpenStreetMap Protocolbuffer Binary Format'
@ -24,18 +21,21 @@ def test_get_map_paths(test_directory):
@pytest.mark.asyncio
async def test_import_file(test_directory, mock_create_subprocess_shell):
async def test_run_import_command(test_directory, mock_create_subprocess_shell):
"""
Import map files. Files to import are checked for validity before importing. Any errors returned by
asyncio.create_subprocess_shell are caught and reported.
"""
pbf_file = test_directory / 'foo.osm.pbf'
with pytest.raises(ValueError):
await lib.import_file(pbf_file)
await lib.run_import_command(pbf_file)
pbf_file.touch()
with pytest.raises(ValueError):
await lib.import_file(pbf_file)
await lib.run_import_command(pbf_file)
dump_file = test_directory / 'dumpy.dump'
dump_file.touch()
with mock.patch('modules.map.lib.asyncio') as mock_asyncio, \
mock.patch('modules.map.lib.is_pbf_file') as mock_is_pbf_file:
@ -44,7 +44,7 @@ async def test_import_file(test_directory, mock_create_subprocess_shell):
communicate_return=(b'out', b'error')
)
mock_is_pbf_file.return_value = True
await lib.import_file(pbf_file)
await lib.run_import_command(pbf_file)
with mock.patch('modules.map.lib.asyncio') as mock_asyncio, \
mock.patch('modules.map.lib.is_pbf_file') as mock_is_pbf_file:
@ -55,4 +55,13 @@ async def test_import_file(test_directory, mock_create_subprocess_shell):
)
mock_is_pbf_file.return_value = True
with pytest.raises(ValueError):
await lib.import_file(pbf_file)
await lib.run_import_command(pbf_file)
with pytest.raises(ValueError) as e:
await lib.run_import_command()
assert 'Must import a file' in str(e)
# Can't import more than one dump.
with pytest.raises(ValueError) as e:
await lib.run_import_command(dump_file, dump_file)
assert 'more than one' in str(e)