Ejemplo n.º 1
0
def test_MinutesFromUTC_tzname(testcase, offset, dt, exp_tzname):
    """
    Test function for MinutesFromUTC.tzname().
    """

    tz = MinutesFromUTC(offset)

    # The code to be tested
    act_tzname = tz.tzname(dt)

    # Ensure that exceptions raised in the remainder of this function
    # are not mistaken as expected exceptions
    assert testcase.exp_exc_types is None

    assert act_tzname == exp_tzname
Ejemplo n.º 2
0
def test_MinutesFromUTC_utcoffset(testcase, offset, dt, exp_utc_offset):
    """
    Test function for MinutesFromUTC.utcoffset().
    """

    tz = MinutesFromUTC(offset)

    # The code to be tested
    act_utcoffset = tz.utcoffset(dt)

    # Ensure that exceptions raised in the remainder of this function
    # are not mistaken as expected exceptions
    assert testcase.exp_exc_types is None

    exp_utcoffset = timedelta(minutes=exp_utc_offset)
    assert act_utcoffset == exp_utcoffset
Ejemplo n.º 3
0
    def create_ciminstance(self):
        """
        Create a sample instance with multiple properties and
        property types.
        """
        class TZ(tzinfo):
            """'Simplistic tsinfo subclass for this test"""
            def utcoffset(self, dt):  # pylint: disable=unused-argument
                return timedelta(minutes=-399)

        dt = datetime(year=2016,
                      month=3,
                      day=31,
                      hour=19,
                      minute=30,
                      second=40,
                      microsecond=654321,
                      tzinfo=MinutesFromUTC(120))
        cim_dt = CIMDateTime(dt)
        props_input = {
            'S1':
            b'Ham',
            'Bool':
            True,
            'UI8':
            Uint8(42),
            'UI16':
            Uint16(4216),
            'UI32':
            Uint32(4232),
            'UI64':
            Uint64(4264),
            'SI8':
            Sint8(-42),
            'SI16':
            Sint16(-4216),
            'SI32':
            Sint32(-4232),
            'SI64':
            Sint64(-4264),
            'R32':
            Real32(42.0),
            'R64':
            Real64(42.64),
            'DTI':
            CIMDateTime(timedelta(10, 49, 20)),
            'DTF':
            cim_dt,
            'DTP':
            CIMDateTime(datetime(2014, 9, 22, 10, 49, 20, 524789,
                                 tzinfo=TZ())),
        }
        # TODO python 2.7 will not write the following unicode character
        # For the moment, only add this property in python 3 test
        if six.PY3:
            props_input['S2'] = u'H\u00E4m'  # U+00E4 = lower case a umlaut

        inst = CIMInstance('CIM_Foo', props_input)
        return inst
Ejemplo n.º 4
0
def test_MinutesFromUTC_init(testcase, args, kwargs, exp_offset):
    """
    Test function for MinutesFromUTC.__init__().
    """

    # The code to be tested
    tz = MinutesFromUTC(*args, **kwargs)

    # Ensure that exceptions raised in the remainder of this function
    # are not mistaken as expected exceptions
    assert testcase.exp_exc_types is None

    assert not hasattr(tz, '__dict__')

    # Verify the UTC offset of the tz object.
    exp_utcoffset = timedelta(minutes=exp_offset)
    dt = datetime.now()
    assert tz.utcoffset(dt) == exp_utcoffset
Ejemplo n.º 5
0
def test_MinutesFromUTC_dst(testcase, offset, dt, exp_dst_offset):
    """
    Test function for MinutesFromUTC.dst().
    """

    tz = MinutesFromUTC(offset)

    # The code to be tested
    act_dst = tz.dst(dt)

    # Ensure that exceptions raised in the remainder of this function
    # are not mistaken as expected exceptions
    assert testcase.exp_exc_types is None

    exp_dst = timedelta(minutes=exp_dst_offset)
    assert act_dst == exp_dst

    # Test the condition for sane tzinfo implementations w.r.t. DST
    dt1 = datetime(2020, 4, 11, 13, 14, 15, tzinfo=tz)
    diff1 = tz.utcoffset(dt1) - tz.dst(dt1)
    dt2 = datetime.now(tz)
    diff2 = tz.utcoffset(dt2) - tz.dst(dt2)
    assert diff1 == diff2
