示例#1
0
class TestUserDefinedMassAbsorptionCoefficientModelXMLHandler(unittest.TestCase):

    def setUp(self):
        unittest.TestCase.setUp(self)

        self.h = UserDefinedMassAbsorptionCoefficientModelXMLHandler()

        self.obj = UserDefinedMassAbsorptionCoefficientModel(MASS_ABSORPTION_COEFFICIENT.henke1993, 'ref1')
        self.obj.add(29, 8.904e3, 200)
        self.obj.add(29, Transition(29, siegbahn='Ka1'), 201)

        etree.register_namespace('mc', 'http://pymontecarlo.sf.net')
        source = BytesIO(b'<mc:userDefinedMassAbsorptionCoefficientModel xmlns:mc="http://pymontecarlo.sf.net" name="user defined mass absorption coefficient" reference="ref1" type="mass absorption coefficient"><mc:model name="Henke 1993" reference="B.L. Henke, E.M. Gullikson and J.C. Davis (1993). X-ray interactions: photoabsorption, scattering, transmission, and reflection at E=50-30000 eV, Z=1-92, Atomic Data and Nuclear Data Tables, 54, pp. 181-342" type="mass absorption coefficient" /><mac absorber="29" energy="8904.0">200</mac><mac absorber="29" z="29" src="4" dest="1">201</mac></mc:userDefinedMassAbsorptionCoefficientModel>')
        self.element = etree.parse(source).getroot()

    def tearDown(self):
        unittest.TestCase.tearDown(self)

    def testcan_parse(self):
        self.assertTrue(self.h.can_parse(self.element))

    def testparse(self):
        obj = self.h.parse(self.element)

        self.assertEqual('user defined mass absorption coefficient', obj.name)
        self.assertEqual('ref1', obj.reference)
        self.assertEqual(MASS_ABSORPTION_COEFFICIENT, obj.type)

        self.assertIs(MASS_ABSORPTION_COEFFICIENT.henke1993, obj.base_model)

        self.assertEqual(2, len(obj.defined_macs))
        self.assertAlmostEqual(200.0, obj.defined_macs[(29, 8.904e3)], 4)
        self.assertAlmostEqual(201.0, obj.defined_macs[(29, Transition(29, siegbahn='Ka1'))], 4)

    def testcan_convert(self):
        self.assertTrue(self.h.can_convert(self.obj))

    def testconvert(self):
        element = self.h.convert(self.obj)

        self.assertEqual('user defined mass absorption coefficient', element.get('name'))
        self.assertEqual(str(MASS_ABSORPTION_COEFFICIENT), element.get('type'))

        subelement = element.find('{http://pymontecarlo.sf.net}model')
        self.assertEqual('Henke 1993', subelement.get('name'))

        subelements = list(element.iter('mac'))
        self.assertEqual(2, len(subelements))
示例#2
0
    def setUp(self):
        unittest.TestCase.setUp(self)

        self.h = UserDefinedMassAbsorptionCoefficientModelXMLHandler()

        self.obj = UserDefinedMassAbsorptionCoefficientModel(MASS_ABSORPTION_COEFFICIENT.henke1993, 'ref1')
        self.obj.add(29, 8.904e3, 200)
        self.obj.add(29, Transition(29, siegbahn='Ka1'), 201)

        etree.register_namespace('mc', 'http://pymontecarlo.sf.net')
        source = BytesIO(b'<mc:userDefinedMassAbsorptionCoefficientModel xmlns:mc="http://pymontecarlo.sf.net" name="user defined mass absorption coefficient" reference="ref1" type="mass absorption coefficient"><mc:model name="Henke 1993" reference="B.L. Henke, E.M. Gullikson and J.C. Davis (1993). X-ray interactions: photoabsorption, scattering, transmission, and reflection at E=50-30000 eV, Z=1-92, Atomic Data and Nuclear Data Tables, 54, pp. 181-342" type="mass absorption coefficient" /><mac absorber="29" energy="8904.0">200</mac><mac absorber="29" z="29" src="4" dest="1">201</mac></mc:userDefinedMassAbsorptionCoefficientModel>')
        self.element = etree.parse(source).getroot()