/usr/lib/python2.7/dist-packages/dicom/test/test_charset.py is in python-dicom 0.9.9-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | # -*- coding: latin_1 -*-
# test_charset.py
"""unittest cases for dicom.charset module"""
# Copyright (c) 2008 Darcy Mason
# This file is part of pydicom, released under a modified MIT license.
# See the file license.txt included with this distribution, also
# available at http://pydicom.googlecode.com
import unittest
import dicom
import os.path
from pkg_resources import Requirement, resource_filename
testcharset_dir = resource_filename(Requirement.parse("pydicom"),
"dicom/testcharsetfiles")
latin1_file = os.path.join(testcharset_dir, "chrFren.dcm")
jp_file = os.path.join(testcharset_dir, "chrH31.dcm")
multiPN_file = os.path.join(testcharset_dir, "chrFrenMulti.dcm")
sq_encoding_file = os.path.join(testcharset_dir, "chrSQEncoding.dcm")
test_dir = resource_filename(Requirement.parse("pydicom"), "dicom/testfiles")
normal_file = os.path.join(test_dir, "CT_small.dcm")
class charsetTests(unittest.TestCase):
def testLatin1(self):
"""charset: can read and decode latin_1 file........................"""
ds = dicom.read_file(latin1_file)
ds.decode()
# Make sure don't get unicode encode error on converting to string
expected = u'Buc^J\xe9r\xf4me'
got = ds.PatientName
self.assertEqual(expected, got,
"Expected %r, got %r" % (expected, got))
def testNestedCharacterSets(self):
"""charset: can read and decode SQ with different encodings........."""
ds = dicom.read_file(sq_encoding_file)
ds.decode()
# These datasets inside of the SQ cannot be decoded with default_encoding
# OR UTF-8 (the parent dataset's encoding). Instead, we make sure that it
# is decoded using the (0008,0005) tag of the dataset
expected = u'\uff94\uff8f\uff80\uff9e^\uff80\uff9b\uff73=\u5c71\u7530^\u592a\u90ce=\u3084\u307e\u3060^\u305f\u308d\u3046'
got = ds[0x32, 0x1064][0].PatientName
self.assertEqual(expected, got,
"Expected %r, got %r" % (expected, got))
def testStandardFile(self):
"""charset: can read and decode standard file without special char.."""
ds = dicom.read_file(normal_file)
ds.decode()
def testMultiPN(self):
"""charset: can decode file with multi-valued data elements........."""
ds = dicom.read_file(multiPN_file)
ds.decode()
if __name__ == "__main__":
# This is called if run alone, but not if loaded through run_tests.py
# If not run from the directory where the sample images are,
# then need to switch there
import sys
import os
import os.path
dir_name = os.path.dirname(sys.argv[0])
save_dir = os.getcwd()
if dir_name:
os.chdir(dir_name)
os.chdir("../testfiles")
unittest.main()
os.chdir(save_dir)
|