mirror of https://github.com/KLayout/klayout.git
Issue 771 (#773)
* Fixed the issue - Byte array variant was not properly converted to Python/Ruby objects. * Added tests + properly converting byte arrays to byte array variants in Python.
This commit is contained in:
parent
6a77c3ae9a
commit
e6ab8c2483
|
|
@ -282,10 +282,12 @@ tl::Variant python2c_func<tl::Variant>::operator() (PyObject *rval)
|
|||
return tl::Variant (python2c<std::string> (rval));
|
||||
#else
|
||||
} else if (PyBytes_Check (rval)) {
|
||||
return tl::Variant (python2c<std::string> (rval));
|
||||
return tl::Variant (python2c<std::vector<char> > (rval));
|
||||
#endif
|
||||
} else if (PyUnicode_Check (rval) || PyByteArray_Check (rval)) {
|
||||
} else if (PyUnicode_Check (rval)) {
|
||||
return tl::Variant (python2c<std::string> (rval));
|
||||
} else if (PyByteArray_Check (rval)) {
|
||||
return tl::Variant (python2c<std::vector<char> > (rval));
|
||||
} else if (PyList_Check (rval)) {
|
||||
|
||||
size_t len = PyList_Size (rval);
|
||||
|
|
@ -496,6 +498,8 @@ PyObject *c2python_func<const tl::Variant &>::operator() (const tl::Variant &c)
|
|||
return c2python (c.to_bool ());
|
||||
} else if (c.is_a_string ()) {
|
||||
return c2python (c.to_string ());
|
||||
} else if (c.is_a_bytearray ()) {
|
||||
return c2python (c.to_bytearray ());
|
||||
} else if (c.is_long ()) {
|
||||
return c2python (c.to_long ());
|
||||
} else if (c.is_ulong ()) {
|
||||
|
|
|
|||
|
|
@ -262,6 +262,8 @@ VALUE c2ruby<tl::Variant> (const tl::Variant &c)
|
|||
return c2ruby<bool> (c.to_bool ());
|
||||
} else if (c.is_a_string ()) {
|
||||
return c2ruby<std::string> (c.to_string ());
|
||||
} else if (c.is_a_bytearray ()) {
|
||||
return c2ruby<std::vector<char> > (c.to_bytearray ());
|
||||
} else if (c.is_long () || c.is_char ()) {
|
||||
return c2ruby<long> (c.to_long ());
|
||||
} else if (c.is_ulong ()) {
|
||||
|
|
|
|||
|
|
@ -1304,6 +1304,13 @@ class BasicTest(unittest.TestCase):
|
|||
self.assertEqual( str(b.b22c()), "hallo" )
|
||||
self.assertEqual( type(b.b22c()).__name__, "LayerInfo" )
|
||||
|
||||
# byte arrays through Variants
|
||||
if sys.version_info >= (3, 0):
|
||||
self.assertEqual( b.b22a( [ bytes('abc', 'utf-8') ] ), 1 )
|
||||
self.assertEqual( str(b.b22c()), "b'abc'" )
|
||||
self.assertEqual( str(b.b22d()), "b'abc'" )
|
||||
self.assertEqual( str(b.var()), "b'abc'" )
|
||||
|
||||
def test_23(self):
|
||||
|
||||
b = pya.B()
|
||||
|
|
|
|||
|
|
@ -629,6 +629,16 @@ class QtBindingTest(unittest.TestCase):
|
|||
self.assertEqual(len(buf.data) > 100, True)
|
||||
self.assertEqual(buf.data[0:8], b'\x89PNG\r\n\x1a\n')
|
||||
|
||||
def test_53(self):
|
||||
|
||||
# issue #771 (QMimeData not working)
|
||||
mimeData = pya.QMimeData()
|
||||
mimeData.setData("application/json",'{"test":"test"}')
|
||||
jsonData = mimeData.data("application/json");
|
||||
if sys.version_info < (3, 0):
|
||||
self.assertEqual(str(jsonData), '{"test":"test"}')
|
||||
else:
|
||||
self.assertEqual(str(jsonData), 'b\'{"test":"test"}\'')
|
||||
|
||||
# run unit tests
|
||||
if __name__ == '__main__':
|
||||
|
|
|
|||
|
|
@ -744,6 +744,17 @@ class QtBinding_TestClass < TestBase
|
|||
|
||||
end
|
||||
|
||||
def test_53
|
||||
|
||||
# issue #771 (QMimeData not working)
|
||||
|
||||
mimeData = RBA::QMimeData::new
|
||||
mimeData.setData("application/json", '{"test":"test"}')
|
||||
jsonData = mimeData.data("application/json");
|
||||
assert_equal(jsonData.to_s, '{"test":"test"}')
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
load("test_epilogue.rb")
|
||||
|
|
|
|||
Loading…
Reference in New Issue