Exemple #1
0
def test_err_msg(monkeypatch):
    err = StringIO()
    monkeypatch.setattr(sys, 'stderr', err)
    cp = Printer()
    cp.err_msg(_u('error'))
    err.seek(0)
    assert err.read() == _u('\033[31;1merror\033[0m')
Exemple #2
0
def test_conky_err_msg(monkeypatch):
    err = StringIO()
    monkeypatch.setattr(sys, 'stderr', err)
    cp = Printer(conky=True)
    cp.err_msg(_u('error'))
    err.seek(0)
    assert err.read() == _u('${color red}error')
Exemple #3
0
def test_debug_msg(monkeypatch):
    err = StringIO()
    monkeypatch.setattr(sys, 'stderr', err)
    cp = Printer()
    cp.debug_msg(_u('debug'))
    err.seek(0)
    assert err.read() == _u('\033[0;33mdebug\033[0m')
Exemple #4
0
def test_conky_err_msg(monkeypatch):
    err = StringIO()
    monkeypatch.setattr(sys, 'stderr', err)
    cp = Printer(conky=True)
    cp.err_msg(_u('error'))
    err.seek(0)
    assert err.read() == _u('${color red}error${color}')
Exemple #5
0
def test_conky_debug_msg(monkeypatch):
    err = StringIO()
    monkeypatch.setattr(sys, 'stderr', err)
    cp = Printer(conky=True)
    cp.debug_msg(_u('debug'))
    err.seek(0)
    assert err.read() == _u('${color yellow}debug${color}')
Exemple #6
0
def test_conky_debug_msg(monkeypatch):
    err = StringIO()
    monkeypatch.setattr(sys, 'stderr', err)
    cp = Printer(conky=True)
    cp.debug_msg(_u('debug'))
    err.seek(0)
    assert err.read() == _u('${color yellow}debug')
Exemple #7
0
def test_debug_msg(monkeypatch):
    err = StringIO()
    monkeypatch.setattr(sys, 'stderr', err)
    cp = Printer()
    cp.debug_msg(_u('debug'))
    err.seek(0)
    assert err.read() == _u('\033[0;33mdebug\033[0m')
Exemple #8
0
def test_err_msg(monkeypatch):
    err = StringIO()
    monkeypatch.setattr(sys, 'stderr', err)
    cp = Printer()
    cp.err_msg(_u('error'))
    err.seek(0)
    assert err.read() == _u('\033[31;1merror\033[0m')
Exemple #9
0
def test_all_colors():
    """Makes sure the COLOR_NAMES is in sync with the colors in the printer"""
    cp = Printer()
    for color_name in COLOR_NAMES:
        out = StringIO()
        cp.msg(_u('msg'), color_name, file=out)
        out.seek(0)
        assert out.read() == _u(cp.colors[color_name] + 'msg' + '\033[0m')
Exemple #10
0
def test_all_colors():
    """Makes sure the COLOR_NAMES is in sync with the colors in the printer"""
    cp = Printer()
    for color_name in COLOR_NAMES:
        out = StringIO()
        cp.msg(_u('msg'), color_name, file=out)
        out.seek(0)
        assert out.read() == _u(cp.colors[color_name] + 'msg' + '\033[0m')
Exemple #11
0
def test_list(capsys, PatchedGCalI):
    gcal = PatchedGCalI(**vars(get_color_parser().parse_args([])))
    with open(TEST_DATA_DIR + '/cal_list.json') as cl:
        cal_count = len(load(cl)['items'])

    # test data has 6 cals
    assert cal_count == len(gcal.all_cals)
    expected_header = gcal.printer.get_colorcode(
            gcal.options['color_title']) + ' Access  Title\n'

    gcal.ListAllCalendars()
    captured = capsys.readouterr()
    assert captured.out.startswith(_u(expected_header))

    # +3 cos one for the header, one for the '----' decorations,
    # and one for the eom
    assert len(captured.out.split('\n')) == cal_count + 3
