Source

pyobjc / pyobjc-framework-Cocoa / PyObjCTest / test_cfdateformatter.py

Ronald Oussoren 9746aba 






Ronald Oussoren 1059289 
Ronald Oussoren 9746aba 































Ronald Oussoren 1059289 

Ronald Oussoren 9746aba 













Ronald Oussoren 1059289 

Ronald Oussoren 9746aba 















































Ronald Oussoren 1059289 
Ronald Oussoren 9746aba 
from PyObjCTools.TestSupport import *
from CoreFoundation import *


class TestDateFormatter (TestCase):
    def testTypeID(self):
        self.assertIsInstance(CFDateGetTypeID(), (int, long))

    def testConstants(self):
        self.assertEqual(kCFDateFormatterNoStyle , 0)
        self.assertEqual(kCFDateFormatterShortStyle , 1)
        self.assertEqual(kCFDateFormatterMediumStyle , 2)
        self.assertEqual(kCFDateFormatterLongStyle , 3)
        self.assertEqual(kCFDateFormatterFullStyle , 4)
        self.assertIsInstance(kCFDateFormatterIsLenient, unicode)
        self.assertIsInstance(kCFDateFormatterTimeZone, unicode)
        self.assertIsInstance(kCFDateFormatterCalendarName, unicode)
        self.assertIsInstance(kCFDateFormatterDefaultFormat, unicode)
        self.assertIsInstance(kCFDateFormatterTwoDigitStartDate, unicode)
        self.assertIsInstance(kCFDateFormatterDefaultDate, unicode)
        self.assertIsInstance(kCFDateFormatterCalendar, unicode)
        self.assertIsInstance(kCFDateFormatterEraSymbols, unicode)
        self.assertIsInstance(kCFDateFormatterMonthSymbols, unicode)
        self.assertIsInstance(kCFDateFormatterShortMonthSymbols, unicode)
        self.assertIsInstance(kCFDateFormatterWeekdaySymbols, unicode)
        self.assertIsInstance(kCFDateFormatterShortWeekdaySymbols, unicode)
        self.assertIsInstance(kCFDateFormatterAMSymbol, unicode)
        self.assertIsInstance(kCFDateFormatterPMSymbol, unicode)
        self.assertIsInstance(kCFDateFormatterLongEraSymbols, unicode)
        self.assertIsInstance(kCFDateFormatterVeryShortMonthSymbols, unicode)
        self.assertIsInstance(kCFDateFormatterStandaloneMonthSymbols, unicode)
        self.assertIsInstance(kCFDateFormatterShortStandaloneMonthSymbols, unicode)
        self.assertIsInstance(kCFDateFormatterVeryShortStandaloneMonthSymbols, unicode)
        self.assertIsInstance(kCFDateFormatterVeryShortWeekdaySymbols, unicode)
        self.assertIsInstance(kCFDateFormatterStandaloneWeekdaySymbols, unicode)
        self.assertIsInstance(kCFDateFormatterShortStandaloneWeekdaySymbols, unicode)
        self.assertIsInstance(kCFDateFormatterVeryShortStandaloneWeekdaySymbols, unicode)
        self.assertIsInstance(kCFDateFormatterQuarterSymbols, unicode)
        self.assertIsInstance(kCFDateFormatterShortQuarterSymbols, unicode)
        self.assertIsInstance(kCFDateFormatterStandaloneQuarterSymbols, unicode)
        self.assertIsInstance(kCFDateFormatterShortStandaloneQuarterSymbols, unicode)
        self.assertIsInstance(kCFDateFormatterGregorianStartDate, unicode)

    @min_os_level('10.6')
    def testConstants10_6(self):
        self.assertIsInstance(kCFDateFormatterDoesRelativeDateFormattingKey, unicode)

    @min_os_level('10.6')
    def testFunction10_6(self):
        self.assertResultIsCFRetained(CFDateFormatterCreateDateFormatFromTemplate)
        r = CFDateFormatterCreateDateFormatFromTemplate(None, "%Y-%m-%d", 0, None)
        self.assertIsInstance(r, unicode)
                            
    def testTypes(self):
        self.assertIsCFType(CFDateFormatterRef)

        self.assertIsInstance(CFDateFormatterGetTypeID(), (int, long))

    def testInspection(self):
        locale = CFLocaleCopyCurrent()
        self.assertIsInstance(locale, CFLocaleRef)

        date = CFDateCreate(None, CFAbsoluteTimeGetCurrent())
        self.assertIsInstance(date, CFDateRef)

        self.assertResultIsCFRetained(CFDateFormatterCreate)
        fmt = CFDateFormatterCreate(None, locale, kCFDateFormatterShortStyle, kCFDateFormatterLongStyle) 
        self.assertIsInstance(fmt, CFDateFormatterRef)
        v = CFDateFormatterGetLocale(fmt)
        self.assertEqual(CFLocaleGetIdentifier(locale), CFLocaleGetIdentifier(v))

        v = CFDateFormatterGetDateStyle(fmt)
        self.assertEqual(v, kCFDateFormatterShortStyle)

        v = CFDateFormatterGetTimeStyle(fmt)
        self.assertEqual(v, kCFDateFormatterLongStyle)

        v = CFDateFormatterGetFormat(fmt)
        self.assertIsInstance(v, unicode)
        CFDateFormatterSetFormat(fmt, v[:-1])
        v2 = CFDateFormatterGetFormat(fmt)
        self.assertEqual(v[:-1], v2)

        v = CFDateFormatterCreateStringWithDate(None, fmt, date)
        self.assertIsInstance(v, unicode)
        v = CFDateFormatterCreateStringWithAbsoluteTime(None, fmt, CFAbsoluteTimeGetCurrent())
        self.assertIsInstance(v, unicode)
        dt, rng = CFDateFormatterCreateDateFromString(None, fmt, v, (0, len(v)))
        self.assertIsInstance(dt, CFDateRef)
        self.assertIsInstance(rng, CFRange)
        ok, rng, abstime = CFDateFormatterGetAbsoluteTimeFromString(fmt, v, (0, len(v)), None)
        self.assertIs(ok, True)
        self.assertIsInstance(rng, CFRange)
        self.assertIsInstance(abstime, float)
        self.assertResultIsCFRetained(CFDateFormatterCopyProperty)
        v = CFDateFormatterCopyProperty(fmt, kCFDateFormatterCalendarName)
        self.assertIsInstance(v, unicode)
        CFDateFormatterSetProperty(fmt, kCFDateFormatterCalendarName, u"gregorian")
        v = CFDateFormatterCopyProperty(fmt, kCFDateFormatterCalendarName)
        self.assertIsInstance(v, unicode)
        self.assertEqual(v , u"gregorian")
        v = CFDateFormatterCopyProperty(fmt, kCFDateFormatterIsLenient)
        self.assertTrue(v is True or v is False)
        CFDateFormatterSetProperty(fmt, kCFDateFormatterIsLenient, True)
        v2 = CFDateFormatterCopyProperty(fmt, kCFDateFormatterIsLenient)
        self.assertIs(v2, True)

if __name__ == "__main__":
    main()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.