Esempio n. 1
0
 def g(expect_regexp, *args):
     with self.assertRaises(ValueError) as cm:
         Setting._parse_time_range(*args, now=now)
     if six.PY2:
         self.assertRegexpMatches(cm.exception.message, expect_regexp)
     else:
         self.assertRegex(str(cm.exception), expect_regexp)
Esempio n. 2
0
def main():
    """
    Main function
    """

    setting = None
    try:
        setting = Setting().parse_args(sys.argv)
        return_code = setting.operation.run()
    except KeyboardInterrupt:
        return_code = 3
    except Exception as e:
        if setting is None or setting.debug:
            import traceback
            traceback.print_exc()
        else:
            print_safe('%s: %s' % (e.__class__.__name__, e))
        return_code = 2
    return return_code
Esempio n. 3
0
    def test_parse_args(self):
        # create
        a0 = ['calendar-cli', 'create', '--date', '20151018', '--start', '1030', '--end', '1100',
              'あいう'.encode('utf-8'), 'えお'.encode('utf-8')]
        s0 = Setting().parse_args(a0)

        self.assertIsInstance(s0.operation, CreateOperation)
        self.assertEqual(s0.operation.calendar_id, 'primary')
        self.assertEqual(s0.operation.event, Event(
            EventTime(True, self._localize(2015, 10, 18, 10, 30)),
            EventTime(True, self._localize(2015, 10, 18, 11, 00)),
            'あいう えお'
        ))

        # summary
        t = datetime.now()
        today = get_localzone().localize(datetime(t.year, t.month, t.day))

        a = ['calendar-cli']
        s = Setting().parse_args(a)

        self.assertIsInstance(s.operation, SummaryOperation)
        self.assertEqual(s.operation.calendar_id, 'primary')
        self.assertEqual(s.operation.start_time, today)
        self.assertEqual(s.operation.duration, timedelta(days=1))
        self.assertEqual(s.operation.format, '[%T] %S%L%C')

        a = ['calendar-cli', '--days', '0']
        s = Setting().parse_args(a)

        self.assertIsInstance(s.operation, SummaryOperation)
        self.assertEqual(s.operation.calendar_id, 'primary')
        self.assertEqual(s.operation.start_time, today)
        self.assertEqual(s.operation.duration, timedelta(days=1))
        self.assertEqual(s.operation.format, '[%T] %S%L%C')

        a = ['calendar-cli', '--days', '1']
        s = Setting().parse_args(a)

        self.assertIsInstance(s.operation, SummaryOperation)
        self.assertEqual(s.operation.calendar_id, 'primary')
        self.assertEqual(s.operation.start_time, today)
        self.assertEqual(s.operation.duration, timedelta(days=2))
        self.assertEqual(s.operation.format, '%D [%T] %S%L%C')

        a = ['calendar-cli', '--days', '6']
        s = Setting().parse_args(a)

        self.assertIsInstance(s.operation, SummaryOperation)
        self.assertEqual(s.operation.calendar_id, 'primary')
        self.assertEqual(s.operation.start_time, today)
        self.assertEqual(s.operation.duration, timedelta(days=7))
        self.assertEqual(s.operation.format, '%D [%T] %S%L%C')

        a = ['calendar-cli', '--days', '6', '--format', '%D %S']
        s = Setting().parse_args(a)

        self.assertIsInstance(s.operation, SummaryOperation)
        self.assertEqual(s.operation.calendar_id, 'primary')
        self.assertEqual(s.operation.start_time, today)
        self.assertEqual(s.operation.duration, timedelta(days=7))
        self.assertEqual(s.operation.format, '%D %S')

        a = ['calendar-cli', '--days', '-1']
        s = Setting().parse_args(a)

        self.assertIsInstance(s.operation, SummaryOperation)
        self.assertEqual(s.operation.calendar_id, 'primary')
        self.assertEqual(s.operation.start_time, today - timedelta(days=1))
        self.assertEqual(s.operation.duration, timedelta(days=2))
        self.assertEqual(s.operation.format, '%D [%T] %S%L%C')

        a = ['calendar-cli', '--date', '20151018']
        s = Setting().parse_args(a)

        self.assertIsInstance(s.operation, SummaryOperation)
        self.assertEqual(s.operation.calendar_id, 'primary')
        self.assertEqual(s.operation.start_time, self._localize(2015, 10, 18, 0, 0))
        self.assertEqual(s.operation.duration, timedelta(days=1))
        self.assertEqual(s.operation.format, '[%T] %S%L%C')

        a = ['calendar-cli', '--date', '20151018', '--days', '-3', '--format', '%S']
        s = Setting().parse_args(a)

        self.assertIsInstance(s.operation, SummaryOperation)
        self.assertEqual(s.operation.calendar_id, 'primary')
        self.assertEqual(s.operation.start_time, self._localize(2015, 10, 15, 0, 0))
        self.assertEqual(s.operation.duration, timedelta(days=4))
        self.assertEqual(s.operation.format, '%S')

        # setup
        a = ['calendar-cli', 'setup', 'client_secret.json']
        s = Setting().parse_args(a)

        self.assertIsInstance(s.operation, SetupOperation)
        self.assertEqual(s.operation.secret_path, 'client_secret.json')
        self.assertEqual(s.operation.read_only, False)
        self.assertEqual(s.operation.no_browser, False)

        a = ['calendar-cli', 'setup', 'client_secret.json', '--read-only', '--no-browser']
        s = Setting().parse_args(a)

        self.assertIsInstance(s.operation, SetupOperation)
        self.assertEqual(s.operation.secret_path, 'client_secret.json')
        self.assertEqual(s.operation.read_only, True)
        self.assertEqual(s.operation.no_browser, True)
Esempio n. 4
0
 def f(has_time, start_year, start_month, start_day, start_hour, start_minute,
       end_year, end_month, end_day, end_hour, end_minute, *args):
     self.assertEqual(
         Setting._parse_time_range(*args, now=now),
         (EventTime(has_time, self._localize(start_year, start_month, start_day, start_hour, start_minute)),
          EventTime(has_time, self._localize(end_year, end_month, end_day, end_hour, end_minute))))