Exemple #12
0
def test_list(capsys, PatchedGCalI):
    gcal = PatchedGCalI(**vars(get_color_parser().parse_args([])))
    with open(TEST_DATA_DIR + '/cal_list.json') as cl:
        cal_count = len(load(cl)['items'])

    # test data has 6 cals
    assert cal_count == len(gcal.all_cals)
    expected_header = gcal.printer.get_colorcode(
        gcal.options['color_title']) + ' Access  Title\n'

    gcal.ListAllCalendars()
    captured = capsys.readouterr()
    assert captured.out.startswith(_u(expected_header))

    # +3 cos one for the header, one for the '----' decorations,
    # and one for the eom
    assert len(captured.out.split('\n')) == cal_count + 3
Exemple #13
0
 def msg(self, msg, colorname='default', file=sys.stdout):
     if self.use_color:
         msg = self.colors[colorname] + msg + self.colors['default']
     file.write(_u(msg))
Exemple #14
0
def test_u():
    for text in [b'text', 'text', '\u309f', u'\xe1', b'\xff\xff', 42]:
        if six.PY2:
            assert isinstance(utils._u(text), unicode)  # noqa: F821
        else:
            assert isinstance(utils._u(text), str)
Exemple #15
0
def test_u():
    for text in [b'text', 'text', '\u309f', u'\xe1', b'\xff\xff', 42]:
        if six.PY2:
            assert isinstance(utils._u(text), unicode)  # noqa: F821
        else:
            assert isinstance(utils._u(text), str)
Exemple #16
0
def test_no_color():
    cp = Printer(use_color=False)
    out = StringIO()
    cp.msg(_u('msg'), 'red', file=out)
    out.seek(0)
    assert out.read() == _u('msg')
