def _import_pbf(self): db_name = self._postgres.get_db_name() postgres_user = self._postgres.get_user() osm_2_pgsql_command = [ 'osm2pgsql', '--create', '--extra-attributes', '--slim', '--latlon', '--database', db_name, '--prefix', 'osm', '--style', self._terminal_style_path, '--tag-transform-script', self._style_path, '--number-processes', '8', '--username', postgres_user, '--hstore-all', '--input-reader', 'pbf', self._pbf_file_path, ] logged_check_call(osm_2_pgsql_command)
def cut_area_from_pbf(pbf_result_file_path, extent_polyfile_path): command = [ "osmconvert", "--out-pbf", "--complete-ways", "--complex-ways", "-o={}".format(pbf_result_file_path), "-B={}".format(extent_polyfile_path), "{}".format(CONVERSION_SETTINGS["PBF_PLANET_FILE_PATH"]), ] logged_check_call(command)
def test_logged_check_call_logs_error_content(mocker, subprocess_check_call_mock): error_output = 'example output' error_return_code = 17 command = 'cmd' error = subprocess.CalledProcessError(cmd=command, output=error_output, returncode=error_return_code) subprocess_check_call_mock.side_effect = error logger_mock = mocker.patch.object(utils.logger, 'error') with pytest.raises(subprocess.CalledProcessError): utils.logged_check_call(command) expected_output = 'Command `cmd` exited with return value 17\nOutput:\nexample output' logger_mock.assert_called_with(expected_output)
def test_logged_check_call_raises(): with pytest.raises(subprocess.CalledProcessError) as excinfo: utils.logged_check_call(['false']) assert excinfo.value.output is None assert excinfo.value.returncode == 1
def test_logged_check_call_forwards_kwargs(subprocess_check_call_mock): test_call = "echo 0" utils.logged_check_call(test_call, shell=True) subprocess_check_call_mock.assert_called_with(test_call, shell=True)
def test_logged_check_call_forwards_args(subprocess_check_call_mock): test_call = ['echo', '0'] utils.logged_check_call(test_call) subprocess_check_call_mock.assert_called_with(test_call)