mirror of
https://github.com/KLayout/klayout.git
synced 2026-08-22 14:07:15 +02:00
Experimental: calling str(x) implicitly in RBA and pya
This commit is contained in:
Vendored
+9
-7
@@ -26,6 +26,12 @@ import copy
|
||||
# Set this to True to disable some tests involving exceptions
|
||||
leak_check = "TEST_LEAK_CHECK" in os.environ
|
||||
|
||||
class ObjectWithStr:
|
||||
def __init__(self, s):
|
||||
self.s = s
|
||||
def __str__(self):
|
||||
return self.s
|
||||
|
||||
# see test_21
|
||||
class AEXT(pya.A):
|
||||
def __init__(self):
|
||||
@@ -191,6 +197,7 @@ class BasicTest(unittest.TestCase):
|
||||
self.assertEqual( a.a1(), -0x80000000 )
|
||||
|
||||
self.assertEqual( a.a3("a"), 1 )
|
||||
self.assertEqual( a.a3(ObjectWithStr("abcde")), 5 ) # implicitly using to_s for string conversion
|
||||
self.assertEqual( a.a3("ab"), 2 )
|
||||
self.assertEqual( a.a3("µ"), 2 ) # two UTF8 bytes
|
||||
if "a3_qstr" in a.__dict__:
|
||||
@@ -2279,13 +2286,8 @@ class BasicTest(unittest.TestCase):
|
||||
self.assertEqual(b.map1_cptr_null() == None, True);
|
||||
self.assertEqual(b.map1_ptr_null() == None, True);
|
||||
|
||||
try:
|
||||
# error converting 1 or True to string
|
||||
b.map1 = { 42: 1, -17: True }
|
||||
error_caught = False
|
||||
except:
|
||||
error_caught = True
|
||||
self.assertEqual(error_caught, True)
|
||||
b.map1 = { 42: 1, -17: True }
|
||||
self.assertEqual(map2str(b.map1), "{-17: True, 42: 1}")
|
||||
|
||||
b.map1 = { 42: "1", -17: "True" }
|
||||
self.assertEqual(map2str(b.map1), "{-17: True, 42: 1}")
|
||||
|
||||
Vendored
+17
-13
@@ -4,6 +4,19 @@
|
||||
# safe in multiple inclusions
|
||||
require File.expand_path('../basic_testcore_defs', __FILE__)
|
||||
|
||||
|
||||
class ObjectWithStr
|
||||
|
||||
def initialize(s)
|
||||
@s = s
|
||||
end
|
||||
|
||||
def to_s
|
||||
@s
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Basic_TestClass < TestBase
|
||||
|
||||
def test_FIRST
|
||||
@@ -85,6 +98,7 @@ class Basic_TestClass < TestBase
|
||||
assert_equal( a.a1, -0x80000000 )
|
||||
|
||||
assert_equal( a.a3("a"), 1 )
|
||||
assert_equal( a.a3(ObjectWithStr::new("abcde")), 5 ) # implicitly using to_s for string conversion
|
||||
assert_equal( a.a3("ab"), 2 )
|
||||
assert_equal( a.a3("µ"), 2 ) # two UTF8 bytes
|
||||
if a.respond_to?(:a3_qstr)
|
||||
@@ -2198,19 +2212,9 @@ class Basic_TestClass < TestBase
|
||||
assert_equal(b.map1_cptr_null == nil, true);
|
||||
assert_equal(b.map1_ptr_null == nil, true);
|
||||
|
||||
begin
|
||||
b.map1 = { 42 => 1, -17 => true }
|
||||
error = nil
|
||||
rescue => ex
|
||||
error = ex.message.split("\n")[0]
|
||||
end
|
||||
if error == "can't convert Fixnum into String"
|
||||
# Ok
|
||||
elsif error == "no implicit conversion of Fixnum into String" || error == "no implicit conversion of Integer into String"
|
||||
# Ok
|
||||
else
|
||||
assert_equal(error, "")
|
||||
end
|
||||
b.map1 = { 42 => 1, -17 => true }
|
||||
assert_equal(b.map1.inspect, "{-17=>\"true\", 42=>\"1\"}")
|
||||
|
||||
b.map1 = { 42 => "1", -17 => "true" }
|
||||
assert_equal(b.map1.inspect, "{-17=>\"true\", 42=>\"1\"}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user