def test_encoding_carried(self): """Test encoding is carried over to a new PN3 object""" # Issue 466 from pydicom.valuerep import PersonName3 pn = PersonName3("John^Doe", encodings='iso_ir_126') assert pn.encodings == ('iso_ir_126',) pn2 = PersonName3(pn) assert pn2.encodings == ('iso_ir_126',)
def test_unicode_jp_from_bytes_comp_delimiter(self): """The example encoding without the escape sequence before '='""" pn = PersonNameUnicode(b'Yamada^Tarou=' b'\033$B;3ED\033(B^\033$BB@O:=' b'\033$B$d$^$@\033(B^\033$B$?$m$&\033(B', [default_encoding, 'iso2022_jp']) if not in_py2: pn = pn.decode() assert (u'Yamada', u'Tarou') == (pn.family_name, pn.given_name) assert u'山田^太郎' == pn.ideographic assert u'やまだ^たろう' == pn.phonetic
def test_unicode_jp_from_bytes_caret_delimiter(self): """PN: 3component in unicode works (Japanese)...""" # Example name from PS3.5-2008 section H p. 98 pn = PersonNameUnicode(b'Yamada^Tarou=' b'\033$B;3ED\033(B^\033$BB@O:\033(B=' b'\033$B$d$^$@\033(B^\033$B$?$m$&\033(B', [default_encoding, 'iso2022_jp']) if not in_py2: pn = pn.decode() assert (u'Yamada', u'Tarou') == (pn.family_name, pn.given_name) assert u'山田^太郎' == pn.ideographic assert u'やまだ^たろう' == pn.phonetic
def test_unicode_kr(self): """PN: 3component in unicode works (Korean)...""" # Example name from PS3.5-2008 section I.2 p. 101 pn = PersonNameUnicode(b'Hong^Gildong=' b'\033$)C\373\363^\033$)C\321\316\324\327=' b'\033$)C\310\253^\033$)C\261\346\265\277', [default_encoding, 'euc_kr']) # PersonNameUnicode and PersonName3 behave differently: # PersonName3 does not decode the components automatically if not in_py2: pn = pn.decode() assert (u'Hong', u'Gildong') == (pn.family_name, pn.given_name) assert u'洪^吉洞' == pn.ideographic assert u'홍^길동' == pn.phonetic
def testNotEqual(self): """PN3: Not equal works correctly (issue 121)...""" # Meant to only be used in python 3 but doing simple check here from pydicom.valuerep import PersonName3 pn = PersonName3("John^Doe") msg = "PersonName3 not equal comparison did not work correctly" self.assertFalse(pn != "John^Doe", msg)
def test_japanese_multi_byte_personname(self): """Test japanese person name which has multi byte strings are correctly encoded.""" file_path = get_charset_files('chrH32.dcm')[0] ds = dcmread(file_path) ds.decode() if hasattr(ds.PatientName, 'original_string'): original_string = ds.PatientName.original_string ds.PatientName.original_string = None fp = DicomBytesIO() fp.is_implicit_VR = False fp.is_little_endian = True ds.save_as(fp, write_like_original=False) fp.seek(0) ds_out = dcmread(fp) assert original_string == ds_out.PatientName.original_string japanese_pn = PersonName3(u"Mori^Ogai=森^鷗外=もり^おうがい") pyencs = pydicom.charset.convert_encodings( ["ISO 2022 IR 6", "ISO 2022 IR 87", "ISO 2022 IR 159"]) actual_encoded = bytes(japanese_pn.encode(pyencs)) expect_encoded = ( b"\x4d\x6f\x72\x69\x5e\x4f\x67\x61\x69\x3d\x1b\x24\x42\x3f" b"\x39\x1b\x28\x42\x5e\x1b\x24\x28\x44\x6c\x3f\x1b\x24\x42" b"\x33\x30\x1b\x28\x42\x3d\x1b\x24\x42\x24\x62\x24\x6a\x1b" b"\x28\x42\x5e\x1b\x24\x42\x24\x2a\x24\x26\x24\x2c\x24\x24" b"\x1b\x28\x42") assert expect_encoded == actual_encoded
def test_not_equal(self): """PN3: Not equal works correctly (issue 121)...""" # Meant to only be used in python 3 but doing simple check here from pydicom.valuerep import PersonName3 pn = PersonName3("John^Doe") assert not pn != "John^Doe"