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 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
|
#/*##########################################################################
#
# The PyMca X-Ray Fluorescence Toolkit
#
# Copyright (c) 2004-2014 European Synchrotron Radiation Facility
#
# This file is part of the PyMca X-ray Fluorescence Toolkit developed at
# the ESRF by the Software group.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
#############################################################################*/
__author__ = "V. Armando Sole - ESRF Data Analysis"
__contact__ = "sole@esrf.fr"
__license__ = "MIT"
__copyright__ = "European Synchrotron Radiation Facility, Grenoble, France"
import unittest
import os
import sys
import numpy
class testData(unittest.TestCase):
ELEMENTS = ['H', 'He',
'Li', 'Be', 'B', 'C', 'N', 'O', 'F', 'Ne',
'Na', 'Mg', 'Al', 'Si', 'P', 'S', 'Cl', 'Ar',
'K', 'Ca', 'Sc', 'Ti', 'V', 'Cr', 'Mn', 'Fe',
'Co', 'Ni', 'Cu', 'Zn', 'Ga', 'Ge', 'As', 'Se',
'Br', 'Kr', 'Rb', 'Sr', 'Y', 'Zr', 'Nb', 'Mo',
'Tc', 'Ru', 'Rh', 'Pd', 'Ag', 'Cd', 'In', 'Sn',
'Sb', 'Te', 'I', 'Xe', 'Cs', 'Ba', 'La', 'Ce',
'Pr', 'Nd', 'Pm', 'Sm', 'Eu', 'Gd', 'Tb', 'Dy',
'Ho', 'Er', 'Tm', 'Yb', 'Lu', 'Hf', 'Ta', 'W',
'Re', 'Os', 'Ir', 'Pt', 'Au', 'Hg', 'Tl', 'Pb',
'Bi', 'Po', 'At', 'Rn', 'Fr', 'Ra', 'Ac', 'Th',
'Pa', 'U', 'Np', 'Pu', 'Am', 'Cm', 'Bk', 'Cf',
'Es', 'Fm', 'Md', 'No', 'Lr', 'Rf', 'Db', 'Sg',
'Bh', 'Hs', 'Mt']
def setUp(self):
"""
Get the data directory
"""
self._importSuccess = False
try:
from PyMca5 import PyMcaDataDir
self._importSuccess = True
self.dataDir = PyMcaDataDir.PYMCA_DATA_DIR
except:
self.dataDir = None
try:
self.docDir = PyMcaDataDir.PYMCA_DOC_DIR
except:
self.docDir = None
def testDataDirectoryPresence(self):
self.assertTrue(self._importSuccess,
'Unsuccessful PyMca5.PyMcaDataDir import')
self.assertTrue(self.dataDir is not None,
'Unassigned PyMca5.PyMcaDataDir.PYMCA_DATA_DIR')
self.assertTrue(os.path.exists(self.dataDir),
'Directory "%s" does not exist' % self.dataDir)
self.assertTrue(os.path.isdir(self.dataDir),
'"%s" expected to be a directory' % self.dataDir)
def testFisxDataDirectoryPresence(self):
try:
from fisx import DataDir
dataDir = DataDir.FISX_DATA_DIR
except:
dataDir = None
self.assertTrue(dataDir is not None,
'fisx module not properly installed')
self.assertTrue(os.path.exists(dataDir),
'fisx directory "%s" does not exist' % dataDir)
self.assertTrue(os.path.isdir(dataDir),
'"%s" expected to be a directory' % dataDir)
for fname in ['BindingEnergies.dat',
'EADL97_BindingEnergies.dat',
'EADL97_KShellConstants.dat',
'EADL97_LShellConstants.dat',
'EADL97_MShellConstants.dat',
'EPDL97_CrossSections.dat',
'KShellConstants.dat',
'KShellRates.dat',
'LShellConstants.dat',
'LShellRates.dat',
'MShellConstants.dat',
'MShellRates.dat',
'XCOM_CrossSections.dat']:
actualName = os.path.join(dataDir, fname)
self.assertTrue(os.path.exists(actualName),
'File "%s" does not exist.' % actualName)
self.assertTrue(os.path.isfile(actualName),
'File "%s" is not an actual file.' % actualName)
def testDataFilePresence(self):
# Testing file presence
self.testDataDirectoryPresence()
for fname in ['LShellRatesCampbell.dat',
'LShellRatesScofieldHS.dat',
'McaTheory.cfg',
'Scofield1973.dict',
'XRFSpectrum.mca',
'Steel.cfg', 'Steel.spe']:
actualName = os.path.join(self.dataDir, fname)
self.assertTrue(os.path.exists(actualName),
'File "%s" does not exist.' % actualName)
self.assertTrue(os.path.isfile(actualName),
'File "%s" is not an actual file.' % actualName)
actualName = os.path.join(self.dataDir, 'attdata')
self.assertTrue(os.path.exists(actualName),
'Directory "%s" does not exist' % actualName)
self.assertTrue(os.path.isdir(actualName),
'"%s" expected to be a directory' % actualName)
for i in range(92):
fname = "%s%s" % (testData.ELEMENTS[i], ".mat")
actualName = os.path.join(self.dataDir, 'attdata', fname)
self.assertTrue(os.path.exists(actualName),
'File "%s" does not exist.' % actualName)
self.assertTrue(os.path.isfile(actualName),
'File "%s" is not an actual file.' % actualName)
def testDocDirectoryPresence(self):
self.assertTrue(self._importSuccess,
'Unsuccessful PyMca5.PyMcaDataDir import')
self.assertTrue(self.docDir is not None,
'Unassigned PyMca5.PyMcaDataDir.PYMCA_DOC_DIR')
self.assertTrue(os.path.exists(self.dataDir),
'Directory "%s" does not exist' % self.docDir)
self.assertTrue(os.path.isdir(self.dataDir),
'"%s" expected to be a directory' % self.docDir)
def getSuite(auto=True):
testSuite = unittest.TestSuite()
if auto:
testSuite.addTest(unittest.TestLoader().loadTestsFromTestCase(testData))
else:
# use a predefined order
testSuite.addTest(testData("testFisxDataDirectoryPresence"))
testSuite.addTest(testData("testDataDirectoryPresence"))
testSuite.addTest(testData("testDataFilePresence"))
testSuite.addTest(testData("testDocDirectoryPresence"))
return testSuite
def test(auto=False):
unittest.TextTestRunner(verbosity=2).run(getSuite(auto=auto))
if __name__ == '__main__':
test()
|