MCPcopy Create free account
hub / github.com/OpenMS/OpenMS / testString

Function testString

src/pyOpenMS/tests/unittests/test000.py:5478–5580  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

5476
5477@report
5478def testString():
5479 pystr = pyopenms.String()
5480 pystr = pyopenms.String("blah")
5481 assert (pystr.toString() == "blah")
5482 pystr = pyopenms.String("blah")
5483 assert (pystr.toString() == "blah")
5484 pystr = pyopenms.String(u"blah")
5485 assert (pystr.toString() == "blah")
5486 pystr = pyopenms.String(pystr)
5487 assert (pystr.toString() == "blah")
5488 assert (len(pystr.toString()) == 4)
5489 cstr = pystr.c_str()
5490
5491 # Printing should work ...
5492 print(cstr)
5493 print(pystr)
5494 print(pystr.toString())
5495 assert (pystr.toString() == "blah")
5496
5497 pystr = pyopenms.String("bläh")
5498 assert (pystr.toString() == u"bläh")
5499 pystr = pyopenms.String("bläh")
5500 pystr = pyopenms.String(u"bläh")
5501 assert (pystr.toString() == u"bläh")
5502 pystr = pyopenms.String(pystr)
5503 assert (pystr.toString() == u"bläh")
5504 cstr = pystr.c_str()
5505
5506 # Printing should work ...
5507 print(cstr)
5508 print(pystr)
5509 print(pystr.toString().encode("utf8"))
5510
5511 assert len(pystr.toString()) == 4
5512 assert len(pystr.c_str()) == 5 # C does not know about Unicode, so be careful with c_str
5513 print(pystr) # this prints the C string, due to Py 2/3 compatibility
5514 print(pystr.toString().encode("utf8")) # this prints the correct String
5515
5516 pystr1 = pyopenms.String("bläh")
5517 pystr2 = pyopenms.String("bläh")
5518 assert(pystr1 == pystr2)
5519
5520 pystr1 = pyopenms.String(u"bläh")
5521 pystr2 = pyopenms.String(u"bläh")
5522 assert(pystr1 == pystr2)
5523
5524 # Handling of different Unicode Strings:
5525 # - unicode is natively stored in OpenMS::String
5526 # - encoded bytesequences for utf8, utf16 and iso8859 can be stored as
5527 # char arrays in OpenMS::String (and be accessed using c_str())
5528 # - encoded bytesequences for anything other than utf8 cannot use
5529 # "toString()" as this function expects utf8
5530 ustr = u"bläh"
5531 pystr = pyopenms.String(ustr)
5532 assert (pystr.toString() == u"bläh")
5533 pystr = pyopenms.String(ustr.encode("utf8"))
5534 assert (pystr.toString() == u"bläh")
5535

Callers

nothing calls this directly

Calls 7

encodeMethod · 0.80
decodeMethod · 0.80
MSSpectrumMethod · 0.80
getNativeIDMethod · 0.80
StringMethod · 0.45
toStringMethod · 0.45
setNativeIDMethod · 0.45

Tested by

no test coverage detected