Ejemplo n.º 1
0
 def _report_disk_usage_per_field(self, stats):
     collated = collate_disk_usage_stats(stats)
     lines = []
     for index, _total, field in sorted(total_disk_usage_per_field(stats)):
         for stat, value in collated[index][field].items():
             lines.append(
                 self._line(f"{index} {field} {stat}", "", value, convert.bytes_to_human_unit(value), convert.bytes_to_human_value)
             )
     return lines
Ejemplo n.º 2
0
    def _report_disk_usage_stats_per_field(self, baseline_stats,
                                           contender_stats):
        best = {}
        for index, total, field in total_disk_usage_per_field(baseline_stats):
            best.setdefault(index, {})[field] = total
        for index, total, field in total_disk_usage_per_field(contender_stats):
            for_idx = best.setdefault(index, {})
            prev = for_idx.get(field, 0)
            if prev < total:
                for_idx[field] = total
        totals = []
        for index, for_idx in best.items():
            for field, total in for_idx.items():
                totals.append([index, total, field])
        totals.sort()

        collated_baseline = collate_disk_usage_stats(baseline_stats)
        collated_contender = collate_disk_usage_stats(contender_stats)

        lines = []
        for index, _total, field in totals:
            for stat in disk_usage_fields(baseline_stats):
                baseline_value = collated_baseline[index].get(field,
                                                              {}).get(stat, 0)
                contender_value = collated_contender[index].get(field, {}).get(
                    stat, 0)
                if baseline_value == 0 and contender_value == 0:
                    continue
                unit = convert.bytes_to_human_unit(
                    min(baseline_value, contender_value))
                lines.append(
                    self._line(
                        f"{index} {field} {stat}",
                        baseline_value,
                        contender_value,
                        "",
                        unit,
                        treat_increase_as_improvement=False,
                        formatter=partial(convert.bytes_to_unit, unit),
                    ))
        return lines
Ejemplo n.º 3
0
 def test_positive_gb(self):
     assert convert.bytes_to_human_string(8808812123) == "8.2 GB"
     assert convert.bytes_to_human_value(8808812123) == 8.2038455856964
     assert convert.bytes_to_human_unit(8808812123) == "GB"
Ejemplo n.º 4
0
 def test_negative_gb(self):
     assert convert.bytes_to_human_string(-881348666323) == "-820.8 GB"
     assert convert.bytes_to_human_value(
         -881348666323) == -820.8199090538546
     assert convert.bytes_to_human_unit(-881348666323) == "GB"
Ejemplo n.º 5
0
 def test_positive_mb(self):
     assert convert.bytes_to_human_string(8808812) == "8.4 MB"
     assert convert.bytes_to_human_value(8808812) == 8.400737762451172
     assert convert.bytes_to_human_unit(8808812) == "MB"
Ejemplo n.º 6
0
 def test_negative_mb(self):
     assert convert.bytes_to_human_string(-881348666) == "-840.5 MB"
     assert convert.bytes_to_human_value(-881348666) == -840.5195865631104
     assert convert.bytes_to_human_unit(-881348666) == "MB"
Ejemplo n.º 7
0
 def test_negative_kb(self):
     assert convert.bytes_to_human_string(-88134) == "-86.1 kB"
     assert convert.bytes_to_human_value(-88134) == -86.068359375
     assert convert.bytes_to_human_unit(-88134) == "kB"
Ejemplo n.º 8
0
 def test_positive_kb(self):
     assert convert.bytes_to_human_string(8808) == "8.6 kB"
     assert convert.bytes_to_human_value(8808) == 8.6015625
     assert convert.bytes_to_human_unit(8808) == "kB"
Ejemplo n.º 9
0
 def test_negative_bytes(self):
     assert convert.bytes_to_human_string(-100) == "-100 bytes"
     assert convert.bytes_to_human_value(-100) == -100
     assert convert.bytes_to_human_unit(-100) == "bytes"
Ejemplo n.º 10
0
 def test_positive_bytes(self):
     assert convert.bytes_to_human_string(100) == "100 bytes"
     assert convert.bytes_to_human_value(100) == 100
     assert convert.bytes_to_human_unit(100) == "bytes"
Ejemplo n.º 11
0
 def test_none(self):
     assert convert.bytes_to_human_string(None) == "N/A"
     assert convert.bytes_to_human_value(None) is None
     assert convert.bytes_to_human_unit(None) == "N/A"