def test_split_iter(self): lst = [1, 0, 0, 0, 2, 3, 4, 0, 5, 0, 0, 6, 7] self.assertEqual(list(lib.split_iter(lst, lambda x: x == 0, skip_sep=True)), [[1], [2, 3, 4], [5], [6, 7]]) self.assertEqual( list(lib.split_iter(lst, lambda x: x == 0, skip_sep=False)), [[1], [0, 0, 0], [2, 3, 4], [0], [5], [0, 0], [6, 7]], )
def test_split_iter(self): lst = [1, 0, 0, 0, 2, 3, 4, 0, 5, 0, 0, 6, 7] self.assertEqual( list(lib.split_iter(lst, lambda x: x == 0, skip_sep=True)), [[1], [2, 3, 4], [5], [6, 7]]) self.assertEqual( list(lib.split_iter(lst, lambda x: x == 0, skip_sep=False)), [[1], [0, 0, 0], [2, 3, 4], [0], [5], [0, 0], [6, 7]])
def parse_report(filename): """ Read and parse a Radiomobile report.txt file. >>> report = parse_report("report.txt") >>> report.nets >>> report.systems >>> report.units """ lines = open(filename).read().splitlines() splitted_lines = list( lib.split_iter(lines, lambda s: s.startswith("---"), skip_sep=True)) generated_on = parse_header(splitted_lines[0]) sections = dict((lib.keyify(key[0]), val) for (key, val) in lib.grouper(2, splitted_lines[1:])) units = parse_active_units(sections["active_units_information"]) report = lib.Struct("RadioMobileReport", generated_on=generated_on, general_information=sections["general_information"], units=units, systems=parse_systems(sections["systems"]), nets=parse_active_nets( sections["active_nets_information"], units)) return report
def parse_report(filename): """ Read and parse a Radiomobile report.txt file. >>> report = parse_report("report.txt") >>> report.nets >>> report.systems >>> report.units """ lines = open(filename).read().splitlines() splitted_lines = list(lib.split_iter(lines, lambda s: s.startswith("---"), skip_sep=True)) generated_on = parse_header(splitted_lines[0]) sections = dict((lib.keyify(key[0]), val) for (key, val) in lib.grouper(2, splitted_lines[1:])) units = parse_active_units(sections["active_units_information"]) report = lib.Struct("RadioMobileReport", generated_on=generated_on, general_information=sections["general_information"], units=units, systems=parse_systems(sections["systems"]), nets=parse_active_nets(sections["active_nets_information"], units)) return report