Ejemplo n.º 1
0
    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)
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
0
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)
Ejemplo n.º 4
0
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)
Ejemplo n.º 5
0
def test_timezone_with_invalid_name():
    with pytest.raises(InvalidTimezone):
        timezone('Invalid')
Ejemplo n.º 6
0
def test_tzinfo():
    d = pendulum.now()
    assert d.tzinfo.name == timezone("America/Toronto").name
Ejemplo n.º 7
0
 def test_tzinfo(self):
     d = Pendulum.now()
     self.assertEqual(timezone('America/Toronto').name, d.tzinfo.name)
Ejemplo n.º 8
0
 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)
Ejemplo n.º 9
0
def test_timezone_with_offset():
    tz = timezone(-19800)

    assert isinstance(tz, FixedTimezone)
    assert tz.name == "-05:30"
Ejemplo n.º 10
0
#!/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}
Ejemplo n.º 11
0
    def setUp(self):
        LocalTimezone.set_local_timezone(timezone('America/Toronto'))

        super(AbstractTestCase, self).setUp()
Ejemplo n.º 12
0
def test_tzinfo():
    d = pendulum.now()
    assert d.tzinfo.name == timezone("America/Toronto").name
Ejemplo n.º 13
0
def test_instance_timezone_aware_datetime():
    now = pendulum.instance(datetime.now(timezone("Europe/Paris")))
    assert now.timezone_name == "Europe/Paris"
Ejemplo n.º 14
0
def test_timezone_with_name():
    tz = timezone("Europe/Paris")

    assert isinstance(tz, Timezone)
    assert tz.name == "Europe/Paris"
Ejemplo n.º 15
0
def test_timezone_with_offset():
    tz = timezone(-19800)

    assert isinstance(tz, FixedTimezone)
    assert tz.name == '-05:30'
Ejemplo n.º 16
0
def test_instance_timezone_aware_datetime():
    now = pendulum.instance(datetime.now(timezone("Europe/Paris")))
    assert now.timezone_name == "Europe/Paris"
Ejemplo n.º 17
0
def test_timezone_with_name():
    tz = timezone('Europe/Paris')

    assert isinstance(tz, Timezone)
    assert tz.name == 'Europe/Paris'
Ejemplo n.º 18
0
def test_timezone_with_invalid_name():
    with pytest.raises(InvalidTimezone):
        timezone("Invalid")