def test_none(self): """ Frames with empty (None) commands/responses should still export. """ frame = Coqdoc_Frame(command=None, command_cd=None, response=None) xml = frame.toxml(doc=BeautifulStoneSoup()) self.assertEquals(xml.command.text, "") self.assertFalse(xml.response) self.assertFalse(xml.find(name="command-coqdoc"))
def _process_code(self, div): """ Process a code div, returning a scene and the frames referenced. """ frames = [] scene = Scene() scene.set_type("code") coqdoc = [] for child in div: coqdoc.append(child) commands = self._find_commands(child) if commands and self.isCommand(commands[0]): command = self._replace_html(commands[0]) if (command.count("Notation") == 0): response = self._prover.send( command.encode(self._coqdoc_tree.originalEncoding)) frame = Coqdoc_Frame(command=command, command_cd=coqdoc, response=response) frames.append(frame) scene.add_scene(frame) coqdoc = [] trailing_frame = Coqdoc_Frame(command=''.join( [str(el) for el in coqdoc]), command_cd=coqdoc, response=None) frames.append(trailing_frame) scene.add_scene(trailing_frame) return frames, scene
def test_none(self): """ Frames with empty (None) commands/responses should still export. """ frame = Coqdoc_Frame(command = None, command_cd = None, response = None) xml = frame.toxml(doc = BeautifulStoneSoup()) self.assertEquals(xml.command.text, "") self.assertFalse(xml.response) self.assertFalse(xml.find(name = "command-coqdoc"))
def test_export_entities(self): """ Entities that are already escaped should not be escaped again. """ frame = Coqdoc_Frame( command=" ", command_cd=BeautifulStoneSoup("<div> </div>")) xml = frame.toxml(doc=BeautifulStoneSoup()) self.assertEquals(xml.find(name="command-coqdoc").div.text, " ")
def test_export_entities(self): """ Entities that are already escaped should not be escaped again. """ frame = Coqdoc_Frame(command =" ", command_cd = BeautifulStoneSoup("<div> </div>")) xml = frame.toxml(doc = BeautifulStoneSoup()) self.assertEquals(xml.find(name = "command-coqdoc").div.text, " ")
def test_nested_entities(self): """ Test that entities in elements escape correctly. """ soup = BeautifulStoneSoup("<div>&</div>") frame = Coqdoc_Frame(command="foo", response="bar", command_cd=soup) xml = frame.toxml(doc=BeautifulStoneSoup()) self.assertEquals(str(xml.find(name="command-coqdoc").div), "<div>&</div>")
def test_nested_entities(self): """ Test that entities in elements escape correctly. """ soup = BeautifulStoneSoup("<div>&</div>") frame = Coqdoc_Frame(command = "foo", response = "bar", command_cd = soup) xml = frame.toxml(doc = BeautifulStoneSoup()) self.assertEquals(str(xml.find(name = "command-coqdoc").div), "<div>&</div>")
def test_entitities(self): """ Test that entities in command, response and coqdoc_command are exported to the correct entitity codes when exporting to XML. """ frame = Coqdoc_Frame(command="&", command_cd="&", response="&") xml = frame.toxml(doc=BeautifulStoneSoup()) self.assertEquals(xml.command.text, "&") self.assertEquals(xml.response.text, "&")
def test_entitities(self): """ Test that entities in command, response and coqdoc_command are exported to the correct entitity codes when exporting to XML. """ frame = Coqdoc_Frame(command = "&", command_cd = "&", response = "&") xml = frame.toxml(doc = BeautifulStoneSoup()) self.assertEquals(xml.command.text, "&") self.assertEquals(xml.response.text, "&")
def fromxml(self, xml): """ Unmarshall the given xml tree into a Coqdoc_movie. """ self._frames = [] self._scenes = [] for frame_xml in xml.film.findAll(name="frame"): frame = Coqdoc_Frame() frame.fromxml(frame_xml) self.addFrame(frame) for scene_xml in xml.scenes.findAll(name="scene", recursive=False): scene = Scene() scene.fromxml(scene_xml) self._replace_frames(scene) self.add_scene(scene)
def fromxml(self, xml): """ Unmarshall the given xml tree into a Coqdoc_movie. """ self._frames = [] self._scenes = [] for frame_xml in xml.film.findAll(name="frame"): frame = Coqdoc_Frame() frame.fromxml(frame_xml) self.addFrame(frame) for scene_xml in xml.scenes.findAll(name="scene", recursive = False): scene = Scene() scene.fromxml(scene_xml) self._replace_frames(scene) self.add_scene(scene)
def _process_doc(self, div): frames = [] scene = Scene() scene.set_type("doc") scene.set_attributes(div.attrs) for child in div: try: child_name = child.name except AttributeError: child_name = "text" child.text = str(child) if child_name == "div": if div.get("class") == "doc": child_frames, child_scene = self._process_doc(child) else: child_frames, child_scene = self._process_div(child) else: child_scene = Coqdoc_Frame(command=child.text, command_cd=[child], response=None) child_frames = [child_scene] frames += child_frames scene.add_scene(child_scene) return frames, scene
def setUp(self): """ Sets up fixture. """ self._target = NamedTemporaryFile(suffix = ".xml", delete = False) s = BeautifulStoneSoup() self._a = Tag(s, "a") self._frame = Coqdoc_Frame(command_cd = [self._a], command = "foo", response = None) self._coqdoc_movie = Coqdoc_Movie() self._coqdoc_movie.addFrame(self._frame)
def test_from_xml(self): """ Test that a frame is constructed from XML, properly. """ xml = BeautifulStoneSoup("""<film><frame framenumber="0"> <command>Spam</command> <response>Eggs</response> <command-coqdoc><div>Spam</div></command-coqdoc> </frame></fiml> """) frame = Coqdoc_Frame() frame.fromxml(xml.frame) self.assertEquals("Spam", frame.getCommand()) self.assertEquals("Eggs", frame.getResponse()) self.assertEquals("<div>Spam</div>", str(frame.get_coqdoc_command()))
def fromxml(self, element): """ Unmarshall the scene from the given element. """ self.set_attributes(element.attrs) try: self.set_type(element['class']) except KeyError: print "Class does not exist in element {el}, setting to doc.".\ format(el = element) self.set_type("doc") self.set_number(['scenenumber']) for child in element.findAll(recursive = False): if child.name == "scene": sub_scene = Scene() sub_scene.fromxml(child) elif child.name == "frame-reference": sub_scene = Coqdoc_Frame(id = child["framenumber"]) self.add_scene(sub_scene)