Exemple #17
0
def main():
    parser = get_argument_parser()
    try:
        argv = sys.argv[1:]
        gcalclirc = os.path.expanduser('~/.gcalclirc')
        if os.path.exists(gcalclirc):
            # We want .gcalclirc to be sourced before any other --flagfile
            # params since we may be told to use a specific config folder, we
            # need to store generated argv in temp variable
            tmp_argv = [
                '@%s' % gcalclirc,
            ] + argv
        else:
            tmp_argv = argv

        (parsed_args, unparsed) = parser.parse_known_args(tmp_argv)
    except Exception as e:
        sys.stderr.write(str(e))
        parser.print_usage()
        sys.exit(1)

    if parsed_args.config_folder:
        if not os.path.exists(os.path.expanduser(parsed_args.config_folder)):
            os.makedirs(os.path.expanduser(parsed_args.config_folder))
        if os.path.exists(
                os.path.expanduser('%s/gcalclirc' %
                                   parsed_args.config_folder)):
            rc_path = [
                '@%s/gcalclirc' % parsed_args.config_folder,
            ]
            if not parsed_args.includeRc:
                tmp_argv = rc_path + argv
            else:
                tmp_argv = rc_path + tmp_argv

        (parsed_args, unparsed) = parser.parse_known_args(tmp_argv)

    printer = Printer(conky=parsed_args.conky,
                      use_color=parsed_args.color,
                      art_style=parsed_args.lineart)

    if unparsed:
        try:
            parsed_args = handle_unparsed(unparsed, parsed_args)
        except Exception as e:
            sys.stderr.write(str(e))
            parser.print_usage()
            sys.exit(1)

    if parsed_args.locale:
        try:
            utils.set_locale(parsed_args.locale)
        except ValueError as exc:
            printer.err_msg(str(exc))

    if len(parsed_args.calendar) == 0:
        parsed_args.calendar = parsed_args.defaultCalendar

    cal_names = parse_cal_names(parsed_args.calendar)
    gcal = GoogleCalendarInterface(cal_names=cal_names,
                                   printer=printer,
                                   **vars(parsed_args))

    try:
        if parsed_args.command == 'list':
            gcal.ListAllCalendars()

        elif parsed_args.command == 'agenda':
            gcal.AgendaQuery(start=parsed_args.start, end=parsed_args.end)

        elif parsed_args.command == 'updates':
            gcal.UpdatesQuery(last_updated_datetime=parsed_args.since,
                              start=parsed_args.start,
                              end=parsed_args.end)

        elif parsed_args.command == 'conflicts':
            gcal.ConflictsQuery(search_text=parsed_args.text,
                                start=parsed_args.start,
                                end=parsed_args.end)

        elif parsed_args.command == 'calw':
            gcal.CalQuery(parsed_args.command,
                          count=parsed_args.weeks,
                          start_text=parsed_args.start)

        elif parsed_args.command == 'calm':
            gcal.CalQuery(parsed_args.command, start_text=parsed_args.start)

        elif parsed_args.command == 'quick':
            if not parsed_args.text:
                printer.err_msg('Error: invalid event text\n')
                sys.exit(1)

            # allow unicode strings for input
            gcal.QuickAddEvent(_u(parsed_args.text),
                               reminders=parsed_args.reminders)

        elif parsed_args.command == 'add':
            if parsed_args.prompt:
                run_add_prompt(parsed_args, printer)

            # calculate "when" time:
            try:
                estart, eend = utils.get_times_from_duration(
                    parsed_args.when, parsed_args.duration, parsed_args.allday)
            except ValueError as exc:
                printer.err_msg(str(exc))
                # Since we actually need a valid start and end time in order to
                # add the event, we cannot proceed.
                raise

            gcal.AddEvent(parsed_args.title, parsed_args.where, estart, eend,
                          parsed_args.description, parsed_args.who,
                          parsed_args.reminders, parsed_args.event_color)

        elif parsed_args.command == 'search':
            gcal.TextQuery(parsed_args.text[0],
                           start=parsed_args.start,
                           end=parsed_args.end)

        elif parsed_args.command == 'delete':
            gcal.ModifyEvents(gcal._delete_event,
                              parsed_args.text[0],
                              start=parsed_args.start,
                              end=parsed_args.end,
                              expert=parsed_args.iamaexpert)

        elif parsed_args.command == 'edit':
            gcal.ModifyEvents(gcal._edit_event,
                              parsed_args.text[0],
                              start=parsed_args.start,
                              end=parsed_args.end)

        elif parsed_args.command == 'remind':
            gcal.Remind(parsed_args.minutes,
                        parsed_args.cmd,
                        use_reminders=parsed_args.use_reminders)

        elif parsed_args.command == 'import':
            gcal.ImportICS(parsed_args.verbose, parsed_args.dump,
                           parsed_args.reminders, parsed_args.file)

    except GcalcliError as exc:
        printer.err_msg(str(exc))
        sys.exit(1)
Exemple #18
0
def test_no_color():
    cp = Printer(use_color=False)
    out = StringIO()
    cp.msg(_u('msg'), 'red', file=out)
    out.seek(0)
    assert out.read() == _u('msg')
Exemple #19
0
def test_conky_red_msg():
    cp = Printer(conky=True)
    out = StringIO()
    cp.msg(_u('msg'), 'red', file=out)
    out.seek(0)
    assert out.read() == _u('${color red}msg${color}')
Exemple #20
0
                   'brightmagenta', 'brightcyan', 'brightwhite'))
