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

        self.h = TransmittedElectronAzimuthalAngularDetectorXMLHandler()

        self.obj = TransmittedElectronAzimuthalAngularDetector(50)

        etree.register_namespace("mc", "http://pymontecarlo.sf.net")
        source = BytesIO(
            b'<mc:transmittedElectronAzimuthalAngularDetector xmlns:mc="http://pymontecarlo.sf.net"><channels>50</channels><limits lower="0.0" upper="6.283185307179586" /></mc:transmittedElectronAzimuthalAngularDetector>'
        )
        self.element = etree.parse(source).getroot()
Ejemplo n.º 2
0
class TestTransmittedElectronAzimuthalAngularDetectorXMLHandler(unittest.TestCase):
    def setUp(self):
        unittest.TestCase.setUp(self)

        self.h = TransmittedElectronAzimuthalAngularDetectorXMLHandler()

        self.obj = TransmittedElectronAzimuthalAngularDetector(50)

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

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