mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-06-28 06:41:43 +00:00
fix: parse array variable from command
This commit is contained in:
@ -122,11 +122,10 @@ def test_patch_create_from_function(mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must create function patch from file
|
||||
"""
|
||||
path = Path("local")
|
||||
patch = PkgbuildPatch("version", "patch")
|
||||
read_mock = mocker.patch("pathlib.Path.read_text", return_value=patch.value)
|
||||
|
||||
assert Patch.patch_create_from_function(patch.key, path) == patch
|
||||
assert Patch.patch_create_from_function(patch.key, Path("local")) == patch
|
||||
read_mock.assert_called_once_with(encoding="utf8")
|
||||
|
||||
|
||||
@ -148,6 +147,15 @@ def test_patch_create_from_function_strip(mocker: MockerFixture) -> None:
|
||||
assert Patch.patch_create_from_function(patch.key, None) == patch
|
||||
|
||||
|
||||
def test_patch_create_from_function_array(mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must correctly read array variable
|
||||
"""
|
||||
patch = PkgbuildPatch("version", ["array", "patch"])
|
||||
mocker.patch("pathlib.Path.read_text", return_value=f"({" ".join(patch.value)})")
|
||||
assert Patch.patch_create_from_function(patch.key, Path("local")) == patch
|
||||
|
||||
|
||||
def test_patch_set_list(application: Application, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must list available patches for the command
|
||||
|
@ -12,7 +12,7 @@ from unittest.mock import call as MockCall
|
||||
from ahriman.core.exceptions import BuildError, CalledProcessError, OptionError, UnsafeRunError
|
||||
from ahriman.core.util import check_output, check_user, dataclass_view, enum_values, extract_user, filter_json, \
|
||||
full_version, minmax, package_like, parse_version, partition, pretty_datetime, pretty_size, safe_filename, \
|
||||
srcinfo_property, srcinfo_property_list, trim_package, unquote, utcnow, walk
|
||||
srcinfo_property, srcinfo_property_list, trim_package, utcnow, walk
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.package_source import PackageSource
|
||||
from ahriman.models.repository_id import RepositoryId
|
||||
@ -445,26 +445,6 @@ def test_trim_package() -> None:
|
||||
assert trim_package("package: a description") == "package"
|
||||
|
||||
|
||||
def test_unquote() -> None:
|
||||
"""
|
||||
must remove quotation marks
|
||||
"""
|
||||
for source in (
|
||||
"abc",
|
||||
"ab'c",
|
||||
"ab\"c",
|
||||
):
|
||||
assert unquote(shlex.quote(source)) == source
|
||||
|
||||
|
||||
def test_unquote_error() -> None:
|
||||
"""
|
||||
must raise value error on invalid quotation
|
||||
"""
|
||||
with pytest.raises(ValueError):
|
||||
unquote("ab'c")
|
||||
|
||||
|
||||
def test_utcnow() -> None:
|
||||
"""
|
||||
must generate correct timestamp
|
||||
|
@ -1,3 +1,6 @@
|
||||
import pytest
|
||||
import shlex
|
||||
|
||||
from pathlib import Path
|
||||
from pytest_mock import MockerFixture
|
||||
from unittest.mock import MagicMock, call
|
||||
@ -48,6 +51,35 @@ def test_from_env() -> None:
|
||||
assert PkgbuildPatch.from_env("KEY") == PkgbuildPatch("KEY", "")
|
||||
|
||||
|
||||
def test_parse() -> None:
|
||||
"""
|
||||
must parse string correctly
|
||||
"""
|
||||
assert PkgbuildPatch.parse("VALUE") == "VALUE"
|
||||
assert PkgbuildPatch.parse("(ARRAY VALUE)") == ["ARRAY", "VALUE"]
|
||||
assert PkgbuildPatch.parse("""("QU'OUTED" ARRAY VALUE)""") == ["QU'OUTED", "ARRAY", "VALUE"]
|
||||
|
||||
|
||||
def test_unquote() -> None:
|
||||
"""
|
||||
must remove quotation marks
|
||||
"""
|
||||
for source in (
|
||||
"abc",
|
||||
"ab'c",
|
||||
"ab\"c",
|
||||
):
|
||||
assert PkgbuildPatch.unquote(shlex.quote(source)) == source
|
||||
|
||||
|
||||
def test_unquote_error() -> None:
|
||||
"""
|
||||
must raise value error on invalid quotation
|
||||
"""
|
||||
with pytest.raises(ValueError):
|
||||
PkgbuildPatch.unquote("ab'c")
|
||||
|
||||
|
||||
def test_serialize() -> None:
|
||||
"""
|
||||
must correctly serialize string values
|
||||
|
Reference in New Issue
Block a user