예제 #1
0
def _timestamp_instants_eq(a, b):
    """Compares two timestamp operands for point-in-time equivalence only."""
    assert isinstance(a, datetime)
    if not isinstance(b, datetime):
        return False
    # datetime's __eq__ can't compare a None offset and a non-None offset. For these equivalence semantics, a None
    # offset (unknown local offset) is treated equivalently to a +00:00.
    if a.tzinfo is None:
        a = a.replace(tzinfo=OffsetTZInfo())
    if b.tzinfo is None:
        b = b.replace(tzinfo=OffsetTZInfo())
    # datetime's __eq__ implementation compares instants; offsets and precision need not be equal.
    return a == b
예제 #2
0
 True,
 False,
 IonPyInt.from_value(IonType.BOOL, 0),
 IonPyInt.from_value(IonType.BOOL, 1),
 0,
 -1,
 1.23,
 1.23e4,
 -1.23,
 -1.23e-4,
 Decimal(0),
 Decimal('-1.23'),
 datetime(year=1,
          month=1,
          day=1,
          tzinfo=OffsetTZInfo(timedelta(minutes=-1))),
 u'',
 u'abc',
 u'abcdefghijklmno',
 u'a\U0001f4a9c',
 u'a\u3000\x20c',
 _st(u''),
 _st(u'abc'),
 _st(u'abcdefghijklmno'),
 _st(u'a\U0001f4a9c'),
 _st(u'a\u3000\x20c'),
 b'abcd',
 IonPyBytes.from_value(IonType.CLOB, b'abcd'),
 [[[]]],
 [[], [], []],
 [{}, {}, {}],
예제 #3
0
    ),
    (
        {},
        _struct({}),
    ),
    (
        {u'abc': 123, 'def': 456},
        _struct({u'def': 456, u'abc': 123}),
    )
)

_EQUIVS_INSTANTS = (
    (
        # These all represent the same instant.
        _dt(2000, 1, 1),
        _dt(2000, 1, 1, tzinfo=(OffsetTZInfo())),
        _dt(2000, 1, 1, 1, tzinfo=OffsetTZInfo(timedelta(hours=1))),
        _ts(1999, 12, 31, 23, 59, off_hours=0, off_minutes=-1, precision=_TP.SECOND),
        _timestamp(_ts(2000, 1, 1, 1, off_hours=1, off_minutes=0, precision=_TP.SECOND)),
    ),
)

_NONEQUIVS = (
    # For each tuple, each element is not equivalent to any other element equivalent under the Ion data model.
    (None, 0, _null(_IT.BOOL)),
    (True, False),
    (True, _bool(False)),
    (_bool(True), False),
    (_bool(True), _bool(False)),
    (1, -1, 1.),
    (1, _int(-1), _float(1)),
예제 #4
0
        (_D('0e100'), b'0d+100'),
        (_D('0e-15'), b'0d-15'),
        (_D('-1e1000'), b'-1d+1000'),
        (_D('-4.412111311414141e1000'), b'-4.412111311414141d+1000'),
        (_D('1.1999999999999999555910790149937383830547332763671875e0'),
         b'1.1999999999999999555910790149937383830547332763671875'),
    ),
    _IT.TIMESTAMP: (
        (None, b'null.timestamp'),
        (_DT(2016, 1, 1), b'2016-01-01T00:00:00.000000-00:00'),
        (_DT(2016, 1, 1, 12), b'2016-01-01T12:00:00.000000-00:00'),
        (_DT(2016, 1, 1, 12, 34, 12), b'2016-01-01T12:34:12.000000-00:00'),
        (_DT(2016, 1, 1, 12, 34, 12,
             555000), b'2016-01-01T12:34:12.555000-00:00'),
        (_DT(2016, 1, 1, 12, 34, 12,
             tzinfo=OffsetTZInfo()), b'2016-01-01T12:34:12.000000Z'),
        (_DT(2016, 1, 1, 12, 34, 12, tzinfo=OffsetTZInfo(timedelta(hours=-7))),
         b'2016-01-01T12:34:12.000000-07:00'),
    ),
    _IT.SYMBOL: (
        (None, b'null.symbol'),
        (SymbolToken(None, 4), b'$4'),  # System symbol 'name'.
        (SymbolToken(u'a token', 400), b"'a token'"),
    ) + _SIMPLE_SYMBOLS_TEXT,
    _IT.STRING: ((None, b'null.string'), ) + _SIMPLE_STRINGS_TEXT,
    _IT.CLOB: ((None, b'null.clob'), ) + _SIMPLE_CLOBS_TEXT,
    _IT.BLOB: ((None, b'null.blob'), ) + _SIMPLE_BLOBS_TEXT,
    _IT.LIST: ((None, b'null.list'), ),
    _IT.SEXP: ((None, b'null.sexp'), ),
    _IT.STRUCT: ((None, b'null.struct'), ),
}
예제 #5
0
        (_D('0e100'), b'0d+100'),
        (_D('0e-15'), b'0d-15'),
        (_D('-1e1000'), b'-1d+1000'),
        (_D('-4.412111311414141e1000'), b'-4.412111311414141d+1000'),
        (_D('1.1999999999999999555910790149937383830547332763671875e0'),
         b'1.1999999999999999555910790149937383830547332763671875'),
    ),
    _IT.TIMESTAMP: (
        (None, b'null.timestamp'),
        (_DT(2016, 1, 1), b'2016-01-01T00:00:00-00:00'),
        (_DT(2016, 1, 1, 12), b'2016-01-01T12:00:00-00:00'),
        (_DT(2016, 1, 1, 12, 34, 12), b'2016-01-01T12:34:12-00:00'),
        (_DT(2016, 1, 1, 12, 34, 12,
             555000), b'2016-01-01T12:34:12.555000-00:00'),
        (_DT(2016, 1, 1, 12, 34, 12,
             tzinfo=OffsetTZInfo()), b'2016-01-01T12:34:12+00:00'),
        (_DT(2016, 1, 1, 12, 34, 12, tzinfo=OffsetTZInfo(timedelta(hours=-7))),
         b'2016-01-01T12:34:12-07:00'),
    ),
    _IT.SYMBOL: (
        (None, b'null.symbol'),
        (SymbolToken(None, 4), b'$4'),  # System symbol 'name'.
        (SymbolToken(u'a token', 400), b"'a token'"),
    ) + _SIMPLE_SYMBOLS,
    _IT.STRING: ((None, b'null.string'), ) + _SIMPLE_STRINGS,
    _IT.CLOB: ((None, b'null.clob'), ) + _SIMPLE_CLOBS,
    _IT.BLOB: ((None, b'null.blob'), ) + _SIMPLE_BLOBS,
    _IT.LIST: ((None, b'null.list'), ),
    _IT.SEXP: ((None, b'null.sexp'), ),
    _IT.STRUCT: ((None, b'null.struct'), ),
}