1from PyObjCTools.TestSupport import *
2from PyObjCTest.fnd import NSDateFormatter, NSArray, NSDate
3import datetime
4
5class TestNSDateProxy (TestCase):
6    # Test for proxied datetime.date and datetime.datetime objects,
7    # these have a custom proxy class.
8
9    def testFormattingForDate(self):
10        # This is jus a round-about way of testing that the right proxy
11        # object is created
12        formatter = NSDateFormatter.alloc().initWithDateFormat_allowNaturalLanguage_(
13                "%Y-%m-%d", True)
14
15        date = datetime.date.today()
16
17        value = formatter.stringFromDate_(NSDate.date())
18        self.assertEqual(value, date.strftime('%Y-%m-%d'))
19
20        value = formatter.stringFromDate_(date)
21        self.assertEqual(value, date.strftime('%Y-%m-%d'))
22
23
24    def testFormattingForDateTime(self):
25        # This is jus a round-about way of testing that the right proxy
26        # object is created
27        formatter = NSDateFormatter.alloc().initWithDateFormat_allowNaturalLanguage_(
28                "%Y-%m-%d %H:%M:%S", True)
29
30        date = datetime.datetime.now()
31
32        value = formatter.stringFromDate_(date)
33        self.assertEqual(value, date.strftime('%Y-%m-%d %H:%M:%S'))
34
35
36if __name__ == "__main__":
37    main()
38