diff --git a/tests/runner_1.py b/tests/runner_1.py new file mode 100755 index 0000000..c40332e --- /dev/null +++ b/tests/runner_1.py @@ -0,0 +1,86 @@ +#!/usr/bin/env python3 + + +from dashing import ( + ColorRangeVGauge, + HBrailleChart, + HChart, + HGauge, + HSplit, + Log, + Text, + VChart, + VGauge, + VSplit, +) + + +import math + + +def main(): + ui = HSplit( + VSplit( + HGauge(val=50, title="only title", border_color=5), + HGauge(label="only label", val=20, border_color=5), + HGauge(label="only label", val=30, border_color=5), + HGauge(label="only label", val=50, border_color=5), + HGauge(label="only label", val=80, border_color=5), + HGauge(val=20), + HGauge(label="label, no border", val=55), + HSplit( + VGauge(val=0, border_color=2), + VGauge(val=5, border_color=2), + VGauge(val=30, border_color=2), + VGauge(val=50, border_color=2), + VGauge(val=80, border_color=2, color=4), + VGauge(val=95, border_color=2, color=3), + ColorRangeVGauge( + val=100, + border_color=2, + colormap=( + (33, 2), + (66, 3), + (100, 1), + ), + ), + ), + ), + VSplit( + Text("Hello World,\nthis is dashing.", border_color=2), + Log(title="logs", border_color=5), + VChart(border_color=2, color=2), + HChart(border_color=2, color=2), + HBrailleChart(border_color=2, color=2), + # HBrailleFilledChart(border_color=2, color=2), + ), + title="Dashing test run", + ) + log = ui.items[1].items[1] + vchart = ui.items[1].items[2] + hchart = ui.items[1].items[3] + bchart = ui.items[1].items[4] + # bfchart = ui.items[1].items[5] + log.append("0 -----") + log.append("1 Hello") + log.append("2 -----") + + cycle = 0 + ui.items[0].items[0].value = int(50 + 49.9 * math.sin(cycle / 80.0)) + ui.items[0].items[1].value = int(50 + 45 * math.sin(cycle / 20.0)) + ui.items[0].items[2].value = int(50 + 45 * math.sin(cycle / 30.0 + 3)) + + vgauges = ui.items[0].items[-1].items + for gaugenum, vg in enumerate(vgauges): + vg.value = 50 + 49.9 * math.sin(cycle / 12.0 + gaugenum) + + vchart.append(50 + 50 * math.sin(cycle / 16.0)) + hchart.append(99.9 * abs(math.sin(cycle / 26.0))) + bchart.append(50 + 50 * math.sin(cycle / 6.0)) + # bfchart.append(50 + 50 * math.sin(cycle / 16.0)) + + ui.display() + + +if __name__ == "__main__": + main() diff --git a/tests/test_integ.py b/tests/test_integ.py new file mode 100644 index 0000000..fe02ced --- /dev/null +++ b/tests/test_integ.py @@ -0,0 +1,240 @@ +# Integration tests for dashing +# +# Some tests are explicitly checking for broken outputs in order to spot unexpected changes +# +# debdeps: python3-pexpect python3-pyte python3-pytest + +from __future__ import unicode_literals + +import pyte +import pexpect + + +def run(w, h, path): + screen = pyte.Screen(w, h) + stream = pyte.ByteStream(screen) + child = pexpect.spawn(path, dimensions=(h, w)) + child.expect(pexpect.EOF) + stream.feed(child.before) + out = screen.display + child.terminate() + return out + + +def check(out, exp): + exp = [x.rstrip() for x in exp.splitlines()] + out = [x.rstrip() for x in out] + len_ok = len(out) == len(exp) + + if exp != out: + print("-- out --") + for line in out: + print(line.rstrip()) + print("-- end out --") + + assert len_ok, f"Number of lines in output: {len(out)} != expected: {len(exp)}" + assert out == exp + + +def test_basic_80_30(): + out = run(80, 30, "./tests/runner_1.py") + exp = """\ + Dashing test run +┌ only title ─────────────────────────┐┌─────────────────────────────────────┐ +│▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▌▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏││Hello World, │ +└─────────────────────────────────────┘│this is dashing. │ +┌─────────────────────────────────────┐│ │ +│only label ▉▉▉▉▉▉▉▉▉▉▉▉▏▏▏▏▏▏▏▏▏▏▏▏▏▏│└─────────────────────────────────────┘ +└─────────────────────────────────────┘┌ logs ───────────────────────────────┐ +┌─────────────────────────────────────┐│0 ----- │ +│only label ▉▉▉▉▉▉▉▉▉▉▉▉▉▌▏▏▏▏▏▏▏▏▏▏▏▏││1 Hello │ +└─────────────────────────────────────┘│2 ----- │ +┌─────────────────────────────────────┐└─────────────────────────────────────┘ +│only label ▉▉▉▉▉▉▉▉▉▉▉▉▏▏▏▏▏▏▏▏▏▏▏▏▏▏│┌─────────────────────────────────────┐ +└─────────────────────────────────────┘│ │ +┌─────────────────────────────────────┐│ │ +│only label ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▎▏▏▏▏▏▏││ │ +└─────────────────────────────────────┘└─────────────────────────────────────┘ +▉▉▉▉▉▉▉▊▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏┌─────────────────────────────────────┐ +▉▉▉▉▉▉▉▊▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏│ │ +▉▉▉▉▉▉▉▊▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏│ │ + ▉▉▉▉▉▉▉▉▉▉▉▏▏▏▏▏▏▏▏▏▏▏│ │ +label, no border ▉▉▉▉▉▉▉▉▉▉▉▏▏▏▏▏▏▏▏▏▏▏└─────────────────────────────────────┘ + ▉▉▉▉▉▉▉▉▉▉▉▏▏▏▏▏▏▏▏▏▏▏┌─────────────────────────────────────┐ +┌───┐┌───┐┌───┐┌───┐┌───┐┌───┐┌───┐ │ │ +│▄▄▄││███││███││▅▅▅││▁▁▁││▁▁▁││▃▃▃│ │ │ +└───┘└───┘└───┘└───┘└───┘└───┘└───┘ │ │ + └─────────────────────────────────────┘ + + + + """ + check(out, exp) + + +def test_basic_80_20(): + out = run(80, 20, "./tests/runner_1.py") + exp = """\ + Dashing test run +┌ only title ─────────────────────────┐┌─────────────────────────────────────┐ +└─────────────────────────────────────┘│this is dashing. │ +┌─────────────────────────────────────┐└─────────────────────────────────────┘ +└─────────────────────────────────────┘┌ logs ───────────────────────────────┐ +┌─────────────────────────────────────┐│2 ----- │ +└─────────────────────────────────────┘└─────────────────────────────────────┘ +┌─────────────────────────────────────┐┌─────────────────────────────────────┐ +└─────────────────────────────────────┘│ │ +┌─────────────────────────────────────┐└─────────────────────────────────────┘ +└─────────────────────────────────────┘┌─────────────────────────────────────┐ +▉▉▉▉▉▉▉▊▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏│ │ +▉▉▉▉▉▉▉▊▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏└─────────────────────────────────────┘ + ▉▉▉▉▉▉▉▉▉▉▉▏▏▏▏▏▏▏▏▏▏▏┌─────────────────────────────────────┐ +label, no border ▉▉▉▉▉▉▉▉▉▉▉▏▏▏▏▏▏▏▏▏▏▏│ │ +┌───┐┌───┐┌───┐┌───┐┌───┐┌───┐┌───┐ └─────────────────────────────────────┘ +└───┘└───┘└───┘└───┘└───┘└───┘└───┘ + + + """ + check(out, exp) + + +def test_basic_100_50(): + out = run(100, 50, "./tests/runner_1.py") + exp = """\ + Dashing test run +┌ only title ───────────────────────────────────┐┌───────────────────────────────────────────────┐ +│▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▌▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏││Hello World, │ +│▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▌▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏││this is dashing. │ +│▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▌▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏││ │ +│▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▌▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏││ │ +└───────────────────────────────────────────────┘│ │ +┌───────────────────────────────────────────────┐│ │ +│ ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏││ │ +│ ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏│└───────────────────────────────────────────────┘ +│only label ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏│┌─ logs ──────────────────────────────────────┐ +│ ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏││0 ----- │ +└───────────────────────────────────────────────┘│1 Hello │ +┌───────────────────────────────────────────────┐│2 ----- │ +│ ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏││ │ +│ ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏││ │ +│only label ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏││ │ +│ ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏││ │ +└───────────────────────────────────────────────┘└───────────────────────────────────────────────┘ +┌───────────────────────────────────────────────┐┌───────────────────────────────────────────────┐ +│ ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏││ │ +│ ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏││ │ +│only label ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏││ │ +│ ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏││ │ +└───────────────────────────────────────────────┘│ │ +┌───────────────────────────────────────────────┐│ │ +│ ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▎▏▏▏▏▏▏▏▏││ │ +│ ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▎▏▏▏▏▏▏▏▏│└───────────────────────────────────────────────┘ +│only label ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▎▏▏▏▏▏▏▏▏│┌───────────────────────────────────────────────┐ +│ ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▎▏▏▏▏▏▏▏▏││ │ +└───────────────────────────────────────────────┘│ │ +▉▉▉▉▉▉▉▉▉▊▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏│ │ +▉▉▉▉▉▉▉▉▉▊▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏│ │ +▉▉▉▉▉▉▉▉▉▊▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏│ │ +▉▉▉▉▉▉▉▉▉▊▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏│ │ +▉▉▉▉▉▉▉▉▉▊▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏│ │ +▉▉▉▉▉▉▉▉▉▊▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏└───────────────────────────────────────────────┘ + ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▌▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏┌───────────────────────────────────────────────┐ + ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▌▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏│ │ + ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▌▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏│ │ +label, no border ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▌▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏│ │ + ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▌▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏│ │ + ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▌▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏│ │ +┌─────┐┌─────┐┌─────┐┌─────┐┌─────┐┌─────┐┌─────┐│ │ +│ ││▆▆▆▆▆││▇▇▇▇▇││ ││ ││ ││ ││ │ +│ ││█████││█████││▃▃▃▃▃││ ││ ││ │└───────────────────────────────────────────────┘ +│█████││█████││█████││█████││ ││ ││▄▄▄▄▄│ +│█████││█████││█████││█████││▄▄▄▄▄││▁▁▁▁▁││█████│ +└─────┘└─────┘└─────┘└─────┘└─────┘└─────┘└─────┘ + """ + check(out, exp) + + +def test_basic_30_30(): + # FIXME: fix "this is dashing" + out = run(30, 30, "./tests/runner_1.py") + exp = """\ +Dashing test run +┌only title──┐┌────────────┐ +│▉▉▉▉▉▉▏▏▏▏▏▏││Hello World,│ +└────────────┘│this is dashing +.────────────┐│ │ +│only label ▋│└────────────┘ +└────────────┘┌logs────────┐ +┌────────────┐│0 ----- │ +│only label ▋││1 Hello │ +└────────────┘│2 ----- │ +┌────────────┐└────────────┘ +│only label ▋│┌────────────┐ +└────────────┘│ │ +┌────────────┐│ │ +│only label ▍││ │ +└────────────┘└────────────┘ +▉▉▊▏▏▏▏▏▏▏▏▏▏▏┌────────────┐ +▉▉▊▏▏▏▏▏▏▏▏▏▏▏│ │ +▉▉▊▏▏▏▏▏▏▏▏▏▏▏│ │ + │ │ +label, no bord└────────────┘ + ┌────────────┐ +┌┐┌┐┌┐┌┐┌┐┌┐┌┐│ │ +│││││││││││││││ │ +└┘└┘└┘└┘└┘└┘└┘│ │ + └────────────┘ + + + + """ + check(out, exp) + + +def test_basic_80_18(): + # FIXME: broken alignment + out = run(80, 18, "./tests/runner_1.py") + exp = """\ +┌─────────────────────────────────────┐ +└─────────────────────────────────────┘┌─────────────────────────────────────┐ +┌─────────────────────────────────────┐│this is dashing. │ +└─────────────────────────────────────┘└─────────────────────────────────────┘ +▉▉▉▉▉▉▉▊▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏┌ logs ───────────────────────────────┐ +▉▉▉▉▉▉▉▊▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏│2 ----- │ + ▉▉▉▉▉▉▉▉▉▉▉▏▏▏▏▏▏▏▏▏▏▏└─────────────────────────────────────┘ +label, no border ▉▉▉▉▉▉▉▉▉▉▉▏▏▏▏▏▏▏▏▏▏▏┌─────────────────────────────────────┐ +┌───┐ │ │ +└───┘┌───┐ └─────────────────────────────────────┘ + └───┘┌───┐ ┌─────────────────────────────────────┐ + └───┘┌───┐ │ │ + └───┘┌───┐ └─────────────────────────────────────┘ + └───┘┌───┐ ┌─────────────────────────────────────┐ + └───┘┌───┐ │ │ + └───┘ └─────────────────────────────────────┘ + + """ + check(out, exp) + + +def test_basic_80_17(): + # FIXME: broken + out = run(80, 17, "./tests/runner_1.py") + exp = """\ + Dashing test run +┌ only title ─────────────────────────┐┌─────────────────────────────────────┐ +┌─────────────────────────────────────┐│this is dashing. │ +┌─────────────────────────────────────┐└─────────────────────────────────────┘ +┌─────────────────────────────────────┐┌ logs ───────────────────────────────┐ +┌─────────────────────────────────────┐│2 ----- │ +▉▉▉▉▉▉▉▊▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏▏└─────────────────────────────────────┘ +label, no border ▉▉▉▉▉▉▉▉▉▉▉▏▏▏▏▏▏▏▏▏▏▏┌─────────────────────────────────────┐ +┌───┐┌───┐┌───┐┌───┐┌───┐┌───┐┌───┐ │ │ + └─────────────────────────────────────┘ + ┌─────────────────────────────────────┐ + │ │ + └─────────────────────────────────────┘ + ┌─────────────────────────────────────┐ + │ │ + └─────────────────────────────────────┘ + """ + check(out, exp)