Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 482034 | Differences between
and this patch

Collapse All | Expand All

(-)trac/util/tests/datefmt.py (-38 / +45 lines)
Lines 730-742 Link Here
730
    I18nDateFormatTestCase = None
730
    I18nDateFormatTestCase = None
731
else:
731
else:
732
    class I18nDateFormatTestCase(unittest.TestCase):
732
    class I18nDateFormatTestCase(unittest.TestCase):
733
734
        if not hasattr(unittest.TestCase, 'assertIn'):
735
            def assertIn(self, member, container, msg=None):
736
                if member not in container:
737
                    raise self.failureException(msg or '%r not in %r' %
738
                                                       (member, container))
739
733
        def test_i18n_format_datetime(self):
740
        def test_i18n_format_datetime(self):
734
            tz = datefmt.timezone('GMT +2:00')
741
            tz = datefmt.timezone('GMT +2:00')
735
            t = datetime.datetime(2010, 8, 28, 11, 45, 56, 123456, datefmt.utc)
742
            t = datetime.datetime(2010, 8, 28, 11, 45, 56, 123456, datefmt.utc)
736
            en_US = Locale.parse('en_US')
743
            en_US = Locale.parse('en_US')
737
            self.assert_(datefmt.format_datetime(t, tzinfo=tz, locale=en_US)
744
            self.assertIn(datefmt.format_datetime(t, tzinfo=tz, locale=en_US),
738
                         in ('Aug 28, 2010 1:45:56 PM',
745
                          ('Aug 28, 2010 1:45:56 PM',
739
                             'Aug 28, 2010, 1:45:56 PM'))  # CLDR 23
746
                           'Aug 28, 2010, 1:45:56 PM'))  # CLDR 23
740
            en_GB = Locale.parse('en_GB')
747
            en_GB = Locale.parse('en_GB')
