mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-12-03 13:19:58 -05:00
Increasing test coverage.
This commit is contained in:
parent
287edad9e6
commit
acf4453a52
4 changed files with 71 additions and 60 deletions
|
|
@ -1,5 +1,7 @@
|
|||
from unittest import mock
|
||||
|
||||
import pytest
|
||||
|
||||
from modules.map import lib
|
||||
|
||||
|
||||
|
|
@ -19,3 +21,38 @@ def test_get_map_paths(test_directory):
|
|||
with mock.patch('modules.map.lib.subprocess.check_output') as mock_check_output:
|
||||
mock_check_output.return_value = b'PostgreSQL custom database dump'
|
||||
assert lib.get_map_paths() == [dump, ]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_import_file(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)
|
||||
|
||||
pbf_file.touch()
|
||||
with pytest.raises(ValueError):
|
||||
await lib.import_file(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:
|
||||
# Run the import, it succeeds.
|
||||
mock_asyncio.create_subprocess_shell = mock_create_subprocess_shell(
|
||||
communicate_return=(b'out', b'error')
|
||||
)
|
||||
mock_is_pbf_file.return_value = True
|
||||
await lib.import_file(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:
|
||||
# Run the import, it fails.
|
||||
mock_asyncio.create_subprocess_shell = mock_create_subprocess_shell(
|
||||
communicate_return=(b'out', b'error'),
|
||||
return_code=1,
|
||||
)
|
||||
mock_is_pbf_file.return_value = True
|
||||
with pytest.raises(ValueError):
|
||||
await lib.import_file(pbf_file)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue