def test_prepare_output_discharging():
    # first battery discharging with 70% and second battery unknown with 0%
    sut = [
        {"state": State.DISCHARGING, 'percentage': 70, 'time': parse_time("01:33:02"),
         'unavailable': False, 'design_capacity': 2010, 'full_capacity': 1658},
        {"state": State.UNKNOWN, 'percentage': 0, 'time': None,
         'unavailable': False, 'design_capacity': 2010, 'full_capacity': 1658},
    ]
    expected = [wrap_span_battery_header(1) + wrap_span_fa(FA_LAPTOP) + ' ' + wrap_span_fa(FA_BATTERY_LIST[3]) + ' ',
                wrap_span_battery_header(2) + wrap_span_fa(FA_QUESTION) + ' ' + wrap_span_fa(FA_BATTERY_LIST[0]) + ' ',
                wrap_span("35%", color(35)),
                wrap_span("(01:33)"),
                ]
    input_list = []
    prepare_output(sut, input_list, [])
    assert input_list == expected, "output is not according to specifications"
Exemple #2
0
def distill_text(battery_text: str,
                 compact: bool = False,
                 show_bug: bool = False) -> Tuple[str, str, int]:
    if battery_text:
        batteries = consolidate_batteries(battery_text)

        full_text = []
        small_text = []
        avg_percentage = prepare_output(batteries,
                                        full_text,
                                        small_text,
                                        compact=compact,
                                        show_bug=show_bug)

        full_text = "".join(full_text)
        small_text = "".join(small_text)

    else:
        # stands for no battery found
        full_text = wrap_span(FA_NO_BATTERY, "red")
        small_text = full_text
        avg_percentage = 100

    if compact:
        return small_text, small_text, avg_percentage
    else:
        return full_text, small_text, avg_percentage
def test_for_remove_of_battery_bug_second_variant():
    # first battery discharging with 70% and second battery unknown with 0%
    sut = [
        {"state": State.UNKNOWN, 'percentage': 6, 'time': None,
         'unavailable': False, 'design_capacity': 1960, 'full_capacity': 1898},
        {"state": State.DISCHARGING, 'percentage': 0, 'time': None,
         'unavailable': True, 'design_capacity': None, 'full_capacity': None},
        {"state": State.CHARGING, 'percentage': 89, 'time': parse_time('00:54:00'),
         'unavailable': False, 'design_capacity': 2010, 'full_capacity': 1658},
    ]
    expected = [wrap_span_battery_header(1) + wrap_span_fa(FA_QUESTION) + ' ' + wrap_span_fa(FA_BATTERY_LIST[0]) + ' ',
                wrap_span_battery_header(2) + wrap_span_fa(FA_PLUG, col='yellow') + ' ' +
                wrap_span_fa(FA_BATTERY_LIST[4]) + ' ',
                wrap_span("47%", color(47)),
                wrap_span("(00:58)")
                ]
    input_list = []
    prepare_output(sut, input_list, [])
    assert input_list == expected, "output is not according to specifications"
def test_prepare_output_charging_small_any_order():
    sut = [
        {"state": State.UNKNOWN, 'percentage': 0, 'time': None,
         'unavailable': False, 'design_capacity': 2010, 'full_capacity': 1658},
        {"state": State.CHARGING, 'percentage': 70, 'time': parse_time("01:33:02"),
         'unavailable': False, 'design_capacity': 2010, 'full_capacity': 1658},
    ]
    expected = [wrap_span_fa(FA_PLUG, "yellow"),
                wrap_span_fa(FA_BATTERY_LIST[1], col=color(35)),
                wrap_span("(01:33)")
                ]
    input_list = []
    prepare_output(sut, [], input_list)
    assert input_list == expected, "output is not according to specifications"
def test_prepare_output_full():
    # first battery Full and second battery unknown with 100%
    sut = [
        {"state": State.FULL, 'percentage': 100, 'time': None,
         'unavailable': False, 'design_capacity': 2010, 'full_capacity': 1658},
        {"state": State.UNKNOWN, 'percentage': 100, 'time': None,
         'unavailable': False, 'design_capacity': 2010, 'full_capacity': 1658},
    ]
    expected = [wrap_span_battery_header(1) + wrap_span_fa(FA_PLUG) + ' ' + wrap_span_fa(FA_BATTERY_LIST[4]) + ' ',
                wrap_span_battery_header(2) + wrap_span_fa(FA_QUESTION) + ' ' + wrap_span_fa(FA_BATTERY_LIST[4]) + ' ',
                wrap_span("100%", color(100)),
                ]
    input_list = []
    prepare_output(sut, input_list, [])
    assert input_list == expected, "output is not according to specifications"
