def test_Elements(self): """ Tests if numerical questions yields reference xml file. Just test the excecution. """ # define i/o file fileIn = os.path.abspath(os.path.join(os.path.dirname(__file__), "test/element.tex")) fileOut = os.path.abspath('./test_element.xml') # convert to xml a2m.amc2moodle(fileInput=fileIn, fileOutput=fileOut, keepFlag=False, catname='test_num', deb=0)
def test_tikz(self): """ Tests if input tex (with tikz) file yields reference xml file. """ # define i/o file fileIn = os.path.abspath( os.path.join(os.path.dirname(__file__), "test/QCM.tex")) fileOut = os.path.abspath('./test_tikz.xml') fileRef = os.path.abspath( os.path.join(os.path.dirname(__file__), "test/QCM.xml")) # convert to xml a2m.amc2moodle(fileInput=fileIn, fileOutput=fileOut, keepFlag=True, catname='test_tikz', deb=0) # check it equiv = check_hash(fileOut, fileRef) if equiv: print(' > Converted XML is identical to the ref.')
def test_numerical(self): """ Tests if numerical questions yields reference xml file. """ # define i/o file fileIn = os.path.abspath( os.path.join(os.path.dirname(__file__), "test/numerical.tex")) fileOut = os.path.abspath('./test_numerical.xml') fileRef = os.path.abspath( os.path.join(os.path.dirname(__file__), "test/numerical.xml")) # convert to xml a2m.amc2moodle(fileInput=fileIn, fileOutput=fileOut, keepFlag=False, catname='test_num', deb=0) # check it equiv = check_hash(fileOut, fileRef) if equiv: print(' > Converted XML is identical to the ref.')
def test_cleaning(self): """ Tests if questions with long equation yields reference xml file. """ # Define i/o file fileIn = os.path.abspath(os.path.join(os.path.dirname(__file__), "test/cleaning.tex")) fileOut = os.path.abspath('./cleaning.xml') fileRef = os.path.abspath(os.path.join(os.path.dirname(__file__), "test/cleaning.xml")) # Convert to xml a2m.amc2moodle(fileInput=fileIn, fileOutput=fileOut, keepFlag=False, catname='test_clean', cleanXML=True, # force cleaning deb=0) # check it equiv = check_hash(fileOut, fileRef) if equiv: Logger.info(' > Converted XML is identical to the ref.') # Parse new XML file # open, parse and store the the converted file tree parser = etree.XMLParser(strip_cdata=False) tree = etree.parse(fileOut, parser) # Question name must contain the string in q_dict q_dict = {'long_eq': '%\n', # check if contain '%\n' } # # Loop over questions of q_dict for qname, value in q_dict.items(): for q in tree.iterfind(".//question"): if q.attrib['type'] != 'category': if q.find('name/text').text == qname: for text in q.findall('.//answer/text'): text_str = etree.tostring(text).decode('utf8') present = value in text_str # the test is ok if present is True self.assertFalse(present) break
def setUpClass(cls): """ Setup XML file from inpout tex (no tikz) for value checking. """ # define i/o file fileIn = os.path.abspath( os.path.join(os.path.dirname(__file__), "test/QCM_wo-tikz.tex")) fileOut = os.path.abspath('./test_notikz.xml') fileRef = os.path.abspath( os.path.join(os.path.dirname(__file__), "test/QCM_wo-tikz.xml")) # convert to xml a2m.amc2moodle(fileInput=fileIn, fileOutput=fileOut, keepFlag=False, catname='test_notikz', deb=0) # check it equiv = check_hash(fileOut, fileRef) if equiv: print(' > Converted XML is identical to the ref.') # open, parse and store the the converted file tree parser = etree.XMLParser(strip_cdata=False) cls.tree = etree.parse(fileOut, parser)