# Path: px/px_load.py
# def average_to_level(average, peak):
# def averages_to_levels(avg0, avg1, avg2):
# def levels_to_graph(levels):
# def get_load_values():
# def get_load_string(load_values=None):
#     LEFT_BAR = [0x00, 0x40, 0x44, 0x46, 0x47]
#     RIGHT_BAR = [0x00, 0x80, 0xA0, 0xB0, 0xB8]
# 
# Path: px/px_terminal.py
# KEY_ESC = "\x1b"
# KEY_DELETE = "\x1b[3~"
# KEY_BACKSPACE = "\x7f"
# KEY_UPARROW = "\x1b[A"
# KEY_DOWNARROW = "\x1b[B"
# KEY_ENTER = "\x0d"
# CSI = "\x1b["
# CURSOR_TO_TOP_LEFT = CSI + u"H"
# CURSOR_TO_RIGHT_EDGE = CSI + u"999C"  # Actually "999 steps to the right"
# CLEAR_SCREEN = CSI + u"1J" + CURSOR_TO_TOP_LEFT
# HIDE_CURSOR = CSI + u"?25l"
# SHOW_CURSOR = CSI + u"?25h"
# CLEAR_TO_EOL = CSI + u"0K"
# CLEAR_TO_END_OF_SCREEN = CSI + "J"  # Clear from cursor to end of screen
# SIGWINCH_PIPE = os.pipe()
# SIGWINCH_KEY = u"\x00"
# def disable_color():
# def sigwinch_handler(signum, frame):
#     def __init__(self, string):
#     def __len__(self):
#     def consume(self, to_consume):
# def read_select(
#     fds,  # type: List[int]
#     timeout_seconds=None,  # type: Optional[int]
# ):
# def getch(timeout_seconds=None, fd=None):
#     def __init__(self, message):
# def get_window_size():
# def raw_lines_to_screen_lines(raw_lines, columns):
# def filter_out_unchanged_screen_lines(all_screen_lines, columns):
# def draw_screen_lines(lines, columns):
# def width_specifier(width, right_align=False):
# def format_with_widths(widths, strings):
# def to_screen_lines(
#     procs,  # type: List[px_process.PxProcess]
#     row_to_highlight,  # type: Optional[int]
#     highlight_heading,  # type: Optional[text_type]
#     with_username=True,  # type: bool
# ):
# def inverse_video(string):
# def bold(string):
# def faint(string):
# def underline(string):
# def red(string):
# def yellow(string):
# def green(string):
# def blue(string):
# def get_string_of_length(string, length):
# def _tokenize(string):
# def crop_ansi_string_at_length(string, length):
# def visual_length(string):
# def _enter_fullscreen():
# def _exit_fullscreen():
#     def __enter__(self):
#     def __exit__(self, exception_type, exception_value, exception_traceback):
#     def __enter__(self):
#     def __exit__(self, exception_type, exception_value, exception_traceback):
# class ConsumableString(object):
# class TerminalError(Exception):
# class fullscreen_display:
# class normal_display:


from px import px_load
from px import px_terminal
# -*- coding: utf-8 -*-



def test_averages_to_levels():
    l0, l1, l2, peak = px_load.averages_to_levels(0.0, 0.0, 0.0)
    assert (l0, l1, l2, peak) == (0, 0, 0, 1.0)

    # Levels are:
    # 0: 0/6 - 1/6
    # 1: 1/6 - 3/6
    # 2: 3/6 - 5/6
    # 3: 5/6 - 6/6
    l0, l1, l2, peak = px_load.averages_to_levels(
        1.0 / 6.0 - 0.01, 1.0 / 6.0 + 0.01, 1.0
    )
    assert (l0, l1, l2, peak) == (0, 1, 3, 1.0)

    l0, l1, l2, peak = px_load.averages_to_levels(
        5.0 / 6.0 - 0.01, 5.0 / 6.0 + 0.01, 1.0
    )
    assert (l0, l1, l2, peak) == (2, 3, 3, 1.0)


def test_levels_to_graph():
    # Levels 0-3 should be visualized with 1-4 dots. And each character should
    # contain two bars. So this test case wants: "1, 2", "3, 4".

# Path: px/px_load.py
# def average_to_level(average, peak):
# def averages_to_levels(avg0, avg1, avg2):
# def levels_to_graph(levels):
# def get_load_values():
# def get_load_string(load_values=None):
#     LEFT_BAR = [0x00, 0x40, 0x44, 0x46, 0x47]
#     RIGHT_BAR = [0x00, 0x80, 0xA0, 0xB0, 0xB8]
# 
# Path: px/px_terminal.py
# KEY_ESC = "\x1b"
# KEY_DELETE = "\x1b[3~"
# KEY_BACKSPACE = "\x7f"
# KEY_UPARROW = "\x1b[A"
# KEY_DOWNARROW = "\x1b[B"
# KEY_ENTER = "\x0d"
# CSI = "\x1b["
# CURSOR_TO_TOP_LEFT = CSI + u"H"
# CURSOR_TO_RIGHT_EDGE = CSI + u"999C"  # Actually "999 steps to the right"
# CLEAR_SCREEN = CSI + u"1J" + CURSOR_TO_TOP_LEFT
# HIDE_CURSOR = CSI + u"?25l"
# SHOW_CURSOR = CSI + u"?25h"
# CLEAR_TO_EOL = CSI + u"0K"
# CLEAR_TO_END_OF_SCREEN = CSI + "J"  # Clear from cursor to end of screen
# SIGWINCH_PIPE = os.pipe()
# SIGWINCH_KEY = u"\x00"
# def disable_color():
# def sigwinch_handler(signum, frame):
#     def __init__(self, string):
#     def __len__(self):
#     def consume(self, to_consume):
# def read_select(
#     fds,  # type: List[int]
#     timeout_seconds=None,  # type: Optional[int]
# ):
# def getch(timeout_seconds=None, fd=None):
#     def __init__(self, message):
# def get_window_size():
# def raw_lines_to_screen_lines(raw_lines, columns):
# def filter_out_unchanged_screen_lines(all_screen_lines, columns):
# def draw_screen_lines(lines, columns):
# def width_specifier(width, right_align=False):
# def format_with_widths(widths, strings):
# def to_screen_lines(
#     procs,  # type: List[px_process.PxProcess]
#     row_to_highlight,  # type: Optional[int]
#     highlight_heading,  # type: Optional[text_type]
#     with_username=True,  # type: bool
# ):
# def inverse_video(string):
# def bold(string):
# def faint(string):
# def underline(string):
# def red(string):
# def yellow(string):
# def green(string):
# def blue(string):
# def get_string_of_length(string, length):
# def _tokenize(string):
# def crop_ansi_string_at_length(string, length):
# def visual_length(string):
# def _enter_fullscreen():
# def _exit_fullscreen():
#     def __enter__(self):
#     def __exit__(self, exception_type, exception_value, exception_traceback):
#     def __enter__(self):
#     def __exit__(self, exception_type, exception_value, exception_traceback):
# class ConsumableString(object):
# class TerminalError(Exception):
# class fullscreen_display:
# class normal_display:


# Path: tests/px_load_test.py
from px import px_load
from px import px_terminal

# -*- coding: utf-8 -*-



def test_averages_to_levels():
    l0, l1, l2, peak = px_load.averages_to_levels(0.0, 0.0, 0.0)
    assert (l0, l1, l2, peak) == (0, 0, 0, 1.0)

    # Levels are:
    # 0: 0/6 - 1/6
    # 1: 1/6 - 3/6
    # 2: 3/6 - 5/6
    # 3: 5/6 - 6/6
    l0, l1, l2, peak = px_load.averages_to_levels(
        1.0 / 6.0 - 0.01, 1.0 / 6.0 + 0.01, 1.0
    )
    assert (l0, l1, l2, peak) == (0, 1, 3, 1.0)

    l0, l1, l2, peak = px_load.averages_to_levels(
        5.0 / 6.0 - 0.01, 5.0 / 6.0 + 0.01, 1.0
    )
    assert (l0, l1, l2, peak) == (2, 3, 3, 1.0)


def test_levels_to_graph():
    # Levels 0-3 should be visualized with 1-4 dots. And each character should
    # contain two bars. So this test case wants: "1, 2", "3, 4".

    assert px_load.levels_to_graph([0, 1, 2, 3]) == u"⣠⣾"