Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sysctl): Fix deserializer #820

Merged
merged 1 commit into from
Oct 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions hathor/sysctl/runner.py
Original file line number Diff line number Diff line change
@@ -76,7 +76,7 @@ def deserialize(self, value_str: str) -> Any:
if len(value_str) == 0:
return ()

parts = [x.strip() for x in value_str.split(',')]
parts = json.loads(f'[{value_str}]')
if len(parts) > 1:
return tuple(json.loads(x) for x in parts)
return tuple(parts)
return json.loads(value_str)
31 changes: 31 additions & 0 deletions tests/sysctl/test_runner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

import pytest

from hathor.sysctl import Sysctl
from hathor.sysctl.runner import SysctlRunner


@pytest.mark.parametrize(
'args',
[
'string',
"\"",
1,
True,
False,
'a,b',
(1, 2, 3),
(1, 'string', True),
[1, 2, 3],
(1, [1, 2, 3]),
(1, ["a,a,a", "b", "c"]),
]
)
def test_deserialize(args):
root = Sysctl()
runner = SysctlRunner(root)

args_serialized = runner.serialize(args)
args_deserialized = runner.deserialize(args_serialized)

assert args == args_deserialized