def test_attribute_name_type(self): fun = sys._getframe().f_code.co_name print("Run: %s.%s() " % (self.__class__.__name__, fun)) attr1 = {} # sattr1 = {"NXentry": "entry1"} at1 = {"name": "name"} at2 = {"name": "type"} el = FetchNameHandler() self.assertTrue(isinstance(el.groupTypes, TNObject)) self.assertEqual(el.startElement("group", attr1), None) self.assertEqual(el.startElement("attribute", at1), None) self.assertEqual(el.characters("entry1"), None) self.assertEqual(el.endElement("attribute"), None) self.assertEqual(el.startElement("attribute", at2), None) self.assertEqual(el.characters("NXentry"), None) self.assertEqual(el.endElement("attribute"), None) self.assertEqual(el.endElement("group"), None) self.assertEqual(el.groupTypes.name, "root") self.assertEqual(el.groupTypes.nxtype, None) ch = el.groupTypes.child(nxtype="NXentry") self.assertTrue(isinstance(ch, TNObject)) self.assertEqual(ch.name, "entry1") self.assertEqual(ch.nxtype, "NXentry") self.assertEqual(len(ch.children), 0)
def test_group_name_only_types(self): fun = sys._getframe().f_code.co_name print("Run: %s.%s() " % (self.__class__.__name__, fun)) attr1 = {"type": "NXentry"} # sattr1 = {attr1["type"]: "entry"} attr2 = {"type": "NXinstrument", "units": "m"} # sattr2 = {attr2["type"]: "instrument"} el = FetchNameHandler() self.assertTrue(isinstance(el.groupTypes, TNObject)) self.assertEqual(el.startElement("group", attr1), None) self.assertEqual(el.startElement("group", attr2), None) self.assertEqual(el.endElement("group"), None) self.assertEqual(el.endElement("group"), None) self.assertEqual(el.groupTypes.name, "root") self.assertEqual(el.groupTypes.nxtype, None) ch = el.groupTypes.child(nxtype=attr1["type"]) self.assertTrue(isinstance(ch, TNObject)) self.assertEqual(ch.name, attr1["type"][2:]) self.assertEqual(ch.nxtype, attr1["type"]) self.assertEqual(len(ch.children), 1) ch = ch.child(nxtype=attr2["type"]) self.assertTrue(isinstance(ch, TNObject)) self.assertEqual(ch.name, attr2["type"][2:]) self.assertEqual(ch.nxtype, attr2["type"]) self.assertEqual(len(ch.children), 0)
def test_group_name_notype(self): fun = sys._getframe().f_code.co_name print("Run: %s.%s() " % (self.__class__.__name__, fun)) attr1 = {"name": "entry"} # sattr1 = {"1": attr1["name"]} el = FetchNameHandler() self.assertTrue(isinstance(el.groupTypes, TNObject)) self.assertEqual(el.startElement("group", attr1), None) self.myAssertRaise(XMLSyntaxError, el.endElement, "group") self.assertTrue(isinstance(el.groupTypes, TNObject))
def test_XML_group_only_types(self): fun = sys._getframe().f_code.co_name print("Run: %s.%s() " % (self.__class__.__name__, fun)) attr1 = {"type": "NXentry"} # sattr1 = {attr1["type"]: "entry"} attr2 = {"type": "NXinstrument", "units": "m"} # sattr2 = {attr2["type"]: "instrument"} # parser = sax.make_parser() el = FetchNameHandler() sax.parseString( tobytes('<group type="%s" ><group type="%s"/></group>' % (attr1["type"], attr2["type"])), el) self.assertEqual(el.groupTypes.name, "root") self.assertEqual(el.groupTypes.nxtype, None) ch = el.groupTypes.child(nxtype=attr1["type"]) self.assertTrue(isinstance(ch, TNObject)) self.assertEqual(ch.name, attr1["type"][2:]) self.assertEqual(ch.nxtype, attr1["type"]) self.assertEqual(len(ch.children), 1) ch = ch.child(nxtype=attr2["type"]) self.assertTrue(isinstance(ch, TNObject)) self.assertEqual(ch.name, attr2["type"][2:]) self.assertEqual(ch.nxtype, attr2["type"]) self.assertEqual(len(ch.children), 0)
def test_XML_group_field(self): fun = sys._getframe().f_code.co_name print("Run: %s.%s() " % (self.__class__.__name__, fun)) attr1 = {"name": "entry1", "type": "NXentry"} # sattr1 = {attr1["type"]: attr1["name"]} attr2 = {"name": "scan", "type": "NX_FLOAT"} # parser = sax.make_parser() el = FetchNameHandler() sax.parseString( tobytes( '<group type="%s" name="%s"><field type="%s" name="%s"/>' '</group>' % (attr1["type"], attr1["name"], attr2["type"], attr2["name"])), el) self.assertEqual(el.groupTypes.name, "root") self.assertEqual(el.groupTypes.nxtype, None) ch = el.groupTypes.child(nxtype=attr1["type"]) self.assertTrue(isinstance(ch, TNObject)) self.assertEqual(ch.name, attr1["name"]) self.assertEqual(ch.nxtype, attr1["type"]) self.assertEqual(len(ch.children), 0)
def test_constructor(self): fun = sys._getframe().f_code.co_name print("Run: %s.%s() " % (self.__class__.__name__, fun)) el = FetchNameHandler() self.assertTrue(isinstance(el.groupTypes, TNObject)) self.assertEqual(el.groupTypes.name, "root") self.assertEqual(el.groupTypes.nxtype, None) self.assertEqual(el.groupTypes.children, [])
def test_group_field(self): fun = sys._getframe().f_code.co_name print("Run: %s.%s() " % (self.__class__.__name__, fun)) attr1 = {"name": "entry1", "type": "NXentry"} # sattr1 = {attr1["type"]: attr1["name"]} attr2 = {"name": "scan", "type": "NX_FLOAT"} el = FetchNameHandler() self.assertTrue(isinstance(el.groupTypes, TNObject)) self.assertEqual(el.startElement("group", attr1), None) self.assertEqual(el.startElement("field", attr2), None) self.assertEqual(el.endElement("field"), None) self.assertEqual(el.endElement("group"), None) self.assertEqual(el.groupTypes.name, "root") self.assertEqual(el.groupTypes.nxtype, None) ch = el.groupTypes.child(nxtype=attr1["type"]) self.assertTrue(isinstance(ch, TNObject)) self.assertEqual(ch.name, attr1["name"]) self.assertEqual(ch.nxtype, attr1["type"]) self.assertEqual(len(ch.children), 0)
def test_XML_group_notype(self): fun = sys._getframe().f_code.co_name print("Run: %s.%s() " % (self.__class__.__name__, fun)) attr1 = {"name": "entry"} # sattr1 = {"1": attr1["name"]} # parser = sax.make_parser() el = FetchNameHandler() self.myAssertRaise(XMLSyntaxError, sax.parseString, tobytes('<group name="%s" />' % (attr1["name"])), el) self.assertTrue(isinstance(el.groupTypes, TNObject)) self.assertEqual(len(el.groupTypes.children), 1) ch = el.groupTypes.child(name="entry") self.assertTrue(isinstance(ch, TNObject)) self.assertEqual(ch.name, "entry") self.assertEqual(ch.nxtype, "")
def test_XML_attribute_type(self): fun = sys._getframe().f_code.co_name print("Run: %s.%s() " % (self.__class__.__name__, fun)) attr1 = {"name": "entry1"} # sattr1 = {"NXentry": "entry1"} # attr2 = {"name": "type"} # parser = sax.make_parser() el = FetchNameHandler() sax.parseString( tobytes('<group name="%s" ><attribute name="type">NXentry' '</attribute></group>' % (attr1["name"])), el) self.assertEqual(el.groupTypes.name, "root") self.assertEqual(el.groupTypes.nxtype, None) ch = el.groupTypes.child(name=attr1["name"]) self.assertTrue(isinstance(ch, TNObject)) self.assertEqual(ch.name, attr1["name"]) self.assertEqual(ch.nxtype, "NXentry") self.assertEqual(len(ch.children), 0)