Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_str(self):
"""Test str(BaseTag) produces correct value."""
self.assertEqual(str(BaseTag(0x00000000)), '(0000, 0000)')
self.assertEqual(str(BaseTag(0x00010002)), '(0001, 0002)')
self.assertEqual(str(BaseTag(0x10002000)), '(1000, 2000)')
self.assertEqual(str(BaseTag(0xFFFFFFFE)), '(ffff, fffe)')
def test_lt_tuple(self):
"""Test __lt__ of tuple with BaseTag."""
self.assertTrue(BaseTag(0x00010001) < (0x0001, 0x0002))
self.assertFalse(BaseTag(0x00010002) < (0x0001, 0x0002))
self.assertFalse(BaseTag(0x00010002) < (0x0001, 0x0001))
def test_str(self):
"""Test str(BaseTag) produces correct value."""
self.assertEqual(str(BaseTag(0x00000000)), '(0000, 0000)')
self.assertEqual(str(BaseTag(0x00010002)), '(0001, 0002)')
self.assertEqual(str(BaseTag(0x10002000)), '(1000, 2000)')
self.assertEqual(str(BaseTag(0xFFFFFFFE)), '(ffff, fffe)')
def test_ne_same_class(self):
"""Test __ne__ of two classes with same type."""
self.assertFalse(BaseTag(0x00000000) != BaseTag(0x00000000))
self.assertTrue(BaseTag(0x00000001) != BaseTag(0x00000000))
def test_le_tuple(self):
"""Test __le__ of tuple with BaseTag."""
self.assertTrue(BaseTag(0x00010001) <= (0x0001, 0x0002))
self.assertTrue(BaseTag(0x00010002) <= (0x0001, 0x0002))
self.assertFalse(BaseTag(0x00010002) <= (0x0001, 0x0001))
def test_group(self):
"""Test BaseTag.group returns correct values."""
self.assertEqual(BaseTag(0x00000001).group, 0x0000)
self.assertEqual(BaseTag(0x00020001).group, 0x0002)
self.assertEqual(BaseTag(0xFFFF0001).group, 0xFFFF)
def test_hash(self):
"""Test hash of BaseTag class."""
self.assertEqual(hash(BaseTag(0x00010001)),
hash(BaseTag(0x00010001)))
self.assertNotEqual(hash(BaseTag(0x00010001)),
hash(BaseTag(0x00010002)))
self.assertNotEqual(hash(BaseTag(0x00020001)),
hash(BaseTag(0x00010002)))
def test_tag_single_tuple(self):
"""Test creating a Tag from a single tuple."""
self.assertEqual(Tag((0x0000, 0x0000)), BaseTag(0x00000000))
self.assertEqual(Tag((0x22, 0xFF)), BaseTag(0x002200FF))
self.assertEqual(Tag((14, 0xF)), BaseTag(0x000E000F))
self.assertEqual(Tag((0x1000, 0x2000)), BaseTag(0x10002000))
self.assertEqual(Tag(('0x01', '0x02')), BaseTag(0x00010002))
# Must be 2 tuple
self.assertRaises(ValueError, Tag, (0x1000, 0x2000, 0x0030))
self.assertRaises(ValueError, Tag, ('0x10', '0x20', '0x03'))
# Must be 32-bit
self.assertRaises(OverflowError, Tag, (0xFFFF, 0xFFFF1))
self.assertRaises(OverflowError, Tag, ('0xFFFF', '0xFFFF1'))
# Must be positive
self.assertRaises(ValueError, Tag, (-1, 0))
self.assertRaises(ValueError, Tag, (0, -1))
self.assertRaises(ValueError, Tag, ('0x0', '-0x1'))
self.assertRaises(ValueError, Tag, ('-0x1', '0x0'))
# Can't have second parameter
self.assertRaises(ValueError, Tag, (0x01, 0x02), 0x01)
self.assertRaises(ValueError, Tag, (0x01, 0x02), '0x01')
long_value = int(arg, 16)
if long_value > 0xFFFFFFFF:
raise OverflowError("Tags are limited to 32-bit length; tag {0!r}"
.format(long_value))
# Single int parameter
else:
long_value = arg
if long_value > 0xFFFFFFFF:
raise OverflowError("Tags are limited to 32-bit length; tag {0!r}"
.format(long_value))
if long_value < 0:
raise ValueError("Tags must be positive.")
return BaseTag(long_value)
from pydicom.datadict import tag_for_keyword
long_value = tag_for_keyword(arg)
if long_value is None:
raise ValueError("'{}' is not a valid int or DICOM keyword"
.format(arg))
# Single int parameter
else:
long_value = arg
if long_value > 0xFFFFFFFF:
raise OverflowError("Tags are limited to 32-bit length; tag {0!r}"
.format(long_value))
if long_value < 0:
raise ValueError("Tags must be positive.")
return BaseTag(long_value)