def test_prepare_output_discharging_small_other_order():
    sut = [
        {"state": State.FULL, 'percentage': 100, 'time': None,
         'unavailable': False, 'design_capacity': 2010, 'full_capacity': 1658},
        {"state": State.UNKNOWN, 'percentage': 0, 'time': None,
         'unavailable': False, 'design_capacity': None, 'full_capacity': None},
        {"state": State.DISCHARGING, 'percentage': 70, 'time': parse_time("01:33:02"),
         'unavailable': False, 'design_capacity': 2010, 'full_capacity': 1658},
    ]
    expected = [wrap_span_fa(FA_LAPTOP),
                wrap_span_fa(FA_BATTERY_LIST[4], col=color(85)),
                wrap_span("(03:45)"),
                ]
    input_list = []
    prepare_output(sut, [], input_list)
    assert input_list == expected, "output is not according to specifications"
def test_for_remove_of_battery_bug_with_indicator():
    # first battery discharging with 70% and second battery unknown with 0%
    sut = [
        {"state": State.FULL, 'percentage': 100, 'time': None,
         'unavailable': False, 'design_capacity': 2010, 'full_capacity': 1658},
        {"state": State.UNKNOWN, 'percentage': 0, 'time': None,
         'unavailable': True, 'design_capacity': None, 'full_capacity': None},
        {"state": State.UNKNOWN, 'percentage': 88, 'time': None,
         'unavailable': False, 'design_capacity': 2010, 'full_capacity': 1658},
    ]
    expected = [wrap_span_bug(),
                wrap_span_battery_header(1) + wrap_span_fa(FA_PLUG) + ' ' + wrap_span_fa(FA_BATTERY_LIST[4]) + ' ',
                wrap_span_battery_header(2) + wrap_span_fa(FA_QUESTION) + ' ' + wrap_span_fa(FA_BATTERY_LIST[4]) + ' ',
                wrap_span("94%", color(94)),
                ]
    input_list = []
    prepare_output(sut, input_list, [], show_bug=True)
    assert input_list == expected, "output is not according to specifications"
Exemple #8
0
def prepare_output(batteries: List[Dict[str, Any]],
                   full_text: List[str],
                   small_text: List[str],
                   compact: bool = False,
                   show_bug: bool = False) -> int:
    """
    Each Battery gets its own block, where the state (charging or discharging) and then the image of the battery
    percentage is shown. After all the percentage of the whole System and the charge_discharge_timer (to charge or
    discharge) is put. :param compact: :param show_bug: :param batteries:  a list of battery dictionaries (as
    refine_input returns) :return: the format string
    """
    timer = battery_timer()  # only one battery is showing these information
    nr = 0
    for battery in batteries:
        # battery bug gate
        if is_buggy(battery):
            if show_bug:
                # bug icon in orange as first entry
                span_bug = wrap_span_bug()
                full_text.insert(0, span_bug)
                small_text.insert(0, span_bug)
            continue

        nr += 1
        # pass battery dict to timer object
        timer.set_timer(battery)

        # set full_text
        full_text.append(
            wrap_span_battery_header(nr) + STATUS_SPANS[battery['state']] +
            ' ' + discern_loading_state(battery['percentage']) + ' ')

    system_state = discern_system_states([b['state'] for b in batteries])
    small_text.append(STATUS_SPANS[system_state])

    avg_percentage = timer.calculate_avg_percentage()
    col = color(avg_percentage)
    full_text.append(wrap_span("%s%%" % avg_percentage, col=col))
    small_text.append(discern_loading_state(avg_percentage, color=col))

    # sets the timer if variable is set
    timer.output_timer(full_text=full_text, small_text=small_text)

    return avg_percentage
Exemple #9
0
def test_wrap(text, font, col, weight, expected):
    assert wrap_span(text=text, font=font, col=col, weight=weight) == expected, \
        "String should be wrapped into span element!"
Exemple #10
0
 def output_timer(self, full_text: List[str], small_text: [str]) -> None:
     if self.time_is_set:
         time_span = wrap_span("(%s)" % self.calculate_time())
         full_text.append(time_span)
         small_text.append(time_span)