ART_CHARS = {
    'fancy': {
        'hrz': '\033(0\x71\033(B',
        'vrt': '\033(0\x78\033(B',
        'lrc': '\033(0\x6A\033(B',
        'urc': '\033(0\x6B\033(B',
        'ulc': '\033(0\x6C\033(B',
        'llc': '\033(0\x6D\033(B',
        'crs': '\033(0\x6E\033(B',
        'lte': '\033(0\x74\033(B',
        'rte': '\033(0\x75\033(B',
        'bte': '\033(0\x76\033(B',
        'ute': '\033(0\x77\033(B'},
    'unicode': {
        'hrz': _u(b'\xe2\x94\x80'),
        'vrt': _u(b'\xe2\x94\x82'),
        'lrc': _u(b'\xe2\x94\x98'),
        'urc': _u(b'\xe2\x94\x90'),
        'ulc': _u(b'\xe2\x94\x8c'),
        'llc': _u(b'\xe2\x94\x94'),
        'crs': _u(b'\xe2\x94\xbc'),
        'lte': _u(b'\xe2\x94\x9c'),
        'rte': _u(b'\xe2\x94\xa4'),
        'bte': _u(b'\xe2\x94\xb4'),
        'ute': _u(b'\xe2\x94\xac')},
    'ascii': {
        'hrz': '-',
        'vrt': '|',
        'lrc': '+',
        'urc': '+',
Exemple #21
0
def test_conky_red_msg():
    cp = Printer(conky=True)
    out = StringIO()
    cp.msg(_u('msg'), 'red', file=out)
    out.seek(0)
    assert out.read() == _u('${color red}msg')
Exemple #22
0
 def msg(self, msg, colorname='default', file=sys.stdout):
     if self.use_color:
         msg = self.colors[colorname] + msg + self.colors['default']
     file.write(_u(msg))
Exemple #23
0
def test_red_msg():
    cp = Printer()
    out = StringIO()
    cp.msg(_u('msg'), 'red', file=out)
    out.seek(0)
    assert out.read() == _u('\033[0;31mmsg\033[0m')
Exemple #24
0
def main():
    parser = get_argument_parser()
    try:
        argv = sys.argv[1:]
        gcalclirc = os.path.expanduser('~/.gcalclirc')
        if os.path.exists(gcalclirc):
            # We want .gcalclirc to be sourced before any other --flagfile
            # params since we may be told to use a specific config folder, we
            # need to store generated argv in temp variable
            tmp_argv = ['@%s' % gcalclirc, ] + argv
        else:
            tmp_argv = argv

        (parsed_args, unparsed) = parser.parse_known_args(tmp_argv)
    except Exception as e:
        sys.stderr.write(str(e))
        parser.print_usage()
        sys.exit(1)

    if parsed_args.config_folder:
        if not os.path.exists(os.path.expanduser(parsed_args.config_folder)):
            os.makedirs(os.path.expanduser(parsed_args.config_folder))
        if os.path.exists(os.path.expanduser('%s/gcalclirc' %
                                             parsed_args.config_folder)):
            rc_path = ['@%s/gcalclirc' % parsed_args.config_folder, ]
            if not parsed_args.includeRc:
                tmp_argv = rc_path + argv
            else:
                tmp_argv = rc_path + tmp_argv

        (parsed_args, unparsed) = parser.parse_known_args(tmp_argv)

    printer = Printer(
            conky=parsed_args.conky, use_color=parsed_args.color,
            art_style=parsed_args.lineart
    )

    if unparsed:
        try:
            parsed_args = handle_unparsed(unparsed, parsed_args)
        except Exception as e:
            sys.stderr.write(str(e))
            parser.print_usage()
            sys.exit(1)

    if parsed_args.locale:
        try:
            utils.set_locale(parsed_args.locale)
        except ValueError as exc:
            printer.err_msg(str(exc))

    if len(parsed_args.calendar) == 0:
        parsed_args.calendar = parsed_args.defaultCalendar

    cal_names = parse_cal_names(parsed_args.calendar)
    gcal = GoogleCalendarInterface(
            cal_names=cal_names, printer=printer, **vars(parsed_args)
    )

    try:
        if parsed_args.command == 'list':
            gcal.ListAllCalendars()

        elif parsed_args.command == 'agenda':
            gcal.AgendaQuery(start=parsed_args.start, end=parsed_args.end)

        elif parsed_args.command == 'calw':
            gcal.CalQuery(
                    parsed_args.command, count=parsed_args.weeks,
                    start_text=parsed_args.start
            )

        elif parsed_args.command == 'calm':
            gcal.CalQuery(parsed_args.command, start_text=parsed_args.start)

        elif parsed_args.command == 'quick':
            if not parsed_args.text:
                printer.err_msg('Error: invalid event text\n')
                sys.exit(1)

            # allow unicode strings for input
            gcal.QuickAddEvent(
                    _u(parsed_args.text), reminders=parsed_args.reminders
            )

        elif parsed_args.command == 'add':
            if parsed_args.prompt:
                run_add_prompt(parsed_args, printer)

            # calculate "when" time:
            try:
                estart, eend = utils.get_times_from_duration(
                        parsed_args.when, parsed_args.duration,
                        parsed_args.allday
                )
            except ValueError as exc:
                printer.err_msg(str(exc))
                # Since we actually need a valid start and end time in order to
                # add the event, we cannot proceed.
                raise

            gcal.AddEvent(parsed_args.title, parsed_args.where, estart, eend,
                          parsed_args.description, parsed_args.who,
                          parsed_args.reminders, parsed_args.event_color)

        elif parsed_args.command == 'search':
            gcal.TextQuery(
                    parsed_args.text[0], start=parsed_args.start,
                    end=parsed_args.end
            )

        elif parsed_args.command == 'delete':
            gcal.ModifyEvents(
                    gcal._delete_event, parsed_args.text[0],
                    start=parsed_args.start, end=parsed_args.end,
                    expert=parsed_args.iamaexpert
            )

        elif parsed_args.command == 'edit':
            gcal.ModifyEvents(
                    gcal._edit_event, parsed_args.text[0],
                    start=parsed_args.start, end=parsed_args.end
            )

        elif parsed_args.command == 'remind':
            gcal.Remind(
                    parsed_args.minutes, parsed_args.cmd,
                    use_reminders=parsed_args.use_reminders
            )

        elif parsed_args.command == 'import':
            gcal.ImportICS(
                    parsed_args.verbose, parsed_args.dump,
                    parsed_args.reminders, parsed_args.file
            )

    except GcalcliError as exc:
        printer.err_msg(str(exc))
        sys.exit(1)
Exemple #25
0
def test_red_msg():
    cp = Printer()
    out = StringIO()
    cp.msg(_u('msg'), 'red', file=out)
    out.seek(0)
    assert out.read() == _u('\033[0;31mmsg\033[0m')
Exemple #26
0
                   'brightmagenta', 'brightcyan', 'brightwhite'))
