/usr/lib/python2.7/dist-packages/dicom/test/test_tag.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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | """Test suite for Tag.py"""
# 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
from dicom.tag import Tag, TupleTag
class Values(unittest.TestCase):
def testGoodInts(self):
"""Tags can be constructed with 4-byte integers.............."""
Tag(0x300a00b0)
Tag(0xFFFFFFEE)
def testGoodTuple(self):
"""Tags can be constructed with two-tuple of 2-byte integers."""
TupleTag((0xFFFF, 0xFFee))
tag = TupleTag((0x300a, 0x00b0))
self.assertEqual(tag.group, 0x300a, "Expected tag.group 0x300a, got %r" % tag.group)
def testAnyUnpack(self):
"""Tags can be constructed from list........................."""
Tag([2, 0])
def testBadTuple(self):
"""Tags: if a tuple, must be a 2-tuple......................."""
self.assertRaises(ValueError, Tag, (1, 2, 3, 4))
def testNonNumber(self):
"""Tags cannot be instantiated from a non-hex string........."""
self.assertRaises(ValueError, Tag, "hello")
def testHexString(self):
"""Tags can be instantiated from hex strings................."""
tag = Tag('0010', '0002')
self.assertEqual(tag.group, 16)
self.assertEqual(tag.elem, 2)
def testStr(self):
"""Tags have (gggg, eeee) string rep........................."""
self.assertTrue(str(Tag(0x300a00b0)) == "(300a, 00b0)")
def testGroup(self):
"""Tags' group and elem portions extracted properly.........."""
tag = Tag(0x300a00b0)
self.assertTrue(tag.group == 0x300a)
self.assertTrue(tag.elem == 0xb0)
self.assertTrue(tag.element == 0xb0)
def testZeroElem(self):
"""Tags with arg2=0 ok (was issue 47)........................"""
tag = Tag(2, 0)
self.assertTrue(tag.group == 2 and tag.elem == 0)
def testBadInts(self):
"""Tags constructed with > 8 bytes gives OverflowError......."""
self.assertRaises(OverflowError, Tag, 0x123456789)
class Comparisons(unittest.TestCase):
def setUp(self):
self.int1 = 0x300a00b0
self.tup1 = (0x300a, 0xb0)
self.tup3 = (0xFFFE, 0xFFFC)
self.t1 = Tag(self.int1)
self.t2 = Tag(self.tup1)
self.t3 = Tag(self.tup3)
def testCmpEq(self):
"""Tags compare correctly (==)..............................."""
self.assertTrue(self.t1 == self.int1, "tag t1 was not equal to int1")
self.assertTrue(self.t1 == self.t2, "tag t1 did not equal other tag")
self.assertTrue(self.t1 == self.tup1, "tag t1 did not equal its tuple")
def testCmpNotEq(self):
self.assertTrue(self.t1 != self.t3, "Not equal comparison failed")
def testCmpLT(self):
"""Tags compare correctly (<, >)............................."""
self.assertTrue(self.t1 < self.int1 + 1, "tag < failed")
self.assertTrue(self.int1 + 1 > self.t1, "int > tag failed")
self.assertTrue(self.t3 > self.t1, "'negative' int tag > other tag failed")
def testHash(self):
"""Tags hash the same as an int.............................."""
self.assertTrue(hash(self.t1) == hash(self.int1))
self.assertTrue(hash(self.t2) == hash(self.int1))
if __name__ == "__main__":
unittest.main()
|