pyobjc / pyobjc / Lib / AppKit / test / test_nsfont.py

import unittest
import objc

import AppKit

import os
ON_JAGUAR=((os.uname()[0] == 'Darwin') and (os.uname()[2][0] == '6'))

class TestNSFont(unittest.TestCase):
    def matrixEquals(self, value1, value2):
        self.assertEquals(len(value1), len(value2))
        for v1, v2 in zip(value1, value2):
            # This should probably be 'assertAlmostEquals'
            self.assertEquals(v1, v2)

    def testConstants(self):
        self.assert_(hasattr(AppKit, 'NSFontIdentityMatrix'))
        self.assertEquals(AppKit.NSFontIdentityMatrix, None)

    def testMatrixMethods(self):
        o = AppKit.NSFont.boldSystemFontOfSize_(10);
        m = o.matrix()
        self.assert_(isinstance(m, tuple))
        self.assertEquals(len(m), 6)

        nm = o.fontName()

        if not ON_JAGUAR:
            # Don't test this on Jaguar, see Radar #3421569.
            o = AppKit.NSFont.fontWithName_matrix_(
                    nm, AppKit.NSFontIdentityMatrix)
            self.assert_(o is not None)

            m = o.matrix()
            self.assert_(isinstance(m, tuple))
            self.assertEquals(len(m), 6)

            self.matrixEquals(m, (1.0, 0.0, 0.0, 1.0, 0.0, 0.0))

        o = AppKit.NSFont.fontWithName_matrix_(nm, (1.0, 2.0, 3.0, 4.0, 5.0, 6.0))
        self.assert_(o is not None)

        m = o.matrix()
        self.assert_(isinstance(m, tuple))
        self.assertEquals(len(m), 6)

        self.matrixEquals(m, (1.0, 2.0, 3.0, 4.0, 5.0, 6.0))

        self.assertRaises(ValueError, AppKit.NSFont.fontWithName_matrix_, nm, "foo")
        self.assertRaises(ValueError, AppKit.NSFont.fontWithName_matrix_, nm, (1, 2, 3, 4))
        self.assertRaises(ValueError, AppKit.NSFont.fontWithName_matrix_, nm, (1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0))




if __name__ == '__main__':
   unittest.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.