Exemplo n.º 1
0
    def setUp(self):
        unittest.TestCase.setUp(self)

        self.h = UncertaintyLimitXMLHandler()

        self.obj = UncertaintyLimit(Transition(29, siegbahn='Ka1'), 'det1', 0.05)

        etree.register_namespace('mc', 'http://pymontecarlo.sf.net')
        source = BytesIO(b'<mc:uncertaintyLimit xmlns:mc="http://pymontecarlo.sf.net" detector_key="det1" uncertainty="0.05"><transition dest="1" src="4" z="29" /></mc:uncertaintyLimit>')
        self.element = etree.parse(source).getroot()
Exemplo n.º 2
0
class TestUncertaintyLimitXMLHandler(unittest.TestCase):

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

        self.h = UncertaintyLimitXMLHandler()

        self.obj = UncertaintyLimit(Transition(29, siegbahn='Ka1'), 'det1', 0.05)

        etree.register_namespace('mc', 'http://pymontecarlo.sf.net')
        source = BytesIO(b'<mc:uncertaintyLimit xmlns:mc="http://pymontecarlo.sf.net" detector_key="det1" uncertainty="0.05"><transition dest="1" src="4" z="29" /></mc:uncertaintyLimit>')
        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('Cu K\u03b11', str(obj.transition))
        self.assertEqual('det1', obj.detector_key)
        self.assertAlmostEqual(0.05, obj.uncertainty, 4)

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

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

        subelement = list(element.findall('transition'))[0]
        self.assertEqual(29, int(subelement.get('z')))
        self.assertEqual(4, int(subelement.get('src')))
        self.assertEqual(1, int(subelement.get('dest')))

        self.assertEqual('det1', element.get('detector_key'))

        self.assertAlmostEqual(0.05, float(element.get('uncertainty')), 4)