File: test_cleaners.py

package info (click to toggle)
python-asusrouter 1.21.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,856 kB
  • sloc: python: 20,497; makefile: 3
file content (68 lines) | stat: -rw-r--r-- 1,834 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
"""Test AsusRouter cleaners tools."""

from asusrouter.tools import cleaners


def test_clean_content() -> None:
    """Test clean_content method."""

    # Test with BOM
    content = "\ufefftest"
    assert cleaners.clean_content(content) == "test"

    # Test without BOM
    content = "test"
    assert cleaners.clean_content(content) == "test"


def test_clean_dict() -> None:
    """Test clean_dict method."""

    # Test with empty dict
    data = {}
    assert cleaners.clean_dict(data) == {}  # pylint: disable=C1803

    # Test with empty string
    data = {"test": ""}
    assert cleaners.clean_dict(data) == {"test": None}

    # Test with nested dicts
    data = {"test": {"test": ""}}
    assert cleaners.clean_dict(data) == {"test": {"test": None}}


def test_clean_dict_key_prefix() -> None:
    """Test clean_dict_key_prefix method."""

    # Test with empty dict
    data = {}
    assert cleaners.clean_dict_key_prefix(data, "prefix") == {}  # pylint: disable=C1803

    # Test with empty string
    data = {"prefix_test": "", "test2": ""}
    assert cleaners.clean_dict_key_prefix(data, "prefix") == {
        "test": "",
        "test2": "",
    }

    # Test with nested dicts
    data = {"prefix_test": {"prefix_test": ""}}
    assert cleaners.clean_dict_key_prefix(data, "prefix") == {
        "test": {"prefix_test": ""}
    }


def test_clean_dict_key() -> None:
    """Test clean_dict_key method."""

    # Test with empty dict
    data = {}
    assert cleaners.clean_dict_key(data, "test") == {}  # pylint: disable=C1803

    # Test with empty string
    data = {"test": "", "test2": ""}
    assert cleaners.clean_dict_key(data, "test") == {"test2": ""}

    # Test with nested dicts
    data = {"test": {"test": ""}, "test2": {"test": ""}}
    assert cleaners.clean_dict_key(data, "test") == {"test2": {}}