ART_CHARS = {
    'fancy': {
        'hrz': '\033(0\x71\033(B',
        'vrt': '\033(0\x78\033(B',
        'lrc': '\033(0\x6A\033(B',
        'urc': '\033(0\x6B\033(B',
        'ulc': '\033(0\x6C\033(B',
        'llc': '\033(0\x6D\033(B',
        'crs': '\033(0\x6E\033(B',
        'lte': '\033(0\x74\033(B',
        'rte': '\033(0\x75\033(B',
        'bte': '\033(0\x76\033(B',
        'ute': '\033(0\x77\033(B'},
    'unicode': {
        'hrz': _u(b'\xe2\x94\x80'),
        'vrt': _u(b'\xe2\x94\x82'),
        'lrc': _u(b'\xe2\x94\x98'),
        'urc': _u(b'\xe2\x94\x90'),
        'ulc': _u(b'\xe2\x94\x8c'),
        'llc': _u(b'\xe2\x94\x94'),
        'crs': _u(b'\xe2\x94\xbc'),
        'lte': _u(b'\xe2\x94\x9c'),
        'rte': _u(b'\xe2\x94\xa4'),
        'bte': _u(b'\xe2\x94\xb4'),
        'ute': _u(b'\xe2\x94\xac')},
    'ascii': {
        'hrz': '-',
        'vrt': '|',
        'lrc': '+',
        'urc': '+',