community.docker/tests/unit/plugins/modules/test_docker_container_copy_into.py
Felix Fontein e8ec22d3b1
Python code modernization, 3/n (#1157)
* Remove __metaclass__ = type.

for i in $(grep -REl '__metaclass__ = type' plugins/ tests/); do
  sed -e '/^__metaclass__ = type/d' -i $i;
done

* Remove super arguments, and stop inheriting from object.
2025-10-10 08:11:58 +02:00

82 lines
1.9 KiB
Python

# Copyright 2025 Felix Fontein <felix@fontein.de>
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
from __future__ import annotations
import pytest
from ansible_collections.community.docker.plugins.modules.docker_container_copy_into import (
parse_modern,
parse_octal_string_only,
)
@pytest.mark.parametrize(
"value, expected",
[
("0777", 0o777),
("777", 0o777),
("0o777", 0o777),
("0755", 0o755),
("755", 0o755),
("0o755", 0o755),
("0644", 0o644),
("644", 0o644),
("0o644", 0o644),
(" 0644 ", 0o644),
(" 644 ", 0o644),
(" 0o644 ", 0o644),
("-1", -1),
],
)
def test_parse_string(value, expected):
assert parse_modern(value) == expected
assert parse_octal_string_only(value) == expected
@pytest.mark.parametrize(
"value",
[
0o777,
0o755,
0o644,
12345,
123456789012345678901234567890123456789012345678901234567890,
],
)
def test_parse_int(value):
assert parse_modern(value) == value
with pytest.raises(TypeError, match=f"^must be an octal string, got {value}L?$"):
parse_octal_string_only(value)
@pytest.mark.parametrize(
"value",
[
1.0,
755.5,
[],
{},
],
)
def test_parse_bad_type(value):
with pytest.raises(TypeError, match="^must be an octal string or an integer, got "):
parse_modern(value)
with pytest.raises(TypeError, match="^must be an octal string, got "):
parse_octal_string_only(value)
@pytest.mark.parametrize(
"value",
[
"foo",
"8",
"9",
],
)
def test_parse_bad_value(value):
with pytest.raises(ValueError):
parse_modern(value)
with pytest.raises(ValueError):
parse_octal_string_only(value)