Пример #1
0
def test_horizontal():
    """Test basic horizontal output."""
    expected = (
        "\n"
        "████████\n"
        "████████████████\n"
        "███████████████████████\n"
        "███████████████████████████████\n"
        "███████████████████████████████████████\n"
        "███████████████████████████████████████████████\n"
        "███████████████████████████████████████████████████████\n"
        "██████████████████████████████████████████████████████████████\n"
        "██████████████████████████████████████████████████████████████████████\n"  # noqa: E501
        "██████████████████████████████████████████████████████████████████████████████\n"  # noqa: E501
    )
    test_values = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
    width = 79

    # Note we force a width here so it doesn't change based on terminal size
    grph = textgraph.horizontal(test_values, width=width)
    print("-Graph")
    print(grph)
    print("-Expected")
    print(expected)
    print("-")
    assert grph == expected
Пример #2
0
def test_horizontal_labels_ordereddict():
    """Test labeled horizontal output."""
    expected = (
        "Test0  \n"
        "T1     ████████\n"
        "Test2  ████████████████\n"
        "Test3  ███████████████████████\n"
        "Test4  ███████████████████████████████\n"
        "Test5  ███████████████████████████████████████\n"
        "Test6  ███████████████████████████████████████████████\n"
        "Test7  ███████████████████████████████████████████████████████\n"
        "Test8  ██████████████████████████████████████████████████████████████\n"  # noqa: E501
        "Test9  ██████████████████████████████████████████████████████████████████████\n"  # noqa: E501
        "Test10 ██████████████████████████████████████████████████████████████████████████████\n"  # noqa: E501
    )
    test_values = collections.OrderedDict([('Test0', 0), ('T1', 1),
                                           ('Test2', 2), ('Test3', 3),
                                           ('Test4', 4), ('Test5', 5),
                                           ('Test6', 6), ('Test7', 7),
                                           ('Test8', 8), ('Test9', 9),
                                           ('Test10', 10)])
    width = 79

    # Note we force a width here so it doesn't change based on terminal size
    grph = textgraph.horizontal(test_values, width=width)
    print("-Graph")
    print(grph)
    print("-Expected")
    print(expected)
    print("-")
    assert grph == expected
Пример #3
0
def test_horizontal_width():
    """Test different width horizontal output."""
    expected = ("\n"
                "██\n"
                "████\n"
                "██████\n"
                "████████\n"
                "██████████\n"
                "███████████\n"
                "█████████████\n"
                "███████████████\n"
                "█████████████████\n"
                "███████████████████\n")
    test_values = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
    width = 20

    grph = textgraph.horizontal(test_values, width=width)
    print("-Graph")
    print(grph)
    print("-Expected")
    print(expected)
    print("-")
    assert grph == expected
Пример #4
0
def test_horizontal_character():
    """Test horizontal character."""
    expected = ("\n"
                "◍◍\n"
                "◍◍◍◍\n"
                "◍◍◍◍◍◍\n"
                "◍◍◍◍◍◍◍◍\n"
                "◍◍◍◍◍◍◍◍◍◍\n"
                "◍◍◍◍◍◍◍◍◍◍◍\n"
                "◍◍◍◍◍◍◍◍◍◍◍◍◍\n"
                "◍◍◍◍◍◍◍◍◍◍◍◍◍◍◍\n"
                "◍◍◍◍◍◍◍◍◍◍◍◍◍◍◍◍◍\n"
                "◍◍◍◍◍◍◍◍◍◍◍◍◍◍◍◍◍◍◍\n")
    test_values = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
    width = 20
    character = '◍'

    grph = textgraph.horizontal(test_values, width=width, character=character)
    print("-Graph")
    print(grph)
    print("-Expected")
    print(expected)
    print("-")
    assert grph == expected
Пример #5
0
#!/usr/bin/env python3
"""Example Usages of textgraph."""

import textgraph

EXAMPLE_DATA = [12, 34, 45, 5, 16, 20]
EXAMPLE_DATA_LABELLED = [('T1', 12), ('Test2', 34), ('Test3', 45),
                         ('Test4', 5), ('Test5', 16), ('Test6', 20)]
EXAMPLE_WIDTH = 20
EXAMPLE_HEIGHT = 30

# Spark Graph
print("Spark")
print(textgraph.spark(EXAMPLE_DATA))

# Horizontal Graph
print("Horizontal Graph")
print(textgraph.horizontal(EXAMPLE_DATA))
print("Horizontal Graph with Labels, Width {}".format(EXAMPLE_WIDTH))
print(textgraph.horizontal(EXAMPLE_DATA_LABELLED, width=EXAMPLE_WIDTH))

# Vertical Graph
print("Vertical Graph")
print(textgraph.vertical(EXAMPLE_DATA))
print("Vertical Graph, Height {}".format(EXAMPLE_HEIGHT))
print(textgraph.vertical(EXAMPLE_DATA, height=EXAMPLE_HEIGHT))