lundi 25 mars 2019

Python assert file checksum but ignore date

I'm trying to write some tests for my code to ensure that an HTML file generated by Folium is consistent.

My initial thought was to use md5 checksums and the test I've written generates a Folium map, saves it to HTML and then generates the checksum using the following code (based on the excellent answers here)...

with open(plot_journey.journey.journey_id + '.html', "rb") as f:
            html_map = f.read()
assert hashlib.md5(html_map).hexdigest() == '12a7073a77278705ca1bfa5446b2a78c'

...but this fails because the md5-checksum calculation includes the date/time of the files creation and that in turn changes each time the test is run.

I don't know of anyway around this, had a quick try of sha256sum and it too uses date/time of file creation.

Is this even a sensible approach to be taking? I'm thinking not, but have no idea how to write a test to ensure that a given set of data is consistently plotted by Folium and saved to HTML.

Aucun commentaire:

Enregistrer un commentaire