]> git.ipfire.org Git - thirdparty/babel.git/commitdiff
Moved some datetime tests from doctest to unittest, to avoid breaking docutils/epydoc...
authorChristopher Lenz <cmlenz@gmail.com>
Thu, 31 May 2007 17:56:14 +0000 (17:56 +0000)
committerChristopher Lenz <cmlenz@gmail.com>
Thu, 31 May 2007 17:56:14 +0000 (17:56 +0000)
babel/dates.py
babel/tests/dates.py

index 595e9115fe9ed6bd45b61a55869bd26568d2a1a5..e3e62e2a0f078084388cfd44a598772c22a910d9 100644 (file)
@@ -160,28 +160,16 @@ def format_date(date, format='medium', locale=LC_TIME):
     >>> format_time(d, "EEE, MMM d, ''yy", locale='en')
     u"Sun, Apr 1, '07"
     
-    If the pattern contains time fields, an `AttributeError` will be raised
-    when trying to apply the formatting:
-    
-    >>> format_date(d, "yyyy-MM-dd HH:mm", locale='en_US')
-    Traceback (most recent call last):
-      ...
-    AttributeError: 'datetime.date' object has no attribute 'hour'
-    
-    This is also true if the value of ``date`` parameter is a ``datetime``
-    object, as this function automatically converts it to a ``date``::
-    
-    >>> dt = datetime(2007, 04, 01, 15, 30)
-    >>> format_date(dt, "yyyy-MM-dd HH:mm", locale='en_US')
-    Traceback (most recent call last):
-      ...
-    AttributeError: 'datetime.date' object has no attribute 'hour'
-    
-    :param date: the ``date`` object
+    :param date: the ``date`` or ``datetime`` object
     :param format: one of "full", "long", "medium", or "short", or a custom
                    date/time pattern
-    :param locale: a `Locale` object or a locale string
+    :param locale: a `Locale` object or a locale identifier
     :rtype: `unicode`
+    
+    :note: If the pattern contains time fields, an `AttributeError` will be
+           raised when trying to apply the formatting. This is also true if
+           the value of ``date`` parameter is actually a ``datetime`` object,
+           as this function automatically converts that to a ``date``.
     """
     if isinstance(date, datetime):
         date = date.date()
@@ -197,7 +185,7 @@ def format_datetime(datetime, format='medium', locale=LC_TIME):
     :param datetime: the ``date`` object
     :param format: one of "full", "long", "medium", or "short", or a custom
                    date/time pattern
-    :param locale: a `Locale` object or a locale string
+    :param locale: a `Locale` object or a locale identifier
     :rtype: `unicode`
     """
     locale = Locale.parse(locale)
@@ -221,28 +209,16 @@ def format_time(time, format='medium', locale=LC_TIME):
     >>> format_time(t, "hh 'o''clock' a", locale='en')
     u"03 o'clock PM"
     
-    If the pattern contains date fields, an `AttributeError` will be raised
-    when trying to apply the formatting:
-    
-    >>> format_time(t, "yyyy-MM-dd HH:mm", locale='en_US')
-    Traceback (most recent call last):
-      ...
-    AttributeError: 'datetime.time' object has no attribute 'year'
-    
-    This is also true if the value of ``time`` parameter is a ``datetime``
-    object, as this function automatically converts it to a ``time``::
-    
-    >>> dt = datetime(2007, 04, 01, 15, 30)
-    >>> format_time(dt, "yyyy-MM-dd HH:mm", locale='en_US')
-    Traceback (most recent call last):
-      ...
-    AttributeError: 'datetime.time' object has no attribute 'year'
-    
-    :param time: the ``time`` object
+    :param time: the ``time`` or ``datetime`` object
     :param format: one of "full", "long", "medium", or "short", or a custom
                    date/time pattern
-    :param locale: a `Locale` object or a locale string
+    :param locale: a `Locale` object or a locale identifier
     :rtype: `unicode`
+    
+    :note: If the pattern contains date fields, an `AttributeError` will be
+           raised when trying to apply the formatting. This is also true if
+           the value of ``time`` parameter is actually a ``datetime`` object,
+           as this function automatically converts that to a ``time``.
     """
     if isinstance(time, (int, long)):
         time = datetime.fromtimestamp(time).time()
index adabb9a285dacab912be4c64f1905af5b132967d..47616a6496b9b33dd4a02d7880f18175d0d28992 100644 (file)
@@ -11,7 +11,7 @@
 # individuals. For the exact contribution history, see the revision
 # history and logs, available at http://babel.edgewall.org/log/.
 
-from datetime import date, datetime
+from datetime import date, datetime, time
 import doctest
 import unittest
 
@@ -55,10 +55,36 @@ class DateTimeFormatTestCase(unittest.TestCase):
         self.assertEqual('4', fmt['c']) # friday is first day of week
 
 
+class FormatDateTestCase(unittest.TestCase):
+
+    def test_with_time_fields_in_pattern(self):
+        self.assertRaises(AttributeError, dates.format_date, date(2007, 04, 01),
+                          "yyyy-MM-dd HH:mm", locale='en_US')
+
+    def test_with_time_fields_in_pattern_and_datetime_param(self):
+        self.assertRaises(AttributeError, dates.format_date,
+                          datetime(2007, 04, 01, 15, 30),
+                          "yyyy-MM-dd HH:mm", locale='en_US')
+
+
+class FormatTimeTestCase(unittest.TestCase):
+
+    def test_with_date_fields_in_pattern(self):
+        self.assertRaises(AttributeError, dates.format_time, date(2007, 04, 01),
+                          "yyyy-MM-dd HH:mm", locale='en_US')
+
+    def test_with_date_fields_in_pattern_and_datetime_param(self):
+        self.assertRaises(AttributeError, dates.format_time,
+                          datetime(2007, 04, 01, 15, 30),
+                          "yyyy-MM-dd HH:mm", locale='en_US')
+
+
 def suite():
     suite = unittest.TestSuite()
     suite.addTest(doctest.DocTestSuite(dates))
     suite.addTest(unittest.makeSuite(DateTimeFormatTestCase))
+    suite.addTest(unittest.makeSuite(FormatDateTestCase))
+    suite.addTest(unittest.makeSuite(FormatTimeTestCase))
     return suite
 
 if __name__ == '__main__':