I am attempting to build the header row of a month in HTML. I have a test case, and when I visually inspect either the comparison or the portion generated by my code, I get an assertion error (eg. my case did not pass). The weird thing is that when I visually inspect, the outputs SEEM to be identical.
I have done some fiddling, and narrowed the scope of the problem. Please see code below.
Here is my testcase:
class xyz(unittest.TestCase):
def test__render_table_header(self):
self.maxDiff = None
testy = self.testcal1
htmltest = testy._render_table_header(date(2014, 8, 1))
htmlcase = """<table>
<th colspan='7'>
<div class="headercontainer">
<div class="montheader">{}</div>
<div class="yearheader">{}</div>
</div>
</th>
<tr>
<td class='dayheader'>Sun</td>
<td class='dayheader'>Mon</td>
<td class='dayheader'>Tues</td>
<td class='dayheader'>Wed</td>
<td class='dayheader'>Thurs</td>
<td class='dayheader'>Fri</td>
<td class='dayheader'>Sat</td>
</tr>
<tr>""".format('August', '2014')
self.assertEqual(htmlcase, htmltest)
Here is my function:
def _render_table_header(self, dateobj):
TOP_OF_TABLE = """<table>
<th colspan='7'>
<div class="headercontainer">
<div class="montheader">{}</div>
<div class="yearheader">{}</div>
</div>
</th>
<tr>
<td class='dayheader'>Sun</td>
<td class='dayheader'>Mon</td>
<td class='dayheader'>Tues</td>
<td class='dayheader'>Wed</td>
<td class='dayheader'>Thurs</td>
<td class='dayheader'>Fri</td>
<td class='dayheader'>Sat</td>
</tr>
<tr>"""
month = dateobj.strftime('%B')
year = dateobj.strftime('%Y')
return TOP_OF_TABLE.format(month, year)
Here is the error and diff I get:
FAIL: test__render_table_header
(__main__.test_enhanced_cal_helper_functions)
----------------------------------------------------------------------
Traceback (most recent call last):
File "court_app_timeline.py", line 430, in test__render_table_header
self.assertEqual(htmlcase, htmltest)
AssertionError: '<table>\n <th colspan=\'7\'>\n <div [585 chars]<tr>' != '<table>\n <th colspan=\'7\'>\n [649 chars]<tr>'
<table>
- <th colspan='7'>
+ <th colspan='7'>
? ++++
- <div class="headercontainer">
+ <div class="headercontainer">
? ++++
- <div class="montheader">August</div>
+ <div class="montheader">August</div>
? ++++
- <div class="yearheader">2014</div>
+ <div class="yearheader">2014</div>
? ++++
- </div>
+ </div>
? ++++
- </th>
+ </th>
? ++++
- <tr>
+ <tr>
? ++++
- <td class='dayheader'>Sun</td>
+ <td class='dayheader'>Sun</td>
? ++++
- <td class='dayheader'>Mon</td>
+ <td class='dayheader'>Mon</td>
? ++++
- <td class='dayheader'>Tues</td>
+ <td class='dayheader'>Tues</td>
? ++++
- <td class='dayheader'>Wed</td>
+ <td class='dayheader'>Wed</td>
? ++++
- <td class='dayheader'>Thurs</td>
+ <td class='dayheader'>Thurs</td>
? ++++
- <td class='dayheader'>Fri</td>
+ <td class='dayheader'>Fri</td>
? ++++
- <td class='dayheader'>Sat</td>
+ <td class='dayheader'>Sat</td>
? ++++
- </tr>
+ </tr>
? ++++
- <tr>+ <tr>? ++++
----------------------------------------------------------------------
I will admit to you fine folks that I'm not the most talented programmer. In fact, my entire programming career hearkens back to only about 5 months ago. Along with that comes a certain ineptitude at reading diffs. It seems to me that the major difference between the outputs has to do with leading whitespace. How can I fix this?
PS - any tips, comments, pointers, etc. are much appreciated.