class TestPhotonDepthDetectorXMLHandler(unittest.TestCase): def setUp(self): unittest.TestCase.setUp(self) self.h = PhotonDepthDetectorXMLHandler() self.obj = PhotonDepthDetector((radians(35), radians(45)), (0, radians(360.0)), 1000) etree.register_namespace("mc", "http://pymontecarlo.sf.net") source = BytesIO( b'<mc:photonDepthDetector xmlns:mc="http://pymontecarlo.sf.net"><elevation lower="0.6108652381980153" upper="0.7853981633974483" /><azimuth lower="0.0" upper="6.283185307179586" /><channels>1000</channels><transitions/></mc:photonDepthDetector>' ) 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.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("channels") self.assertEqual(1000, int(subelement.text))
def setUp(self): unittest.TestCase.setUp(self) self.h = PhotonDepthDetectorXMLHandler() self.obj = PhotonDepthDetector((radians(35), radians(45)), (0, radians(360.0)), 1000) etree.register_namespace("mc", "http://pymontecarlo.sf.net") source = BytesIO( b'<mc:photonDepthDetector xmlns:mc="http://pymontecarlo.sf.net"><elevation lower="0.6108652381980153" upper="0.7853981633974483" /><azimuth lower="0.0" upper="6.283185307179586" /><channels>1000</channels><transitions/></mc:photonDepthDetector>' ) self.element = etree.parse(source).getroot()