コード例 #1
0
ファイル: arrow_test.py プロジェクト: alphachoi/arrow
    def test_eq_utc_converstions(self):

        arr = Arrow(datetime(11, 1, 1))

        utc_1 = arr.utc()
        utc_2 = arr.to('UTC')

        self.assertEqual(utc_1.datetime, utc_2.datetime)
        self.assertEqual(utc_1, utc_2)
コード例 #2
0
ファイル: arrow_test.py プロジェクト: minaeid90/arrow
    def test_eq_utc_converstions(self):

        arr = Arrow(datetime(11, 1, 1))

        utc_1 = arr.utc()
        utc_2 = arr.to('UTC')

        self.assertEqual(utc_1.datetime, utc_2.datetime)
        self.assertEqual(utc_1, utc_2)
コード例 #3
0
ファイル: arrow_test.py プロジェクト: alphachoi/arrow
class ArrowTests(BaseArrowTests):

    def setUp(self):
        super(ArrowTests, self).setUp()

        self.arrow = Arrow(datetime.utcnow(), tz=tz.tzutc())

    def test_str(self):

        expected = '{0} UTC'.format(self.arrow._datetime.isoformat())

        self.assertEqual(self.arrow.__str__(), expected)

    def test_repr(self):

        expected = '<Arrow({0} UTC)>'.format(self.arrow._datetime.isoformat())

        self.assertEqual(self.arrow.__repr__(), expected)

    def test_tz(self):

        self.arrow._timezone = self.utc

        self.assertEqual(self.arrow.tz, self.utc)

    def test_to(self):

        self.arrow._datetime = datetime.utcnow().replace(tzinfo=self.utc.tzinfo)
        self.arrow._timezone = self.utc

        result = self.arrow.to('local')

        self.assert_dt_equal(result.datetime, self.arrow._datetime.astimezone(self.local.tzinfo))

    def test_utc_utc(self):

        self.arrow._datetime = datetime.now().replace(tzinfo=self.local.tzinfo)
        self.arrow._timezone = self.local

        result = self.arrow.utc()

        self.assert_dt_equal(result.datetime, self.arrow._datetime.astimezone(self.utc.tzinfo))

    def test_utc_local(self):

        self.arrow._datetime = datetime.utcnow().replace(tzinfo=self.utc.tzinfo)
        self.arrow._timezone = self.utc

        result = self.arrow.utc()

        self.assert_dt_equal(result.datetime, self.arrow._datetime.astimezone(self.utc.tzinfo))

    def test_datetime(self):

        dt = datetime.utcnow().replace(tzinfo=tz.tzutc())

        self.arrow._datetime = dt
        self.arrow._timezone = self.utc

        result = self.arrow.datetime

        self.assertEqual(result, dt)

    def test_timestamp(self):

        dt = datetime.utcnow()

        self.arrow._datetime = dt
        self.arrow._timezone = self.utc

        result = self.arrow.timestamp

        self.assertEqual(result, calendar.timegm(dt.timetuple()))

    def test_parse_int(self):

        dt, timezone = self.arrow._parse(int(time.time()), self.utc)

        self.assert_dt_equal(dt, datetime.utcnow())

    def test_parse_float_utc(self):

        dt, timezone = self.arrow._parse(time.time(), self.utc)

        self.assert_dt_equal(dt, datetime.utcnow())

    def test_parse_float_local(self):

        dt, timezone = self.arrow._parse(time.time(), self.local)

        self.assert_dt_equal(dt, datetime.now())

    def test_parse_str_float_utc(self):

        dt, timezone = self.arrow._parse(str(time.time()), self.utc)

        self.assert_dt_equal(dt, datetime.utcnow())

    def test_parse_str_int_utc(self):

        dt, timezone = self.arrow._parse(str(int(time.time())), self.utc)

        self.assert_dt_equal(dt, datetime.utcnow())

    def test_parse_str_float_local(self):

        dt, timezone = self.arrow._parse(str(time.time()), self.local)

        self.assert_dt_equal(dt, datetime.now())

    def test_parse_str_int_local(self):

        dt, timezone = self.arrow._parse(str(int(time.time())), self.local)
        
        self.assert_dt_equal(dt, datetime.now())

    def test_parse_parse_str(self):

        with self.assertRaises(ValueError):
            self.arrow._parse('abcdefg', self.utc)

    def test_parse_unrecognized(self):

        with self.assertRaises(ValueError):
            self.arrow._parse(object, self.utc)
