def test_color_wrap(): text = ("Lorem ipsum \x1b[31mdolor sit amet, consetetur sadipscing " "elitr, sed diam nonumy\x1b[0m eirmod tempor") expected = [ "Lorem ipsum \x1b[31mdolor sit amet,\x1b[0m", "\x1b[31mconsetetur sadipscing elitr, sed\x1b[0m", "\x1b[31mdiam nonumy\x1b[0m eirmod tempor", ] assert utils.color_wrap(text, 35) == expected
def test_color_wrap_256(): text = ( "\x1b[38;2;17;255;0mLorem ipsum dolor sit amet, consetetur sadipscing " "elitr, sed diam nonumy\x1b[0m") expected = [ "\x1b[38;2;17;255;0mLorem ipsum\x1b[0m", "\x1b[38;2;17;255;0mdolor sit amet, consetetur\x1b[0m", "\x1b[38;2;17;255;0msadipscing elitr, sed diam\x1b[0m", "\x1b[38;2;17;255;0mnonumy\x1b[0m" ] assert utils.color_wrap(text, 30) == expected
def test_color_wrap(): text = ( "Lorem ipsum \x1b[31mdolor sit amet, consetetur sadipscing " "elitr, sed diam nonumy\x1b[0m eirmod tempor" ) expected = [ "Lorem ipsum \x1b[31mdolor sit amet,\x1b[0m", "\x1b[31mconsetetur sadipscing elitr, sed\x1b[0m", "\x1b[31mdiam nonumy\x1b[0m eirmod tempor", ] assert utils.color_wrap(text, 35) == expected
def test_color_wrap_256(): text = ( "\x1b[38;2;17;255;0mLorem ipsum dolor sit amet, consetetur sadipscing " "elitr, sed diam nonumy\x1b[0m" ) expected = [ "\x1b[38;2;17;255;0mLorem ipsum\x1b[0m", "\x1b[38;2;17;255;0mdolor sit amet, consetetur\x1b[0m", "\x1b[38;2;17;255;0msadipscing elitr, sed diam\x1b[0m", "\x1b[38;2;17;255;0mnonumy\x1b[0m" ] assert utils.color_wrap(text, 30) == expected
def test_color_wrap_multiple_colors_and_tabs(): text = ( "\x1b[31m14:00-14:50 AST-1002-102 INTRO AST II/STAR GALAX (R) Classes", "15:30-16:45 PHL-2000-104 PHILOSOPHY, SOCIETY & ETHICS (R) Classes", "\x1b[38;2;255;0m17:00-18:00 Pay Ticket Deadline Calendar", "09:30-10:45 PHL-1501-101 MIND, KNOWLEDGE & REALITY (R) Classes", "\x1b[38;2;255;0m11:00-14:00 Rivers Street (noodles and pizza) (R) Calendar", ) expected = [ '\x1b[31m14:00-14:50 AST-1002-102 INTRO AST II/STAR GALAX (R)\x1b[0m', '\x1b[31mClasses\x1b[0m', '15:30-16:45 PHL-2000-104 PHILOSOPHY, SOCIETY & ETHICS (R)', 'Classes', '\x1b[38;2;255;0m17:00-18:00 Pay Ticket Deadline Calendar\x1b[0m', '09:30-10:45 PHL-1501-101 MIND, KNOWLEDGE & REALITY (R)', 'Classes', '\x1b[38;2;255;0m11:00-14:00 Rivers Street (noodles and\x1b[0m', '\x1b[38;2;255;0mpizza) (R) Calendar\x1b[0m' ] actual = [] for line in text: actual += utils.color_wrap(line, 60) assert actual == expected
def get_events_between(collection, locale, start, end, agenda_format=None, notstarted=False, env=None, width=None, seen=None, original_start=None): """returns a list of events scheduled between start and end. Start and end are strings or datetimes (of some kind). :param collection: :type collection: khalendar.CalendarCollection :param start: the start datetime :param end: the end datetime :param agenda_format: a format string that can be used in python string formatting :type agenda_format: str :param env: a collection of "static" values like calendar names and color :type env: dict :param nostarted: True if each event should start after start (instead of be active between start and end) :type nostarted: bool :param original_start: start datetime to compare against of notstarted is set :type original_start: datetime.datetime :returns: a list to be printed as the agenda for the given days :rtype: list(str) """ assert not (notstarted and not original_start) event_list = [] if env is None: env = {} assert start assert end start_local = locale['local_timezone'].localize(start) end_local = locale['local_timezone'].localize(end) start = start_local.replace(tzinfo=None) end = end_local.replace(tzinfo=None) events = sorted(collection.get_localized(start_local, end_local)) events_float = sorted(collection.get_floating(start, end)) events = sorted(events + events_float) for event in events: # yes the logic could be simplified, but I believe it's easier # to understand what's going on here this way if notstarted: if event.allday and event.start < original_start.date(): continue elif not event.allday and event.start_local < original_start: continue if seen is not None and event.uid in seen: continue try: event_string = event.format(agenda_format, relative_to=(start, end), env=env) except KeyError as error: raise FatalError(error) if width: event_list += utils.color_wrap(event_string, width) else: event_list.append(event_string) if seen is not None: seen.add(event.uid) return event_list