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

        self.h = PhotonIntensityDetectorXMLHandler()

        self.obj = PhotonIntensityDetector((radians(35), radians(45)), (0, radians(360.0)))

        etree.register_namespace("mc", "http://pymontecarlo.sf.net")
        source = BytesIO(
            b'<mc:photonIntensityDetector xmlns:mc="http://pymontecarlo.sf.net"><elevation lower="0.6108652381980153" upper="0.7853981633974483" /><azimuth lower="0.0" upper="6.283185307179586" /><transitions/></mc:photonIntensityDetector>'
        )
        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)

    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)
Exemplo n.º 2
0
    def setUp(self):
        unittest.TestCase.setUp(self)

        self.h = PhotonIntensityDetectorXMLHandler()

        self.obj = PhotonIntensityDetector((radians(35), radians(45)), (0, radians(360.0)))

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