コード例 #4
0
class ArrowTests(BaseArrowTests):
    def setUp(self):
        super(ArrowTests, self).setUp()

        self.arrow = Arrow(datetime.utcnow(), tz='UTC')

    def test_str(self):

        expected = '{0}.{1} +00:00 (UTC)'.format(
            time.strftime('%x %X', self.arrow.datetime.timetuple()),
            self.arrow.datetime.microsecond)

        self.assertEqual(self.arrow.__str__(), expected)

    def test_repr(self):

        expected = 'Arrow({0}.{1} +00:00 (UTC))'.format(
            time.strftime('%x %X', self.arrow.datetime.timetuple()),
            self.arrow.datetime.microsecond)

        self.assertEqual(self.arrow.__repr__(), expected)

    def test_tz(self):

        self.arrow._timezone = self.utc

        self.assertEqual(self.arrow.tz, self.utc)

    def test_to(self):

        self.arrow._datetime = datetime.utcnow().replace(
            tzinfo=self.utc.tzinfo)
        self.arrow._timezone = self.utc

        result = self.arrow.to('local')

        self.assert_dt_equal(
            result.datetime,
            self.arrow._datetime.astimezone(self.local.tzinfo))

    def test_utc_utc(self):

        self.arrow._datetime = datetime.now().replace(tzinfo=self.local.tzinfo)
        self.arrow._timezone = self.local

        result = self.arrow.utc()

        self.assert_dt_equal(result.datetime,
                             self.arrow._datetime.astimezone(self.utc.tzinfo))

    def test_utc_local(self):

        self.arrow._datetime = datetime.utcnow().replace(
            tzinfo=self.utc.tzinfo)
        self.arrow._timezone = self.utc

        result = self.arrow.utc()

        self.assert_dt_equal(result.datetime,
                             self.arrow._datetime.astimezone(self.utc.tzinfo))

    def test_datetime(self):

        dt = datetime.utcnow().replace(tzinfo=tz.tzutc())

        self.arrow._datetime = dt
        self.arrow._timezone = self.utc

        result = self.arrow.datetime

        self.assertEqual(result, dt)

    def test_timestamp_utc(self):

        dt = datetime.utcnow()

        self.arrow._datetime = dt
        self.arrow._timezone = self.utc

        result = self.arrow.timestamp

        self.assertEqual(result, calendar.timegm(dt.timetuple()))

    def test_timestamp_local(self):

        dt = datetime.now()

        self.arrow._datetime = dt
        self.arrow._timezone = self.local

        result = self.arrow.timestamp

        self.assertEqual(result, time.mktime(dt.timetuple()))

    def test_get_datetime_int(self):

        result = self.arrow._get_datetime(int(time.time()), self.utc)

        self.assert_dt_equal(result, datetime.utcnow())

    def test_get_datetime_float_utc(self):

        result = self.arrow._get_datetime(time.time(), self.utc)

        self.assert_dt_equal(result, datetime.utcnow())

    def test_get_datetime_float_local(self):

        result = self.arrow._get_datetime(time.time(), self.local)

        self.assert_dt_equal(result, datetime.now())

    def test_get_datetime_str_float_utc(self):

        result = self.arrow._get_datetime(str(time.time()), self.utc)

        self.assert_dt_equal(result, datetime.utcnow())

    def test_get_datetime_str_int_utc(self):

        result = self.arrow._get_datetime(str(int(time.time())), self.utc)

        self.assert_dt_equal(result, datetime.utcnow())

    def test_get_datetime_str_float_local(self):

        result = self.arrow._get_datetime(str(time.time()), self.local)

        self.assert_dt_equal(result, datetime.now())

    def test_get_datetime_str_int_local(self):

        result = self.arrow._get_datetime(str(int(time.time())), self.local)

        self.assert_dt_equal(result, datetime.now())

    def test_get_datetime_datetime(self):

        dt = datetime.utcnow()

        result = self.arrow._get_datetime(dt, self.utc)

        self.assert_dt_equal(result, dt)

    def test_get_datetime_parse_str(self):

        with self.assertRaises(RuntimeError):
            self.arrow._get_datetime('abcdefg', self.utc)

    def test_get_datetime_unrecognized(self):

        with self.assertRaises(RuntimeError):
            self.arrow._get_datetime(object, self.utc)