未验证 提交 3386811b 编写于 作者: F Frost Ming

Fix toml parsing error

上级 0b4e493f
Fix a bug that TOML parsing error is not correctly captured.
......@@ -2,6 +2,7 @@ import re
from pathlib import Path
import tomlkit
import tomlkit.exceptions
from pdm.formats.base import MetaConverter, convert_from
from pdm.models.requirements import parse_requirement
......@@ -9,7 +10,10 @@ from pdm.models.requirements import parse_requirement
def check_fingerprint(project, filename):
with open(filename, encoding="utf-8") as fp:
data = tomlkit.parse(fp.read())
try:
data = tomlkit.parse(fp.read())
except tomlkit.exceptions.TOMLKitError:
return False
return "tool" in data and "flit" in data["tool"]
......
......@@ -3,6 +3,7 @@ import operator
import re
import tomlkit
import tomlkit.exceptions
from pdm.formats.base import MetaConverter, convert_from
from pdm.models.markers import Marker
......@@ -11,7 +12,10 @@ from pdm.models.specifiers import PySpecSet
def check_fingerprint(project, filename):
with open(filename, encoding="utf-8") as fp:
data = tomlkit.parse(fp.read())
try:
data = tomlkit.parse(fp.read())
except tomlkit.exceptions.TOMLKitError:
return False
return "tool" in data and "poetry" in data["tool"]
......
......@@ -8,6 +8,7 @@ import pytest
from pdm.cli import actions
from pdm.models.requirements import parse_requirement
from pdm.utils import get_python_version, temp_environ
from tests import FIXTURES
def test_help_option(invoke):
......@@ -239,3 +240,18 @@ def test_cache_clear_command(project, invoke, mocker):
result = invoke(["cache", "clear"], obj=project)
assert result.exit_code == 0
m.assert_called_once()
@pytest.mark.parametrize(
"filename",
[
"requirements.txt",
"Pipfile",
"pyproject-poetry.toml",
"projects/flit-demo/pyproject.toml",
],
)
def test_import_other_format_file(project, invoke, filename):
requirements_file = FIXTURES / filename
result = invoke(["import", str(requirements_file)], obj=project)
assert result.exit_code == 0
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册