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

        self.h = SubstrateXMLHandler()

        self.obj = Substrate([Material.pure(29), Material.pure(30)], 1.1, 2.2)

        etree.register_namespace('mc', 'http://pymontecarlo.sf.net')
        source = BytesIO(b'<mc:substrate xmlns:mc="http://pymontecarlo.sf.net" rotation="2.2" tilt="1.1"><materials><mc:material _index="1" density="8960.0" name="Copper"><composition><element weightFraction="1.0" z="29" /></composition></mc:material><mc:material _index="2" density="7140.0" name="Zinc"><composition><element weightFraction="1.0" z="30" /></composition></mc:material></materials><body material="1,2" /></mc:substrate>')
        self.element = etree.parse(source).getroot()
Esempio n. 2
0
class TestSubstrateXMLHandler(unittest.TestCase):

    def setUp(self):
        unittest.TestCase.setUp(self)

        self.h = SubstrateXMLHandler()

        self.obj = Substrate([Material.pure(29), Material.pure(30)], 1.1, 2.2)

        etree.register_namespace('mc', 'http://pymontecarlo.sf.net')
        source = BytesIO(b'<mc:substrate xmlns:mc="http://pymontecarlo.sf.net" rotation="2.2" tilt="1.1"><materials><mc:material _index="1" density="8960.0" name="Copper"><composition><element weightFraction="1.0" z="29" /></composition></mc:material><mc:material _index="2" density="7140.0" name="Zinc"><composition><element weightFraction="1.0" z="30" /></composition></mc:material></materials><body material="1,2" /></mc:substrate>')
        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(1.1, obj.tilt_rad, 4)
        self.assertAlmostEqual(2.2, obj.rotation_rad, 4)

        self.assertEqual(2, len(obj.body.material))
        self.assertEqual('Copper', str(obj.body.material[0]))
        self.assertEqual('Zinc', str(obj.body.material[1]))

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

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

        self.assertAlmostEqual(1.1, float(element.get('tilt')), 4)
        self.assertAlmostEqual(2.2, float(element.get('rotation')), 4)
        self.assertEqual('1,2', element.find('body').get('material'))