Added testing for some functions and classes

pull/233/head
aristocratos 4 years ago
parent 8041ca1afb
commit 2e31b05e5d

@ -0,0 +1,36 @@
import bpytop
from bpytop import Box, SubBox, CpuBox, MemBox, NetBox, ProcBox, Term
from bpytop import Graph, Fx, Meter, Color, Banner
def test_Fx_uncolor():
assert Fx.uncolor("\x1b[38;2;102;238;142mTEST\x1b[48;2;0;0;0m") == "TEST"
def test_Color():
assert Color.fg("#00ff00") == "\x1b[38;2;0;255;0m"
assert Color.bg("#cc00cc") == "\x1b[48;2;204;0;204m"
assert Color.fg(255, 255, 255) == "\x1b[38;2;255;255;255m"
def test_Theme():
bpytop.THEME = bpytop.Theme("Default")
assert str(bpytop.THEME.main_fg) == "\x1b[38;2;204;204;204m"
assert list(bpytop.THEME.main_fg) == [204, 204, 204]
assert len(bpytop.THEME.gradient["cpu"]) == 101
def test_Box_calc_sizes():
Term.width, Term.height = 80, 25
Box.calc_sizes()
assert CpuBox.width == MemBox.width + ProcBox.width == NetBox.width + ProcBox.width == 80
assert CpuBox.height + ProcBox.height == CpuBox.height + MemBox.height + NetBox.height == 25
def test_Graph():
test_graph = Graph(width=20, height=10, color=None, data=[x for x in range(20)], invert=False, max_value=0, offset=0, color_max_value=None)
assert len(str(test_graph)) == 281
assert str(test_graph).endswith("⣀⣤⣴⣾⣿⣿⣿⣿⣿")
assert test_graph(5).endswith("")
def test_Meter():
test_meter = Meter(value=100, width=20, gradient_name="cpu", invert=False)
assert Fx.uncolor(str(test_meter)) == "■■■■■■■■■■■■■■■■■■■■"
def test_Banner():
assert len(Banner.draw(line=1, col=1, center=False, now=False)) == 2477

@ -0,0 +1,25 @@
import bpytop
from bpytop import get_cpu_name, get_cpu_core_mapping, create_box, floating_humanizer, units_to_bytes
from bpytop import Fx, SYSTEM
def test_get_cpu_name():
assert isinstance(get_cpu_name(), str)
def test_get_cpu_core_mapping():
assert isinstance(get_cpu_core_mapping(), list)
def test_create_box():
assert len(Fx.uncolor(create_box(x=1, y=1, width=10, height=10, title="", title2="", line_color=None, title_color=None, fill=True, box=None))) == 205
def test_floating_humanizer():
assert floating_humanizer(100) == "100 Byte"
assert floating_humanizer(100<<10) == "100 KiB"
assert floating_humanizer(100<<20, bit=True) == "800 Mib"
assert floating_humanizer(100<<20, start=1) == "100 GiB"
assert floating_humanizer(100<<40, short=True) == "100T"
assert floating_humanizer(100<<50, per_second=True) == "100 PiB/s"
def test_units_to_bytes():
assert units_to_bytes("10kbits") == 1280
assert units_to_bytes("100Mbytes") == 104857600
assert units_to_bytes("1gbit") == 134217728
Loading…
Cancel
Save