From 3457ecf8d5463580c4d9f71dbadf1c59f1fb21f3 Mon Sep 17 00:00:00 2001 From: Dan Goldsmith Date: Sun, 26 Jul 2020 21:28:25 +0100 Subject: [PATCH] Unit tests for Marks calucation in header --- test/inputs/inputHeaderMarks.md | 10 ++++ test/inputs/inputHeaderMarksTotal.md | 11 +++++ test/inputs/inputHeaderMarksTotalMismatch.md | 11 +++++ test/test_parser.py | 48 ++++++++++++++++++++ 4 files changed, 80 insertions(+) create mode 100644 test/inputs/inputHeaderMarks.md create mode 100644 test/inputs/inputHeaderMarksTotal.md create mode 100644 test/inputs/inputHeaderMarksTotalMismatch.md diff --git a/test/inputs/inputHeaderMarks.md b/test/inputs/inputHeaderMarks.md new file mode 100644 index 0000000..9fd9f25 --- /dev/null +++ b/test/inputs/inputHeaderMarks.md @@ -0,0 +1,10 @@ +--- +name: "foo" +marks: + secOne: 5 + secTwo: 10 +--- + +# Some Fake input + +Bleh diff --git a/test/inputs/inputHeaderMarksTotal.md b/test/inputs/inputHeaderMarksTotal.md new file mode 100644 index 0000000..f66927f --- /dev/null +++ b/test/inputs/inputHeaderMarksTotal.md @@ -0,0 +1,11 @@ +--- +name: "foo" +marks: + secOne: 50 + secTwo: 10 + total: 60 +--- + +# Some Fake input + +Bleh diff --git a/test/inputs/inputHeaderMarksTotalMismatch.md b/test/inputs/inputHeaderMarksTotalMismatch.md new file mode 100644 index 0000000..23bae60 --- /dev/null +++ b/test/inputs/inputHeaderMarksTotalMismatch.md @@ -0,0 +1,11 @@ +--- +name: "foo" +marks: + secOne: 20 + secTwo: 30 + total: 60 +--- + +# Some Fake input + +Bleh diff --git a/test/test_parser.py b/test/test_parser.py index 5a1f854..72a8ab4 100644 --- a/test/test_parser.py +++ b/test/test_parser.py @@ -218,7 +218,52 @@ And More Spacing to be dealt with""" self.assertEqual("\n".join(body), bodyStr) + def testHeaderTemplate(self): + """ + Test if the header has a Template attached + """ + theParser = parser.MarkdownParser("test/inputs/inputController.md") + hasParsed = theParser.parseFile() + #theParser.parseFile() + #header, body = theParser._splitHeader() + self.assertEqual(theParser.header["template"], "controller.jinja2") + + def testHeaderMarks(self): + """ + If marks are given in the header, do we summarise them correctly + """ + theParser = parser.MarkdownParser("test/inputs/inputHeaderMarks.md") + theParser.parseFile() + #First do we have the marks we expected + self.assertEqual(theParser.header["marks"]["secOne"], 5) + self.assertEqual(theParser.header["marks"]["secTwo"], 10) + self.assertEqual(theParser.header["marks"]["total"], 15) + + def testHeaderTotalMarks(self): + """ + If marks are given in the header, do we summarise them correctly + """ + theParser = parser.MarkdownParser("test/inputs/inputHeaderMarksTotal.md") + hasParsed = theParser.parseFile() + + #First do we have the marks we expected + self.assertEqual(theParser.header["marks"]["secOne"], 50) + self.assertEqual(theParser.header["marks"]["secTwo"], 10) + self.assertEqual(theParser.header["marks"]["total"], 60) + def testHeaderTotalMismatch(self): + """ + If marks are given in the header, do we summarise them correctly + """ + theParser = parser.MarkdownParser("test/inputs/inputHeaderMarksTotalMismatch.md") + with self.assertLogs(level="WARNING") as cm: + hasParsed = theParser.parseFile() + #First do we have the marks we expected + self.assertEqual(theParser.header["marks"]["secOne"], 20) + self.assertEqual(theParser.header["marks"]["secTwo"], 30) + self.assertEqual(theParser.header["marks"]["total"], 50) + self.assertEqual(cm.records[0].msg, "Marks Mismatch. Provided 60 Calculated 50") + def testHeaderVals(self): """ Are the values in our header correct @@ -305,3 +350,6 @@ sid: 14242 self.assertIsInstance(theSection, section.Section) self.assertEqual(expectedExp, theSection.text) + + +