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

        self.h = TransmittedElectronPolarAngularDetectorXMLHandler()

        self.obj = TransmittedElectronPolarAngularDetector(50)

        etree.register_namespace("mc", "http://pymontecarlo.sf.net")
        source = BytesIO(
            b'<mc:transmittedElectronPolarAngularDetector xmlns:mc="http://pymontecarlo.sf.net"><channels>50</channels><limits lower="-1.5707963267948966" upper="1.5707963267948966" /></mc:transmittedElectronPolarAngularDetector>'
        )
        self.element = etree.parse(source).getroot()
Esempio n. 2
0
class TestTransmittedElectronPolarAngularDetectorXMLHandler(unittest.TestCase):
    def setUp(self):
        unittest.TestCase.setUp(self)

        self.h = TransmittedElectronPolarAngularDetectorXMLHandler()

        self.obj = TransmittedElectronPolarAngularDetector(50)

        etree.register_namespace("mc", "http://pymontecarlo.sf.net")
        source = BytesIO(
            b'<mc:transmittedElectronPolarAngularDetector xmlns:mc="http://pymontecarlo.sf.net"><channels>50</channels><limits lower="-1.5707963267948966" upper="1.5707963267948966" /></mc:transmittedElectronPolarAngularDetector>'
        )
        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.assertAlmostEqual(radians(-90), obj.limits_rad[0], 4)
        self.assertAlmostEqual(radians(90), obj.limits_rad[1], 4)
        self.assertEqual(50, obj.channels)

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

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

        subelement = element.find("limits")
        self.assertAlmostEqual(radians(-90), float(subelement.get("lower")), 4)
        self.assertAlmostEqual(radians(90), float(subelement.get("upper")), 4)

        subelement = element.find("channels")
        self.assertEqual(50, int(subelement.text))