Ejemplo n.º 6
0
  None),
 ('**************.******:000', 'interval', None,
  timedelta(days=0, hours=0, minutes=0, seconds=0,
            microseconds=0), 0, 0, '**************.******:000'),
 ('12345678224455.654321:777', ValueError, None, None, None, None,
  None),
 ('12345678224455,654321:000', ValueError, None, None, None, None,
  None),
 (datetime(year=2014,
           month=9,
           day=24,
           hour=19,
           minute=30,
           second=40,
           microsecond=654321,
           tzinfo=MinutesFromUTC(120)), 'timestamp',
  datetime(year=2014,
           month=9,
           day=24,
           hour=19,
           minute=30,
           second=40,
           microsecond=654321,
           tzinfo=MinutesFromUTC(120)), None, None, 120,
  '20140924193040.654321+120'),
 (datetime(year=2014,
           month=9,
           day=24,
           hour=19,
           minute=30,
           second=40,
Ejemplo n.º 7
0
     timedelta(days=12345678, hours=22, minutes=44, seconds=55,
               microseconds=654321),
     0,
     '12345678224455.654321:000'
 ),
 (
     '12345678224455.654321:777',
     ValueError, None, None, None, None
 ),
 (
     '12345678224455,654321:000',
     ValueError, None, None, None, None
 ),
 (
     datetime(year=2014, month=9, day=24, hour=19, minute=30, second=40,
              microsecond=654321, tzinfo=MinutesFromUTC(120)),
     'timestamp',
     datetime(year=2014, month=9, day=24, hour=19, minute=30, second=40,
              microsecond=654321, tzinfo=MinutesFromUTC(120)),
     None,
     120,
     '20140924193040.654321+120'
 ),
 (
     '20140924193040.654321+120',
     'timestamp',
     datetime(year=2014, month=9, day=24, hour=19, minute=30, second=40,
              microsecond=654321, tzinfo=MinutesFromUTC(120)),
     None,
     120,
     '20140924193040.654321+120'
Ejemplo n.º 8
0
               microseconds=0),
     0,
     0,
     '**************.******:000'
 ),
 (
     '12345678224455.654321:777',
     ValueError, None, None, None, None, None
 ),
 (
     '12345678224455,654321:000',
     ValueError, None, None, None, None, None
 ),
 (
     datetime(year=2014, month=9, day=24, hour=19, minute=30, second=40,
              microsecond=654321, tzinfo=MinutesFromUTC(120)),
     'timestamp',
     datetime(year=2014, month=9, day=24, hour=19, minute=30, second=40,
              microsecond=654321, tzinfo=MinutesFromUTC(120)),
     None,
     None,
     120,
     '20140924193040.654321+120'
 ),
 (
     datetime(year=2014, month=9, day=24, hour=19, minute=30, second=40,
              microsecond=654321, tzinfo=MinutesFromUTC(0)),
     'timestamp',
     datetime(year=2014, month=9, day=24, hour=19, minute=30, second=40,
              microsecond=654321, tzinfo=MinutesFromUTC(0)),
     None,
Ejemplo n.º 9
0
 (CIMDateTime('12345678224455.654321:000'), 'interval', None,
  timedelta(days=12345678,
            hours=22,
            minutes=44,
            seconds=55,
            microseconds=654321), 0, '12345678224455.654321:000'),
 ('12345678224455.654321:777', ValueError, None, None, None, None),
 ('12345678224455,654321:000', ValueError, None, None, None, None),
 (datetime(year=2014,
           month=9,
           day=24,
           hour=19,
           minute=30,
           second=40,
           microsecond=654321,
           tzinfo=MinutesFromUTC(120)), 'timestamp',
  datetime(year=2014,
           month=9,
           day=24,
           hour=19,
           minute=30,
           second=40,
           microsecond=654321,
           tzinfo=MinutesFromUTC(120)), None, 120,
  '20140924193040.654321+120'),
 (datetime(year=2014,
           month=9,
           day=24,
           hour=19,
           minute=30,
           second=40,