Author: Armin Rigo <ar...@tunes.org> Branch: Changeset: r73647:e69035610b6b Date: 2014-09-22 18:16 +0200 http://bitbucket.org/pypy/pypy/changeset/e69035610b6b/
Log: Issue #1869: fix error messages to match CPython's datetime.c diff --git a/lib_pypy/datetime.py b/lib_pypy/datetime.py --- a/lib_pypy/datetime.py +++ b/lib_pypy/datetime.py @@ -1242,7 +1242,7 @@ (other._hour, other._minute, other._second, other._microsecond)) if myoff is None or otoff is None: - raise TypeError("cannot compare naive and aware times") + raise TypeError("can't compare offset-naive and offset-aware datetimes") myhhmm = self._hour * 60 + self._minute - myoff othhmm = other._hour * 60 + other._minute - otoff return _cmp((myhhmm, self._second, self._microsecond), @@ -1838,7 +1838,7 @@ other._hour, other._minute, other._second, other._microsecond)) if myoff is None or otoff is None: - raise TypeError("cannot compare naive and aware datetimes") + raise TypeError("can't compare offset-naive and offset-aware datetimes") # XXX What follows could be done more efficiently... diff = self - other # this will take offsets into account if diff.days < 0: @@ -1885,7 +1885,7 @@ if myoff == otoff: return base if myoff is None or otoff is None: - raise TypeError("cannot mix naive and timezone-aware time") + raise TypeError("can't compare offset-naive and offset-aware datetimes") return base + timedelta(minutes = otoff-myoff) def __hash__(self): diff --git a/pypy/module/test_lib_pypy/test_datetime.py b/pypy/module/test_lib_pypy/test_datetime.py --- a/pypy/module/test_lib_pypy/test_datetime.py +++ b/pypy/module/test_lib_pypy/test_datetime.py @@ -191,3 +191,21 @@ def __radd__(self, other): return "radd" assert datetime.date(10, 10, 10) + X() == "radd" + +def test_raises_if_passed_naive_datetime_and_start_or_end_time_defined(): + class Foo(datetime.tzinfo): + def utcoffset(self, dt): + return datetime.timedelta(0.1) + naive = datetime.datetime(2014, 9, 22) + aware = datetime.datetime(2014, 9, 22, tzinfo=Foo()) + with py.test.raises(TypeError) as e: + naive == aware + assert str(e.value) == "can't compare offset-naive and offset-aware datetimes" + with py.test.raises(TypeError) as e: + naive - aware + assert str(e.value) == "can't compare offset-naive and offset-aware datetimes" + naive = datetime.time(7, 32, 12) + aware = datetime.time(7, 32, 12, tzinfo=Foo()) + with py.test.raises(TypeError) as e: + naive == aware + assert str(e.value) == "can't compare offset-naive and offset-aware datetimes" _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit