/usr/lib/python2.7/dist-packages/dicom/test/test_valuerep.py is in python-dicom 0.9.9-2.
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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | # test_valuerep.py
"""Test suite for valuerep.py"""
# Copyright (c) 2008-2012 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
from dicom import in_py3
import dicom.config
if in_py3:
from dicom.valuerep import PersonName3 as PersonNameUnicode
PersonName = PersonNameUnicode
else:
from dicom.valuerep import PersonName, PersonNameUnicode
default_encoding = 'iso8859'
class DecimalStringtests(unittest.TestCase):
"""Unit tests unique to the use of DS class derived from python Decimal"""
def setUp(self):
dicom.config.DS_decimal(True)
def tearDown(self):
dicom.config.DS_decimal(False)
def testValidDecimalStrings(self):
# Ensures that decimal.Decimal doesn't cause a valid string to become
# invalid
valid_str = '-9.81338674e-006'
ds = dicom.valuerep.DS(valid_str)
L = len(str(ds))
self.assertTrue(L <= 16, "DS: expected a string of length 16 but got %d" % (L,))
# Now the input string is too long but decimal.Decimal can convert it
# to a valid 16-character string
long_str = '-0.000000981338674'
ds = dicom.valuerep.DS(long_str)
L = len(str(ds))
self.assertTrue(L <= 16, "DS: expected a string of length 16 but got %d" % (L,))
def testInvalidDecimalStrings(self):
# Now the input string truly is invalid
invalid_string = '-9.813386743e-006'
self.assertRaises(OverflowError, dicom.valuerep.DS, invalid_string)
class PersonNametests(unittest.TestCase):
def testLastFirst(self):
"""PN: Simple Family-name^Given-name works..............................."""
pn = PersonName("Family^Given")
expected = "Family"
got = pn.family_name
self.assertEqual(got, expected, "PN: expected '%s', got '%s' for family name" % (expected, got))
expected = 'Given'
got = pn.given_name
self.assertEqual(got, expected, "PN: expected '%s', got '%s' for given name" % (expected, got))
expected = ''
got = pn.name_suffix
self.assertEqual(got, expected, "PN: expected '%s', got '%s' for name_suffix" % (expected, got))
expected = ''
got = pn.phonetic
self.assertEqual(got, expected, "PN: expected '%s', got '%s' for phonetic component" % (expected, got))
def testThreeComponent(self):
"""PN: 3component (single-byte, ideographic, phonetic characters) works.."""
# Example name from PS3.5-2008 section I.2 p. 108
pn = PersonName("""Hong^Gildong=\033$)C\373\363^\033$)C\321\316\324\327=\033$)C\310\253^\033$)C\261\346\265\277""")
expected = ("Hong", "Gildong")
got = (pn.family_name, pn.given_name)
self.assertEqual(got, expected, "PN: Expected single_byte name '%s', got '%s'" % (expected, got))
def testFormatting(self):
"""PN: Formatting works.................................................."""
pn = PersonName("Family^Given")
expected = "Family, Given"
got = pn.family_comma_given()
self.assertEqual(got, expected, "PN: expected '%s', got '%s' for formatted Family, Given" % (expected, got))
def testUnicodeKr(self):
"""PN: 3component in unicode works (Korean).............................."""
# Example name from PS3.5-2008 section I.2 p. 101
pn = PersonNameUnicode(
"""Hong^Gildong=\033$)C\373\363^\033$)C\321\316\324\327=\033$)C\310\253^\033$)C\261\346\265\277""",
[default_encoding, 'euc_kr'])
expected = ("Hong", "Gildong")
got = (pn.family_name, pn.given_name)
self.assertEqual(got, expected, "PN: Expected single_byte name '{0!s}', got '{1!s}'".format(expected, got))
def testUnicodeJp(self):
"""PN: 3component in unicode works (Japanese)............................"""
# Example name from PS3.5-2008 section H p. 98
pn = PersonNameUnicode(
"""Yamada^Tarou=\033$B;3ED\033(B^\033$BB@O:\033(B=\033$B$d$^$@\033(B^\033$B$?$m$&\033(B""",
[default_encoding, 'iso2022_jp'])
expected = ("Yamada", "Tarou")
got = (pn.family_name, pn.given_name)
self.assertEqual(got, expected, "PN: Expected single_byte name '{0!s}', got '{1!s}'".format(expected, got))
def testNotEqual(self):
"""PN3: Not equal works correctly (issue 121)..........................."""
# Meant to only be used in python 3 but doing simple check here
from dicom.valuerep import PersonName3
pn = PersonName3("John^Doe")
msg = "PersonName3 not equal comparison did not work correctly"
self.assertFalse(pn != "John^Doe", msg)
if __name__ == "__main__":
unittest.main()
|