]> Creatis software - gdcm.git/blob - gdcmPython/testSuite.py
Fix mistypings
[gdcm.git] / gdcmPython / testSuite.py
1 import unittest
2 import os
3 from gdcmPython import *
4 if os.name == 'posix':
5    from libvtkgdcmPython import *
6 else:
7    from vtkgdcmPython import *
8
9 class gdcmTestCase(unittest.TestCase):
10    # The files whose name starts with a modality (e.g. CR-MONO1-10-chest.dcm)
11    # come from Sebastien Barre's Dicom2 highly recommendable site
12    # http://www.barre.nom.fr/medical/samples/index.html
13
14    MultiFrameFiles = [
15
16    GdcmFiles = [
17       # FOLLOWING FILE NOT IN GDCMDATA ANYMORE !?!?!?!
18       ["gdcm-MR-PHILIPS-16.dcm",
19          # Interest: - possesses a sequence
20          #           - dicom file, with a recognition code of ACR-NEMA1
21          [ ["Transfer Syntax UID", "1.2.840.10008.1.2"],  # Implicit VR, LE
22            ["Recognition Code (RET)", "ACR-NEMA 1.0"],
23            ["Modality", "MR"],
24            ["Photometric Interpretation", "MONOCHROME2"],
25            ["Rows", "256"],
26            ["Columns", "256"],
27            ["Bits Stored", "8"],
28            ["Bits Allocated", "16"],
29            ["High Bit", "7"],
30            ["Pixel Representation", "0"],
31            ["Manufacturer", "Philips Medical Systems"],
32            ["Manufacturer's Model Name", "Gyroscan Intera"],
33            ["Sequence Variant", "OTHER"],
34            ["Pixel Data", "gdcm::NotLoaded. Address:6584 Length:131072 x(20000)"]
35           ] ],
36    ]
37
38    def _BaseTest(self, FileSet):
39       for entry in FileSet:
40          fileName = os.path.join(GDCM_TEST_DATA_PATH, entry[0])
41          reader = gdcmFile(fileName)
42          assert reader.IsReadable(),\
43                 "File '%s' is not readable by gdcmFile" % fileName
44
45          valDict = reader.GetEntryValue()
46          for subEntry in entry[1]:
47             element = subEntry[0]
48             value   = subEntry[1]
49             self.assertEqual(valDict[element], value,
50                              ("Wrong %s for file %s (got %s, shoud be %s)"
51                              % (element,fileName, valDict[element], value)) )
52
53    def testFiles(self):
54       gdcmTestCase._BaseTest(self, gdcmTestCase.GdcmFiles)
55
56 if __name__ == '__main__':
57    if not GDCM_TEST_DATA_PATH:
58       print "GDCM_TEST_DATA_PATH (internal variable) is not setup properly."
59       print "   This test suite requires that some Dicom reference files be "
60       print "   installed."
61       print "   For further details on installation of gdcmData, please"
62       print "   refer to the developper's section of page "
63       print "       http://www.creatis.insa-lyon.fr/Public/Gdcm"
64       print ""
65       print "gdcmData directory (used in the test suite) must be placed in"
66       print "the gdcm directory. The gdcm tree must be :"
67       print "   gdcm"
68       print "    |____Dicts"
69       print "    |____Doc"
70       print "    |____gdcmData      (not in gdcm by default)"
71       print "    |____gdcmPython"
72       print "    |____Test"
73    else:
74       unittest.main()
75