1from PyObjCTools.TestSupport import * 2from AppKit import * 3 4class TestNSLayoutContraintManual (TestCase): 5 def testNSDictionaryOfVariableBindings(self): 6 var1 = 'foo' 7 var2 = 'bar' 8 9 self.assertEqual(NSDictionaryOfVariableBindings('var1', 'var2'), 10 {'var1': 'foo', 'var2': 'bar'}) 11 12 self.assertRaises(KeyError, NSDictionaryOfVariableBindings, 'var1', 'var3') 13 14 @min_os_level('10.7') 15 def testConstants10_7(self): 16 self.assertIsInstance(NSViewNoInstrinsicMetric, float) 17 self.assertEqual(NSLayoutRelationLessThanOrEqual, -1) 18 self.assertEqual(NSLayoutRelationEqual, 0) 19 self.assertEqual(NSLayoutRelationGreaterThanOrEqual, 1) 20 self.assertEqual(NSLayoutAttributeLeft, 1) 21 self.assertEqual(NSLayoutAttributeRight, 2) 22 self.assertEqual(NSLayoutAttributeTop, 3) 23 self.assertEqual(NSLayoutAttributeBottom, 4) 24 self.assertEqual(NSLayoutAttributeLeading, 5) 25 self.assertEqual(NSLayoutAttributeTrailing, 6) 26 self.assertEqual(NSLayoutAttributeWidth, 7) 27 self.assertEqual(NSLayoutAttributeHeight, 8) 28 self.assertEqual(NSLayoutAttributeCenterX, 9) 29 self.assertEqual(NSLayoutAttributeCenterY, 10) 30 self.assertEqual(NSLayoutAttributeBaseline, 11) 31 self.assertEqual(NSLayoutAttributeNotAnAttribute, 0) 32 self.assertEqual(NSLayoutFormatAlignAllLeft, (1 << NSLayoutAttributeLeft)) 33 self.assertEqual(NSLayoutFormatAlignAllRight, (1 << NSLayoutAttributeRight)) 34 self.assertEqual(NSLayoutFormatAlignAllTop, (1 << NSLayoutAttributeTop)) 35 self.assertEqual(NSLayoutFormatAlignAllBottom, (1 << NSLayoutAttributeBottom)) 36 self.assertEqual(NSLayoutFormatAlignAllLeading, (1 << NSLayoutAttributeLeading)) 37 self.assertEqual(NSLayoutFormatAlignAllTrailing, (1 << NSLayoutAttributeTrailing)) 38 self.assertEqual(NSLayoutFormatAlignAllCenterX, (1 << NSLayoutAttributeCenterX)) 39 self.assertEqual(NSLayoutFormatAlignAllCenterY, (1 << NSLayoutAttributeCenterY)) 40 self.assertEqual(NSLayoutFormatAlignAllBaseline, (1 << NSLayoutAttributeBaseline)) 41 self.assertEqual(NSLayoutFormatAlignmentMask, 0xFFFF) 42 43 self.assertEqual(NSLayoutFormatDirectionLeadingToTrailing, 0 << 16) 44 self.assertEqual(NSLayoutFormatDirectionLeftToRight, 1 << 16) 45 self.assertEqual(NSLayoutFormatDirectionRightToLeft, 2 << 16) 46 47 self.assertEqual(NSLayoutFormatDirectionMask, 0x3 << 16) 48 self.assertEqual(NSLayoutConstraintOrientationHorizontal, 0) 49 self.assertEqual(NSLayoutConstraintOrientationVertical, 1) 50 51 self.assertEqual(NSLayoutPriorityRequired, 1000) 52 self.assertEqual(NSLayoutPriorityDefaultHigh, 750) 53 self.assertEqual(NSLayoutPriorityDragThatCanResizeWindow, 510) 54 self.assertEqual(NSLayoutPriorityWindowSizeStayPut, 500) 55 self.assertEqual(NSLayoutPriorityDragThatCannotResizeWindow, 490) 56 self.assertEqual(NSLayoutPriorityDefaultLow, 250) 57 self.assertEqual(NSLayoutPriorityFittingSizeCompression, 50) 58 59 @min_os_level('10.7') 60 def testRecords10_7(self): 61 v = NSEdgeInsets() 62 self.assertEqual(v.top, 0.0) 63 self.assertEqual(v.left, 0.0) 64 self.assertEqual(v.bottom, 0.0) 65 self.assertEqual(v.right, 0.0) 66 67 self.assertEqual(NSEdgeInsets.__typestr__, 68 b'{_NSEdgeInsets=' + objc._C_CGFloat + objc._C_CGFloat + objc._C_CGFloat + objc._C_CGFloat + b'}') 69 70 @min_os_level('10.7') 71 def testFunctions10_7(self): 72 v = NSEdgeInsetsMake(1, 2, 3, 4) 73 self.assertIsInstance(v, NSEdgeInsets) 74 self.assertEqual(v.top, 1.0) 75 self.assertEqual(v.left, 2.0) 76 self.assertEqual(v.bottom, 3.0) 77 self.assertEqual(v.right, 4.0) 78 79 @min_os_level('10.7') 80 def testMethods10_7(self): 81 self.assertResultIsBOOL(NSLayoutConstraint.shouldBeArchived) 82 self.assertArgIsBOOL(NSLayoutConstraint.setShouldBeArchived_, 0) 83 84 self.assertResultIsBOOL(NSView.needsUpdateConstraints) 85 self.assertArgIsBOOL(NSView.setNeedsUpdateConstraints_, 0) 86 87 self.assertResultIsBOOL(NSView.needsLayout) 88 self.assertArgIsBOOL(NSView.setNeedsLayout_, 0) 89 90 self.assertResultIsBOOL(NSView.translatesAutoresizingMaskIntoConstraints) 91 self.assertArgIsBOOL(NSView.setTranslatesAutoresizingMaskIntoConstraints_, 0) 92 self.assertResultIsBOOL(NSView.requiresConstraintBasedLayout) 93 self.assertResultIsBOOL(NSView.hasAmbiguousLayout) 94 95if __name__ == "__main__": 96 main() 97