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

        self.h = PhotonSpectrumDetectorXMLHandler()

        self.obj = PhotonSpectrumDetector((radians(35), radians(45)), (0, radians(360.0)), 1000, (12.34, 56.78))

        etree.register_namespace("mc", "http://pymontecarlo.sf.net")
        source = BytesIO(
            b'<mc:photonSpectrumDetector xmlns:mc="http://pymontecarlo.sf.net"><elevation lower="0.6108652381980153" upper="0.7853981633974483" /><azimuth lower="0.0" upper="6.283185307179586" /><channels>1000</channels><limits lower="12.34" upper="56.78" /></mc:photonSpectrumDetector>'
        )
        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(35), obj.elevation_rad[0], 4)
        self.assertAlmostEqual(radians(45), obj.elevation_rad[1], 4)
        self.assertAlmostEqual(0, obj.azimuth_rad[0], 4)
        self.assertAlmostEqual(radians(360.0), obj.azimuth_rad[1], 4)
        self.assertAlmostEqual(12.34, obj.limits_eV[0], 4)
        self.assertAlmostEqual(56.78, obj.limits_eV[1], 4)
        self.assertEqual(1000, 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("elevation")
        self.assertAlmostEqual(radians(35), float(subelement.get("lower")), 4)
        self.assertAlmostEqual(radians(45), float(subelement.get("upper")), 4)

        subelement = element.find("azimuth")
        self.assertAlmostEqual(0, float(subelement.get("lower")), 4)
        self.assertAlmostEqual(radians(360.0), float(subelement.get("upper")), 4)

        subelement = element.find("limits")
        self.assertAlmostEqual(12.34, float(subelement.get("lower")), 4)
        self.assertAlmostEqual(56.78, float(subelement.get("upper")), 4)

        subelement = element.find("channels")
        self.assertEqual(1000, int(subelement.text))
Ejemplo n.º 2
0
    def setUp(self):
        unittest.TestCase.setUp(self)

        self.h = PhotonSpectrumDetectorXMLHandler()

        self.obj = PhotonSpectrumDetector((radians(35), radians(45)), (0, radians(360.0)), 1000, (12.34, 56.78))

        etree.register_namespace("mc", "http://pymontecarlo.sf.net")
        source = BytesIO(
            b'<mc:photonSpectrumDetector xmlns:mc="http://pymontecarlo.sf.net"><elevation lower="0.6108652381980153" upper="0.7853981633974483" /><azimuth lower="0.0" upper="6.283185307179586" /><channels>1000</channels><limits lower="12.34" upper="56.78" /></mc:photonSpectrumDetector>'
        )
        self.element = etree.parse(source).getroot()