PyTest

Modules:

Name Description
conftest

Pytest top-level conftest.py.

test_pyobjson

Pytest test for Python Object JSON Tool code.

conftest

Pytest top-level conftest.py.

Classes:

Name Description
ChildChildClass

ChildChildClass for testing.

ChildClass

ChildClass for testing.

ParentClass

ParentClass for testing.

Functions:

Name Description
parent_class_with_nested_child_classes

Create ParentClass instance for testing.

parent_class_json_str

Create JSON string from ParentClass instance for testing.

ChildChildClass

Bases: PythonObjectJson

ChildChildClass for testing.

Source code in tests/conftest.py
21
22
23
24
25
26
27
class ChildChildClass(PythonObjectJson):
    """ChildChildClass for testing.
    """

    def __init__(self, child_child_class_param: str):
        super().__init__()
        self.child_child_class_param: str = child_child_class_param

ChildClass

Bases: PythonObjectJson

ChildClass for testing.

Source code in tests/conftest.py
30
31
32
33
34
35
36
class ChildClass(PythonObjectJson):
    """ChildClass for testing.
    """

    def __init__(self, child_child_class_list: List[ChildChildClass]):
        super().__init__()
        self.child_child_class_list: List[ChildChildClass] = child_child_class_list

ParentClass

Bases: PythonObjectJson

ParentClass for testing.

Source code in tests/conftest.py
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
class ParentClass(PythonObjectJson):
    """ParentClass for testing.
    """

    def __init__(self, child_class_dict: Dict[str, ChildClass], child_class_list: List[ChildClass],
                 parent_class_set: Optional[Set[str]], parent_class_tuple: Optional[Tuple[str]],
                 parent_class_file: Optional[Path], parent_class_external_function: Optional[Callable],
                 parent_class_datetime: Optional[datetime]):
        super().__init__()
        self.child_class_dict: Dict[str, ChildClass] = child_class_dict
        self.child_class_list: List[ChildClass] = child_class_list
        self.parent_class_set: Set[str] = parent_class_set
        self.parent_class_tuple: Tuple[str] = parent_class_tuple
        self.parent_class_file: Path = parent_class_file
        self.parent_class_external_function: Optional[Callable] = parent_class_external_function
        self.parent_class_datetime: datetime = parent_class_datetime

parent_class_with_nested_child_classes

parent_class_with_nested_child_classes()

Create ParentClass instance for testing.

Returns:
  • ParentClass( ParentClass ) –

    Instance of ParentClass.

Source code in tests/conftest.py
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
@fixture(scope="module")
def parent_class_with_nested_child_classes() -> ParentClass:
    """Create ParentClass instance for testing.

    Returns:
        ParentClass: Instance of ParentClass.
    """
    return ParentClass(
        {"child_class_1": ChildClass([ChildChildClass("test_child_child_class_argument_in_dict")])},
        [ChildClass([ChildChildClass("test_child_child_class_argument_in_list")])],
        {"test_parent_class_collection_element"},
        ("test_parent_class_collection_element",),
        Path(__name__),
        external_function,
        datetime(2024, 1, 1, 0, 0, 0)
    )

parent_class_json_str

parent_class_json_str()

Create JSON string from ParentClass instance for testing.

Returns:
  • str( str ) –

    JSON string derived from serialized ParentClass instance.

Source code in tests/conftest.py
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
@fixture(scope="module")
def parent_class_json_str() -> str:
    """Create JSON string from ParentClass instance for testing.

    Returns:
        str: JSON string derived from serialized ParentClass instance.

    """
    return json.dumps(
        {
            "conftest.parentclass": {
                "collection:dict.child_class_dict": {
                    "child_class_1": {
                        "conftest.childclass": {
                            "collection:list.child_child_class_list": [
                                {
                                    "conftest.childchildclass": {
                                        "child_child_class_param": "test_child_child_class_argument_in_dict"
                                    }
                                }
                            ]
                        }
                    }
                },
                "collection:list.child_class_list": [
                    {
                        "conftest.childclass": {
                            "collection:list.child_child_class_list": [
                                {
                                    "conftest.childchildclass": {
                                        "child_child_class_param": "test_child_child_class_argument_in_list"
                                    }
                                }
                            ]
                        }
                    }
                ],
                "collection:set.parent_class_set": [
                    "test_parent_class_collection_element"
                ],
                "collection:tuple.parent_class_tuple": [
                    "test_parent_class_collection_element"
                ],
                "path.parent_class_file": "conftest",
                "callable.parent_class_external_function": (
                    "conftest.external_function::param1:str,param2:str"
                ),
                "datetime.parent_class_datetime": "2024-01-01T00:00:00"
            }
        },
        ensure_ascii=False,
        indent=2
    )

test_pyobjson

Pytest test for Python Object JSON Tool code.

Note

Tests pyobjson.base module.