741
            self.assertEqual('28 Aug 2010 13:45:56',
748
            self.assertEqual('28 Aug 2010 13:45:56',
742
                             datefmt.format_datetime(t, tzinfo=tz,
749
                             datefmt.format_datetime(t, tzinfo=tz,
Lines 751-759 Link Here
751
            self.assertEqual(u'13:45:56 28-08-2010',
758
            self.assertEqual(u'13:45:56 28-08-2010',
752
                             datefmt.format_datetime(t, tzinfo=tz, locale=vi))
759
                             datefmt.format_datetime(t, tzinfo=tz, locale=vi))
753
            zh_CN = Locale.parse('zh_CN')
760
            zh_CN = Locale.parse('zh_CN')
754
            self.assertEqual(u'2010-8-28 下午01:45:56',
761
            self.assertIn(datefmt.format_datetime(t, tzinfo=tz, locale=zh_CN),
755
                             datefmt.format_datetime(t, tzinfo=tz,
762
                          (u'2010-8-28 下午01:45:56',
756
                                                     locale=zh_CN))
763
                           u'2010年8月28日 下午1:45:56'))
757
764
758
        def test_i18n_format_date(self):
765
        def test_i18n_format_date(self):
759
            tz = datefmt.timezone('GMT +2:00')
766
            tz = datefmt.timezone('GMT +2:00')
Lines 774-781 Link Here
774
            self.assertEqual(u'07-08-2010',
781
            self.assertEqual(u'07-08-2010',
775
                             datefmt.format_date(t, tzinfo=tz, locale=vi))
782
                             datefmt.format_date(t, tzinfo=tz, locale=vi))
776
            zh_CN = Locale.parse('zh_CN')
783
            zh_CN = Locale.parse('zh_CN')
777
            self.assertEqual(u'2010-8-7',
784
            self.assertIn(datefmt.format_date(t, tzinfo=tz, locale=zh_CN),
778
                             datefmt.format_date(t, tzinfo=tz, locale=zh_CN))
785
                          (u'2010-8-7', u'2010年8月7日'))
779
786
780
        def test_i18n_format_time(self):
787
        def test_i18n_format_time(self):
781
            tz = datefmt.timezone('GMT +2:00')
788
            tz = datefmt.timezone('GMT +2:00')
Lines 797-804 Link Here
797
                             datefmt.format_time(t, tzinfo=tz, locale=ja))
804
                             datefmt.format_time(t, tzinfo=tz, locale=ja))
798
            self.assertEqual('13:45:56',
805
            self.assertEqual('13:45:56',
799
                             datefmt.format_time(t, tzinfo=tz, locale=vi))
806
                             datefmt.format_time(t, tzinfo=tz, locale=vi))
800
            self.assertEqual(u'下午01:45:56',
807
            self.assertIn(datefmt.format_time(t, tzinfo=tz, locale=zh_CN),
801
                             datefmt.format_time(t, tzinfo=tz, locale=zh_CN))
808
                          (u'下午01:45:56', u'下午1:45:56'))
802
809
803
        def test_i18n_datetime_hint(self):
810
        def test_i18n_datetime_hint(self):
804
            en_US = Locale.parse('en_US')
811
            en_US = Locale.parse('en_US')
Lines 808-825 Link Here
808
            vi = Locale.parse('vi')
815
            vi = Locale.parse('vi')
809
            zh_CN = Locale.parse('zh_CN')
816
            zh_CN = Locale.parse('zh_CN')
810
817
811
            self.assert_(datefmt.get_datetime_format_hint(en_US)
818
            self.assertIn(datefmt.get_datetime_format_hint(en_US),
812
                         in ('MMM d, yyyy h:mm:ss a', 'MMM d, y h:mm:ss a'))
819
                          ('MMM d, yyyy h:mm:ss a', 'MMM d, y h:mm:ss a',
813
            self.assert_(datefmt.get_datetime_format_hint(en_GB)
820
                           'MMM d, y, h:mm:ss a'))
814
                         in ('d MMM yyyy HH:mm:ss', 'd MMM y HH:mm:ss'))
821
            self.assertIn(datefmt.get_datetime_format_hint(en_GB),
815
            self.assert_(datefmt.get_datetime_format_hint(fr)
822
                          ('d MMM yyyy HH:mm:ss', 'd MMM y HH:mm:ss'))
816
                         in ('d MMM yyyy HH:mm:ss', 'd MMM y HH:mm:ss'))
823
            self.assertIn(datefmt.get_datetime_format_hint(fr),
817
            self.assertEqual('yyyy/MM/dd H:mm:ss',
824
                          ('d MMM yyyy HH:mm:ss', 'd MMM y HH:mm:ss'))
818
                             datefmt.get_datetime_format_hint(ja))
825
            self.assertIn(datefmt.get_datetime_format_hint(ja),
819
            self.assertEqual('HH:mm:ss dd-MM-yyyy',
826
                          ('yyyy/MM/dd H:mm:ss', 'y/MM/dd H:mm:ss'))
820
                             datefmt.get_datetime_format_hint(vi))
827
            self.assertIn(datefmt.get_datetime_format_hint(vi),
821
            self.assertEqual('yyyy-M-d ahh:mm:ss',
828
                          ('HH:mm:ss dd-MM-yyyy', 'HH:mm:ss dd-MM-y'))
822
                             datefmt.get_datetime_format_hint(zh_CN))
829
            self.assertIn(datefmt.get_datetime_format_hint(zh_CN),
830
                          ('yyyy-M-d ahh:mm:ss', u'y年M月d日 ah:mm:ss'))
823
831
824
        def test_i18n_date_hint(self):
832
        def test_i18n_date_hint(self):
825
            en_US = Locale.parse('en_US')
833
            en_US = Locale.parse('en_US')
Lines 829-846 Link Here
829
            vi = Locale.parse('vi')
837
            vi = Locale.parse('vi')
830
            zh_CN = Locale.parse('zh_CN')
838
            zh_CN = Locale.parse('zh_CN')
831
839
832
            self.assert_(datefmt.get_date_format_hint(en_US)
840
            self.assertIn(datefmt.get_date_format_hint(en_US),
833
                         in ('MMM d, yyyy', 'MMM d, y'))
841
                          ('MMM d, yyyy', 'MMM d, y'))
834
            self.assert_(datefmt.get_date_format_hint(en_GB)
842
            self.assertIn(datefmt.get_date_format_hint(en_GB),
835
                         in ('d MMM yyyy', 'd MMM y'))
843
                          ('d MMM yyyy', 'd MMM y'))
836
            self.assert_(datefmt.get_date_format_hint(fr)
844
            self.assertIn(datefmt.get_date_format_hint(fr),
837
                         in ('d MMM yyyy', 'd MMM y'))
845
                          ('d MMM yyyy', 'd MMM y'))
838
            self.assertEqual('yyyy/MM/dd',
846
            self.assertIn(datefmt.get_date_format_hint(ja),
839
                             datefmt.get_date_format_hint(ja))
847
                          ('yyyy/MM/dd', 'y/MM/dd'))
840
            self.assertEqual('dd-MM-yyyy',
848
            self.assertIn(datefmt.get_date_format_hint(vi),
841
                             datefmt.get_date_format_hint(vi))
849
                          ('dd-MM-yyyy', 'dd-MM-y'))
842
            self.assertEqual('yyyy-M-d',
850
            self.assertIn(datefmt.get_date_format_hint(zh_CN),
843
                             datefmt.get_date_format_hint(zh_CN))
851
                          ('yyyy-M-d', u'y年M月d日'))
844
852
845
        def test_i18n_parse_date_iso8609(self):
853
        def test_i18n_parse_date_iso8609(self):
846
            tz = datefmt.timezone('GMT +2:00')
854
            tz = datefmt.timezone('GMT +2:00')
Lines 1022-1030 Link Here
1022
            en_US = Locale.parse('en_US')
1030
            en_US = Locale.parse('en_US')
1023
1031
1024
            # Converting default format to babel's format
1032
            # Converting default format to babel's format
1025
            self.assert_(datefmt.format_datetime(t, '%x %X', tz, en_US)
1033
            self.assertIn(datefmt.format_datetime(t, '%x %X', tz, en_US),
1026
                         in ('Aug 28, 2010 1:45:56 PM',
1034
                          ('Aug 28, 2010 1:45:56 PM',
1027
                             'Aug 28, 2010, 1:45:56 PM'))  # CLDR 23
1035
                           'Aug 28, 2010, 1:45:56 PM'))  # CLDR 23
1028
            self.assertEqual('Aug 28, 2010',
1036
            self.assertEqual('Aug 28, 2010',
1029
                             datefmt.format_datetime(t, '%x', tz, en_US))
1037
                             datefmt.format_datetime(t, '%x', tz, en_US))
1030
            self.assertEqual('1:45:56 PM',
1038
            self.assertEqual('1:45:56 PM',
1031
-----------------------------------------------------------------------

Return to bug 482034