Skip to content

Commit

Permalink
Merge pull request #70 from jnsebgosselin/generate_html_from_file
Browse files Browse the repository at this point in the history
PR: Add a method to format the content of a WeatherSationList into a HTML table
  • Loading branch information
jnsebgosselin committed Oct 5, 2017
2 parents 00c039f + da5d01b commit b09373f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
16 changes: 16 additions & 0 deletions WHAT/meteo/weather_stationlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,22 @@ def save_to_file(self, filename):

print('Station list saved successfully in %s' % filename)

def format_list_in_html(self):
"""Format the content of the weather station list into a HTML table."""
html = "<table>"
html += "<tr>"
for attrs in self.HEADER:
html += '<th>%s</th>' % attrs
html += "<tr>"
for station in self:
html += "<tr>"
for attrs in station:
html += '<td>%s</td>' % attrs
html += "</tr>"
html += "</table>"

return html


if __name__ == '__main__':
fname = ("C:\\Users\\jsgosselin\\OneDrive\\WHAT\\WHAT\\tests\\"
Expand Down
6 changes: 5 additions & 1 deletion WHAT/tests/test_dwnld_weather_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,11 @@ def test_load_stationlist(downloader_bot, mocker):
wxdata_downloader.btn_browse_staList_isClicked()

# Assert that the data are stored correctly in the widget table.
assert expected_result == wxdata_downloader.station_table.get_stationlist()
station_list = wxdata_downloader.station_table.get_stationlist()
assert expected_result == station_list

# Test that the station list formating to html works without any error.
station_list.format_list_in_html()

# Try to open a station list when the file does not exist.
wxdata_downloader.load_stationList("dummy.lst")
Expand Down

0 comments on commit b09373f

Please sign in to comment.