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)
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")
def test_MissingExerciseTex(self): import lxml self.assertRaises(lxml.etree.XMLSyntaxError, lambda : Exercise.fromXMLFile(dataPath("invalid14.xml")))
def test_readPlainXML(self): self.assertTrue(Exercise.fromXMLFile(dataPath("noschemaandencoding.xml")))
def loadFromXML(creator, number): from exdb.exercise import Exercise return Exercise.fromXMLFile(xmlPath(creator=creator, number=number))
def test_MissingExerciseTex(self): import lxml self.assertRaises( lxml.etree.XMLSyntaxError, lambda: Exercise.fromXMLFile(dataPath("invalid14.xml")))
def test_readPlainXML(self): self.assertTrue( Exercise.fromXMLFile(dataPath("noschemaandencoding.xml")))