예제 #1
0
 def test_importInvalidXML(self):
     vlines = validXML.splitlines()
     vlines[6:6] = ["<unspecifiedElement>bla</unspecifiedElement>"]
     invalidXML = "\n".join(vlines)
     
     self.assertRaisesRegexp(XMLSyntaxError, "not expected",
                             lambda : Exercise.fromXMLString(invalidXML.encode('utf-8')))
     del vlines[6]
     vlines[7:7] = ['<tex_exercise lang="DE">double german</tex_exercise>']
     invalidXML2 = "\n".join(vlines)
     self.assertRaisesRegexp(XMLSyntaxError, "Duplicate key-sequence",
                             lambda : Exercise.fromXMLString(invalidXML2.encode('utf-8')))
예제 #2
0
    def test_importInvalidXML(self):
        vlines = validXML.splitlines()
        vlines[6:6] = ["<unspecifiedElement>bla</unspecifiedElement>"]
        invalidXML = "\n".join(vlines)

        self.assertRaisesRegexp(
            XMLSyntaxError, "not expected",
            lambda: Exercise.fromXMLString(invalidXML.encode('utf-8')))
        del vlines[6]
        vlines[7:7] = ['<tex_exercise lang="DE">double german</tex_exercise>']
        invalidXML2 = "\n".join(vlines)
        self.assertRaisesRegexp(
            XMLSyntaxError, "Duplicate key-sequence",
            lambda: Exercise.fromXMLString(invalidXML2.encode('utf-8')))
예제 #3
0
 def test_importValidXML(self):
     exercise = Exercise.fromXMLFile(dataPath("jemand1.xml"))
     self.assertEqual(exercise.schemaversion, 2)
     self.assertEqual(len(exercise.tags), 2)
     self.assertIn('aabc', exercise.tags)
     self.assertIsInstance(exercise.modified, datetime.datetime)
     self.assertIn('DE', exercise.tex_exercise)
     self.assertIn('DE', exercise.tex_solution)
     self.assertIn('EN', exercise.tex_solution)
     self.assertNotIn('EN', exercise.tex_exercise)
     self.assertIsInstance(exercise.number, int)
예제 #4
0
 def test_importValidXML(self):
     exercise = Exercise.fromXMLFile(dataPath("jemand1.xml"))
     self.assertEqual(exercise.schemaversion, 2)
     self.assertEqual(len(exercise.tags), 2)
     self.assertIn('aabc', exercise.tags)
     self.assertIsInstance(exercise.modified, datetime.datetime)
     self.assertIn('DE', exercise.tex_exercise)
     self.assertIn('DE', exercise.tex_solution)
     self.assertIn('EN', exercise.tex_solution)
     self.assertNotIn('EN', exercise.tex_exercise)
     self.assertIsInstance(exercise.number, int)
예제 #5
0
 def test_jsonExport(self):
     exercise = Exercise.fromXMLString(validXML.encode("utf-8"))
     jsonEx = exercise.toJSON()
     jsonDecoded = json.loads(jsonEx)
     for attrib, value in exercise.items():
         if isinstance(value, datetime.datetime):
             self.assertEqual(datetime.datetime.strptime(jsonDecoded[attrib], Exercise.DATEFMT),
                              value)
         else:
             self.assertEqual(jsonDecoded[attrib], value)
     for attrib in jsonDecoded:
         assert attrib in exercise
예제 #6
0
 def test_jsonExport(self):
     exercise = Exercise.fromXMLString(validXML.encode("utf-8"))
     jsonEx = exercise.toJSON()
     jsonDecoded = json.loads(jsonEx)
     for attrib, value in exercise.items():
         if isinstance(value, datetime.datetime):
             self.assertEqual(
                 datetime.datetime.strptime(jsonDecoded[attrib],
                                            Exercise.DATEFMT), value)
         else:
             self.assertEqual(jsonDecoded[attrib], value)
     for attrib in jsonDecoded:
         assert attrib in exercise
예제 #7
0
파일: test_repo.py 프로젝트: mnechay/exdb
 def testRepositoryOperations(self):
     """Adds and removes exercises and checks the history."""
     numExercises = len(glob.glob(join(exdb.repo.repoPath(), "exercises", "*", "*.xml" )))
     self.assertEqual(len(exdb.sql.exercises()), numExercises)
     exes = exdb.sql.exercises()
     self.assertEqual(set(ex.creator for ex in exes), set(("jensmander", "foobar")))
     self.assertTrue(all(ex.number == 1 for ex in exes))
     
     exercise = Exercise.fromXMLFile(dataPath("jemand1.xml"))
     exercise.number = None
     exdb.addExercise(exercise, {})
     self.assertEqual(exercise.number, 1)
     self.assertEqual(len(exdb.sql.exercises()), numExercises+1)
     exdb.removeExercise("jensmander", 1)
     self.assertEqual(len(exdb.sql.exercises()), numExercises)
     exes = exdb.sql.exercises()
     self.assertNotIn("jensmander", (ex.creator for ex in exes))
     history = exdb.repo.history()
     self.assertEqual(history[0]["author"], "jensmander")
     self.assertEqual(history[0]["action"], "REMOVE")
     self.assertEqual(history[1]["action"], "ADD")
예제 #8
0
 def test_xmlExport(self):
     self.maxDiff = None
     self.assertEqual(Exercise.fromXMLString(validXML.encode('utf-8')).toXML(),
                      validXML)
예제 #9
0
 def test_importTooRecentSchema(self):
     invalidXML = validXML.replace('schemaversion="2"', 'schemaversion="1000"')
     self.assertRaises(VersionMismatchError,
                       lambda : Exercise.fromXMLString(invalidXML.encode('utf-8')))
예제 #10
0
 def test_MissingExerciseTex(self):
     import lxml
     self.assertRaises(lxml.etree.XMLSyntaxError,
                       lambda : Exercise.fromXMLFile(dataPath("invalid14.xml")))
예제 #11
0
 def test_readPlainXML(self):
     self.assertTrue(Exercise.fromXMLFile(dataPath("noschemaandencoding.xml")))
예제 #12
0
 def test_readPlainXML(self):
     self.assertTrue(
         Exercise.fromXMLFile(dataPath("noschemaandencoding.xml")))
예제 #13
0
 def test_importTooRecentSchema(self):
     invalidXML = validXML.replace('schemaversion="2"',
                                   'schemaversion="1000"')
     self.assertRaises(
         VersionMismatchError,
         lambda: Exercise.fromXMLString(invalidXML.encode('utf-8')))
예제 #14
0
파일: repo.py 프로젝트: mnechay/exdb
def loadFromXML(creator, number):
    from exdb.exercise import Exercise
    return Exercise.fromXMLFile(xmlPath(creator=creator, number=number))
예제 #15
0
파일: repo.py 프로젝트: supermihi/exdb
def loadFromXML(creator, number):
    from exdb.exercise import Exercise
    return Exercise.fromXMLFile(xmlPath(creator=creator, number=number))
예제 #16
0
 def test_xmlExport(self):
     self.maxDiff = None
     self.assertEqual(
         Exercise.fromXMLString(validXML.encode('utf-8')).toXML(), validXML)
예제 #17
0
 def test_MissingExerciseTex(self):
     import lxml
     self.assertRaises(
         lxml.etree.XMLSyntaxError,
         lambda: Exercise.fromXMLFile(dataPath("invalid14.xml")))