From: W. Trevor King Date: Sat, 1 Sep 2012 12:03:48 +0000 (-0400) Subject: template: remove extra blank lines from construct student email. X-Git-Tag: v0.3~46 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=7e0ae6facf3b1f1a743723d6963b6cb2e48578fd;p=pygrader.git template: remove extra blank lines from construct student email. By fixing STUDENT_TEMPLATE to remove blank lines due to grades without comments. Also remove NORMALIZE_WHITESPACE from template doctests, which had been there to match tabs (doctest expands hard tab characters to spaces using 8-column tab stops). However, with NORMALIZE_WHITESPACE it was impossible to test for extra blank lines. --- diff --git a/pygrader/template.py b/pygrader/template.py index c209dc9..dc1ec3d 100644 --- a/pygrader/template.py +++ b/pygrader/template.py @@ -46,14 +46,13 @@ Grades: {%- endfor %} Comments: -{%- for grade in grades -%} -{% if grade.comment %} +{%- for grade in grades -%}{% if grade.comment %} {{ grade.assignment.name }} {{ grade.comment }} -{%- endif %} -{% endfor %} +{%- endif %}{% endfor %} + Yours, {{ author.alias() }} """.strip()) @@ -240,8 +239,8 @@ def construct_student_email(author, grades, cc=None): ... points=int(points/2.0)) ... grades.append(grade) >>> msg = construct_student_email(author=author, grades=grades) - >>> print(msg.as_string()) - ... # doctest: +REPORT_UDIFF, +ELLIPSIS, +NORMALIZE_WHITESPACE + >>> print(msg.as_string().replace('\\t', ' ')) + ... # doctest: +REPORT_UDIFF, +ELLIPSIS Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit @@ -255,20 +254,19 @@ def construct_student_email(author, grades, cc=None): Jill, Grades: - * Exam 1:\t5 out of 10 available points. - * Homework 1:\t1 out of 3 available points. + * Exam 1: 5 out of 10 available points. + * Homework 1: 1 out of 3 available points. Comments: - Yours, Jack >>> grades[0].comment = ('Bla bla bla. '*20).strip() >>> grades[1].comment = ('Hello world') >>> msg = construct_student_email(author=author, grades=grades) - >>> print(msg.as_string()) - ... # doctest: +REPORT_UDIFF, +ELLIPSIS, +NORMALIZE_WHITESPACE + >>> print(msg.as_string().replace('\\t', ' ')) + ... # doctest: +REPORT_UDIFF, +ELLIPSIS Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit @@ -282,8 +280,8 @@ def construct_student_email(author, grades, cc=None): Jill, Grades: - * Exam 1:\t5 out of 10 available points. - * Homework 1:\t1 out of 3 available points. + * Exam 1: 5 out of 10 available points. + * Homework 1: 1 out of 3 available points. Comments: @@ -291,15 +289,39 @@ def construct_student_email(author, grades, cc=None): Hello world + Homework 1 + Bla bla bla. Bla bla bla. Bla bla bla. Bla bla bla. Bla bla bla. Bla bla bla. Bla bla bla. Bla bla bla. Bla bla bla. Bla bla bla. Bla bla bla. Bla bla bla. Bla bla bla. Bla bla bla. Bla bla bla. Bla bla bla. Bla bla bla. Bla bla bla. Bla bla bla. Bla bla bla. - Homework 1 + Yours, + Jack + + >>> grades[0].comment = 'Work harder!' + >>> grades[1].comment = None + >>> msg = construct_student_email(author=author, grades=grades) + >>> print(msg.as_string().replace('\\t', ' ')) + ... # doctest: +REPORT_UDIFF, +ELLIPSIS + Content-Type: text/plain; charset="us-ascii" + MIME-Version: 1.0 + Content-Transfer-Encoding: 7bit + Content-Disposition: inline + Date: ... + From: Jack + Reply-to: Jack + To: Jill + Subject: Your grade + + Jill, + + Grades: + * Exam 1: 5 out of 10 available points. + * Homework 1: 1 out of 3 available points. - Bla bla bla. Bla bla bla. Bla bla bla. Bla bla bla. Bla bla bla. Bla bla - bla. Bla bla bla. Bla bla bla. Bla bla bla. Bla bla bla. Bla bla bla. Bla - bla bla. Bla bla bla. Bla bla bla. Bla bla bla. Bla bla bla. Bla bla bla. - Bla bla bla. Bla bla bla. Bla bla bla. + Comments: + + Homework 1 + Work harder! Yours, Jack @@ -353,8 +375,8 @@ def construct_course_email(author, course, targets, cc=None): ... assignments=assignments, people=[student], grades=grades) >>> msg = construct_course_email( ... author=author, course=course, targets=[prof]) - >>> print(msg.as_string()) - ... # doctest: +REPORT_UDIFF, +ELLIPSIS, +NORMALIZE_WHITESPACE + >>> print(msg.as_string().replace('\\t', ' ')) + ... # doctest: +REPORT_UDIFF, +ELLIPSIS Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit @@ -369,15 +391,15 @@ def construct_course_email(author, course, targets, cc=None): Here are the (tab delimited) course grades to date: - Student\tExam 1\tHomework 1\tTotal - Jill\t5\t1\t0.416... + Student Exam 1 Homework 1 Total + Jill 5 1 0.416... -- - Mean\t5.00\t1.00\t0.416... - Std. Dev.\t0.00\t0.00\t0.0 + Mean 5.00 1.00 0.416... + Std. Dev. 0.00 0.00 0.0 The available points (and weights) for each assignment are: - * Exam 1:\t10\t0.5 - * Homework 1:\t3\t0.5 + * Exam 1: 10 0.5 + * Homework 1: 3 0.5 Yours, Jack