Exemple #1
0
def test_format_dict_node_template():
    """Test dict node formatting"""
    dummy_dict_with_leafs = {1: {2: {}}, 2: {}, 3: {1: {4: 3}, 2: {}}}
    lines = format_dict(dummy_dict_with_leafs).split("\n")
    assert len(lines) == 7
    assert lines[0] == "1:"
    #   2
    # 2
    assert lines[3] == "3:"
    assert lines[4].lstrip(" ") == "1:"
Exemple #2
0
def test_format_dict_leaf_template():
    """Test dict leaf node formatting"""
    dummy_dict_with_leafs = {1: {2: {}}, 2: {}, 3: {1: 3, 2: {}}}
    lines = format_dict(dummy_dict_with_leafs).split("\n")
    assert len(lines) == 6
    # 1:
    #   2
    # 2
    # 3:
    assert lines[4].lstrip(" ") == "1: 3"
Exemple #3
0
def test_format_dict_empty_leaf_template():
    """Test dict empty leaf node formatting"""
    dummy_dict_with_leafs = {1: {2: {}}, 2: {}, 3: {1: 3, 2: {}}}
    lines = format_dict(dummy_dict_with_leafs).split("\n")
    assert len(lines) == 6
    # 1:
    assert lines[1].lstrip(" ") == "2"
    assert lines[2].lstrip(" ") == "2"
    # 3:
    #   1: 3
    assert lines[5].lstrip(" ") == "2"
Exemple #4
0
def test_format_dict_leaf_template_custom():
    """Test dict leaf node formatting with custom template"""
    template = "value of {key} is {value}\n"
    dummy_dict_with_leafs = {1: {2: {}}, 2: {}, 3: {1: 3, 2: {}}}
    lines = format_dict(dummy_dict_with_leafs, templates={
        "leaf": template
    }).split("\n")
    assert len(lines) == 6
    # 1:
    #   2
    # 2
    # 3:
    assert lines[4] == "value of 1 is 3"
Exemple #5
0
def test_format_dict_node_template_custom():
    """Test dict formatting with custom node template"""
    template = "{key} is a dict:\n{value}\n"
    dummy_dict_with_leafs = {1: {2: {}}, 2: {}, 3: {1: {4: 3}, 2: {}}}
    lines = format_dict(dummy_dict_with_leafs,
                        templates={
                            "dict_node": template
                        }).split("\n")
    assert len(lines) == 7
    assert lines[0] == "1 is a dict:"
    #   2
    # 2
    assert lines[3] == "3 is a dict:"
    assert lines[4] == "1 is a dict:"
Exemple #6
0
def test_format_dict_width_full(width, dummy_dict):
    """Test dict formatting with different widths for all lines"""
    tab = " " * width
    lines = format_dict(dummy_dict, width=width).split("\n")
    assert len(lines) == 9
    assert lines[0].startswith("1")
    assert lines[1].startswith(tab + "1")
    assert lines[2].startswith(tab + "1")
    assert lines[3].startswith((tab * 2) + "1")
    assert lines[4].startswith((tab * 2) + "1")
    assert lines[5].startswith("2")
    assert lines[6].startswith(tab + "2")
    assert lines[7].startswith(tab + "2")
    assert lines[8].startswith("3")
Exemple #7
0
def test_format_dict_empty_leaf_template_custom():
    """Test dict empty leaf node formatting with custom template"""
    template = "{key} is a leaf\n"
    dummy_dict_with_leafs = {1: {2: {}}, 2: {}, 3: {1: 3, 2: {}}}
    lines = format_dict(dummy_dict_with_leafs,
                        templates={
                            "empty_leaf": template
                        }).split("\n")
    assert len(lines) == 6
    # 1:
    assert lines[1] == "2 is a leaf"
    assert lines[2] == "2 is a leaf"
    # 3:
    #   1: 3
    assert lines[5] == "2 is a leaf"
Exemple #8
0
def test_format_dict_depth_full(dummy_dict):
    """Test dict depth formatting for all lines"""
    WIDTH = 4
    tab = " " * WIDTH

    lines = format_dict(dummy_dict).split("\n")
    assert len(lines) == 9
    assert lines[0].startswith("1")
    assert lines[1].startswith(tab + "1")
    assert lines[2].startswith(tab + "1")
    assert lines[3].startswith((tab * 2) + "1")
    assert lines[4].startswith((tab * 2) + "1")
    assert lines[5].startswith("2")
    assert lines[6].startswith(tab + "2")
    assert lines[7].startswith(tab + "2")
    assert lines[8].startswith("3")
Exemple #9
0
def test_format_dict_with_list(dummy_list_of_objects):
    """Test dict formatting with embedded lists"""
    assert (format_dict(dummy_list_of_objects) == """\
[
    1:
        1.1: 1.1.1
        1.2:
            [
                1.2.1
                1.2.2
            ]
    [
        4
        5
    ]
    2:
        2.1: 2.1.1
        2.2
    3
]\
""")
Exemple #10
0
def test_format_dict_width_synthetic(width, depth, dummy_dict):
    """Test dict formatting with different combination of widths and depth for one line"""
    tab = (" " * width) * depth
    assert (format_dict(dummy_dict, depth=depth,
                        width=width).split("\n")[0].startswith(tab + "1"))
Exemple #11
0
def test_format_dict_depth_synthetic(depth, dummy_dict):
    """Test dict formatting with different depths for one line"""
    WIDTH = 4
    tab = (" " * WIDTH) * depth
    assert (format_dict(dummy_dict, depth=depth,
                        width=WIDTH).split("\n")[0].startswith(tab + "1"))
Exemple #12
0
def test_format_dict_with_list(dummy_list_of_objects):
    """Test dict formatting with embedded lists"""
    assert format_dict(dummy_list_of_objects) == """\