diff --git a/testdata/python/basic.py b/testdata/python/basic.py index 38595d8e8..ea4f63eb5 100644 --- a/testdata/python/basic.py +++ b/testdata/python/basic.py @@ -92,6 +92,28 @@ def ph(x): else: return x.replace("X", "") +def map2str(dict): + # A helper function to product a "canonical" (i.e. sorted-keys) string + # representation of a dict + keys = list(dict) + + for k in keys: + if type(k) is str: + strKeys = [] + strDict = {} + for x in keys: + strKeys.append(str(x)) + strDict[str(x)] = dict[x] + strings = [] + for x in sorted(strKeys): + strings.append(str(x) + ": " + str(strDict[x])) + return "{" + ", ".join(strings) + "}" + + strings = [] + for x in sorted(keys): + strings.append(str(x) + ": " + str(dict[x])) + return "{" + ", ".join(strings) + "}" + class BasicTest(unittest.TestCase): def test_00(self): @@ -2066,44 +2088,27 @@ class BasicTest(unittest.TestCase): def test_41(self): - v3 = sys.version_info >= (3, 0) - # maps b = pya.B() b.insert_map1(1, "hello") - if v3: - self.assertEqual(repr(b.map1), "{1: 'hello'}") - else: - self.assertEqual(repr(b.map1), "{1L: 'hello'}") + self.assertEqual(map2str(b.map1), "{1: hello}") b.map1 = {} b.insert_map1(2, "hello") - if v3: - self.assertEqual(repr(b.map1_cref()), "{2: 'hello'}") - else: - self.assertEqual(repr(b.map1_cref()), "{2L: 'hello'}") + self.assertEqual(map2str(b.map1_cref()), "{2: hello}") b.map1 = {} b.insert_map1(3, "hello") - if v3: - self.assertEqual(repr(b.map1_cptr()), "{3: 'hello'}") - else: - self.assertEqual(repr(b.map1_cptr()), "{3L: 'hello'}") + self.assertEqual(map2str(b.map1_cptr()), "{3: hello}") b.map1 = {} b.insert_map1(4, "hello") - if v3: - self.assertEqual(repr(b.map1_ref()), "{4: 'hello'}") - else: - self.assertEqual(repr(b.map1_ref()), "{4L: 'hello'}") + self.assertEqual(map2str(b.map1_ref()), "{4: hello}") b.map1 = {} b.insert_map1(5, "hello") - if v3: - self.assertEqual(repr(b.map1_ptr()), "{5: 'hello'}") - else: - self.assertEqual(repr(b.map1_ptr()), "{5L: 'hello'}") + self.assertEqual(map2str(b.map1_ptr()), "{5: hello}") self.assertEqual(b.map1_cptr_null() == None, True); self.assertEqual(b.map1_ptr_null() == None, True); @@ -2117,52 +2122,28 @@ class BasicTest(unittest.TestCase): self.assertEqual(error_caught, True) b.map1 = { 42: "1", -17: "True" } - if v3: - self.assertEqual(repr(b.map1), "{42: '1', -17: 'True'}") - else: - self.assertEqual(repr(b.map1), "{42L: '1', -17L: 'True'}") + self.assertEqual(map2str(b.map1), "{-17: True, 42: 1}") b.set_map1_cref({ 42: "2", -17: "True" }) - if v3: - self.assertEqual(repr(b.map1), "{42: '2', -17: 'True'}") - else: - self.assertEqual(repr(b.map1), "{42L: '2', -17L: 'True'}") + self.assertEqual(map2str(b.map1), "{-17: True, 42: 2}") b.set_map1_cptr({ 42: "3", -17: "True" }) - if v3: - self.assertEqual(repr(b.map1), "{42: '3', -17: 'True'}") - else: - self.assertEqual(repr(b.map1), "{42L: '3', -17L: 'True'}") + self.assertEqual(map2str(b.map1), "{-17: True, 42: 3}") b.set_map1_cptr(None) - if v3: - self.assertEqual(repr(b.map1), "{42: '3', -17: 'True'}") - else: - self.assertEqual(repr(b.map1), "{42L: '3', -17L: 'True'}") + self.assertEqual(map2str(b.map1), "{-17: True, 42: 3}") b.set_map1_ref({ 42: "4", -17: "True" }) - if v3: - self.assertEqual(repr(b.map1), "{42: '4', -17: 'True'}") - else: - self.assertEqual(repr(b.map1), "{42L: '4', -17L: 'True'}") + self.assertEqual(map2str(b.map1), "{-17: True, 42: 4}") b.set_map1_ptr({ 42: "5", -17: "True" }) - if v3: - self.assertEqual(repr(b.map1), "{42: '5', -17: 'True'}") - else: - self.assertEqual(repr(b.map1), "{42L: '5', -17L: 'True'}") + self.assertEqual(map2str(b.map1), "{-17: True, 42: 5}") b.set_map1_ptr(None) - if v3: - self.assertEqual(repr(b.map1), "{42: '5', -17: 'True'}") - else: - self.assertEqual(repr(b.map1), "{42L: '5', -17L: 'True'}") + self.assertEqual(map2str(b.map1), "{-17: True, 42: 5}") b.map2 = { 'xy': 1, -17: True } - if v3: - self.assertEqual(repr(b.map2), "{'xy': 1, -17: True}") - else: - self.assertEqual(repr(b.map2), "{'xy': 1L, -17L: True}") + self.assertEqual(map2str(b.map2), "{-17: True, xy: 1}") self.assertEqual(b.map2_null(), None) diff --git a/testdata/python/qtbinding.py b/testdata/python/qtbinding.py index 494c363d4..f1f79f60b 100644 --- a/testdata/python/qtbinding.py +++ b/testdata/python/qtbinding.py @@ -77,6 +77,28 @@ class MyObject(pya.QObject): def on_event_filter(self, ef): self.ef = ef +def map2str(dict): + # A helper function to product a "canonical" (i.e. sorted-keys) string + # representation of a dict + keys = list(dict) + + for k in keys: + if type(k) is str: + strKeys = [] + strDict = {} + for x in keys: + strKeys.append(str(x)) + strDict[str(x)] = dict[x] + strings = [] + for x in sorted(strKeys): + strings.append(str(x) + ": " + str(strDict[x])) + return "{" + ", ".join(strings) + "}" + + strings = [] + for x in sorted(keys): + strings.append(str(x) + ": " + str(dict[x])) + return "{" + ", ".join(strings) + "}" + # The Qt binding tests class QtBindingTest(unittest.TestCase): @@ -462,15 +484,13 @@ class QtBindingTest(unittest.TestCase): # QHash bindings slm = MyStandardItemModel() - r1 = "{0: \'display\', 1: \'decoration\', 2: \'edit\', 3: \'toolTip\', 4: \'statusTip\', 5: \'whatsThis\'}" - r2 = "{0L: \'display\', 1L: \'decoration\', 2L: \'edit\', 3L: \'toolTip\', 4L: \'statusTip\', 5L: \'whatsThis\'}" - self.assertEqual(str(slm.roleNames()) == r1 or str(slm.roleNames()) == r2, True) rn = slm.roleNames() - rn[7] = "blabla" - slm.srn(rn) - r1 = "{0: \'display\', 1: \'decoration\', 2: \'edit\', 3: \'toolTip\', 4: \'statusTip\', 5: \'whatsThis\', 7: \'blabla\'}" - r2 = "{0L: \'display\', 1L: \'decoration\', 2L: \'edit\', 3L: \'toolTip\', 4L: \'statusTip\', 5L: \'whatsThis\', 7L: \'blabla\'}" - self.assertEqual(str(slm.roleNames()) == r1 or str(slm.roleNames()) == r2, True) + self.assertEqual(map2str(rn), "{0: display, 1: decoration, 2: edit, 3: toolTip, 4: statusTip, 5: whatsThis}") + rnNew = slm.roleNames() + rnNew[7] = "blabla" + slm.srn(rnNew) + rn = slm.roleNames() + self.assertEqual(map2str(rn), "{0: display, 1: decoration, 2: edit, 3: toolTip, 4: statusTip, 5: whatsThis, 7: blabla}") def test_44(self): @@ -488,8 +508,8 @@ class QtBindingTest(unittest.TestCase): self.assertEqual(child.height > 100, True) parent.resize(100, 100) - self.assertEqual(child.width < 100, True) - self.assertEqual(child.height < 100, True) + self.assertEqual(child.width <= 100, True) + self.assertEqual(child.height <= 100, True) # now if we delete the parent, the child needs to become disconnected diff --git a/testdata/ruby/dbTransTest.rb b/testdata/ruby/dbTransTest.rb index c94204de8..94e9d93f7 100644 --- a/testdata/ruby/dbTransTest.rb +++ b/testdata/ruby/dbTransTest.rb @@ -170,7 +170,7 @@ class DBTrans_TestClass < TestBase assert_equal( c.is_mag?, true ) assert_equal( c.rot, RBA::DCplxTrans::M0.rot ) assert_equal( c.s_trans.to_s, "m0 2.5,-12.5" ) - assert_equal( c.angle, 45 ) + assert_equal( (c.angle - 45).abs < 1e-10, true ) assert_equal( c.ctrans( 5 ).to_s, "3.75" ) assert_equal( c.trans( RBA::DPoint::new( 12, 16 ) ).to_s, "17.3492424049,-14.6213203436" ) @@ -324,7 +324,7 @@ class DBTrans_TestClass < TestBase assert_equal( c.is_mag?, true ) assert_equal( c.rot, RBA::CplxTrans::M0.rot ) assert_equal( c.s_trans.to_s, "m0 3,-13" ) - assert_equal( c.angle, 45 ) + assert_equal( (c.angle - 45).abs < 1e-10, true ) assert_equal( c.ctrans( 5 ).to_s, "3.75" ) assert_equal( c.trans( RBA::Point::new( 12, 16 ) ).to_s, "17.3492424049,-14.6213203436" ) diff --git a/testdata/ruby/qtbinding.rb b/testdata/ruby/qtbinding.rb index c74c396ad..cce2909bb 100644 --- a/testdata/ruby/qtbinding.rb +++ b/testdata/ruby/qtbinding.rb @@ -576,8 +576,8 @@ class QtBinding_TestClass < TestBase assert_equal(child.height() > 100, true) parent.resize(100, 100) - assert_equal(child.width() < 100, true) - assert_equal(child.height() < 100, true) + assert_equal(child.width() <= 100, true) + assert_equal(child.height() <= 100, true) # now if we delete the parent, the child needs to become disconnected