def test_setting_timezone(self): tz = 'Europe/London' dtz = timezone(tz) dt = datetime.utcnow() offset = dtz.convert(dt).tzinfo.offset / 3600 p = Pendulum(dt.year, dt.month, dt.day, tzinfo=dtz) self.assertEqual(tz, p.timezone_name) self.assertEqual(int(offset), p.offset_hours)
def test_parse_setting_timezone_with_string(self): tz = 'Europe/London' dtz = timezone(tz) dt = datetime.utcnow() offset = dtz.convert(dt).tzinfo.offset / 3600 p = Pendulum.parse(tz=tz) self.assertEqual(tz, p.timezone_name) self.assertEqual(int(offset), p.offset_hours)
def test_setting_timezone_with_string(): tz = "Europe/London" dtz = timezone(tz) dt = datetime.utcnow() offset = dtz.convert(dt).utcoffset().total_seconds() / 3600 p = pendulum.datetime(dt.year, dt.month, dt.day, tz=tz) assert p.timezone_name == tz assert p.offset_hours == int(offset)
def test_timezone_with_invalid_name(): with pytest.raises(InvalidTimezone): timezone('Invalid')
def test_tzinfo(): d = pendulum.now() assert d.tzinfo.name == timezone("America/Toronto").name
def test_tzinfo(self): d = Pendulum.now() self.assertEqual(timezone('America/Toronto').name, d.tzinfo.name)
def test_instance_timezone_aware_datetime(self): now = Pendulum.instance( datetime.now( TimezoneInfo.create(timezone('Europe/Paris'), 7200, True, 'EST'))) self.assertEqual('Europe/Paris', now.timezone_name)
def test_timezone_with_offset(): tz = timezone(-19800) assert isinstance(tz, FixedTimezone) assert tz.name == "-05:30"
#!/usr/bin/env python # -*- coding: utf-8 -*- from datetime import datetime from typing import Dict, Tuple, Union import pytest from flask import Flask from marshmallow import Schema, ValidationError from pendulum import tz from pendulum.datetime import DateTime utc = tz.timezone("utc") def test_fields_dump(ma_app: Flask, pendulum_field_schema: Schema) -> None: with ma_app.app_context(): data = {"time": datetime(1994, 9, 11, 8, 20)} res = pendulum_field_schema.dump(data) assert res["time"] == "1994-09-11 16:20:00" def test_fields_load(ma_app: Flask, pendulum_field_schema: Schema) -> None: with ma_app.app_context(): data = {"time": "1994-09-11 08:20:00"} res = pendulum_field_schema.load(data) assert str(res["time"]) == "1994-09-11T00:20:00+00:00" def test_fileds_none_load_handle(ma_app: Flask, pendulum_field_schema: Schema) -> None: with ma_app.app_context(): data = {"time": None}
def setUp(self): LocalTimezone.set_local_timezone(timezone('America/Toronto')) super(AbstractTestCase, self).setUp()
def test_instance_timezone_aware_datetime(): now = pendulum.instance(datetime.now(timezone("Europe/Paris"))) assert now.timezone_name == "Europe/Paris"
def test_timezone_with_name(): tz = timezone("Europe/Paris") assert isinstance(tz, Timezone) assert tz.name == "Europe/Paris"
def test_timezone_with_offset(): tz = timezone(-19800) assert isinstance(tz, FixedTimezone) assert tz.name == '-05:30'
def test_timezone_with_name(): tz = timezone('Europe/Paris') assert isinstance(tz, Timezone) assert tz.name == 'Europe/Paris'
def test_timezone_with_invalid_name(): with pytest.raises(InvalidTimezone): timezone("Invalid")