From 3d21d135c8e97a81890975a04bee208f51a3086a Mon Sep 17 00:00:00 2001 From: = <=> Date: Mon, 11 Nov 2019 14:02:45 -0600 Subject: [PATCH 1/2] fix pep8 line length error --- openmc/_utils.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/openmc/_utils.py b/openmc/_utils.py index 97c253f39d..b3c6d065c7 100644 --- a/openmc/_utils.py +++ b/openmc/_utils.py @@ -60,9 +60,10 @@ def download(url, checksum=None, as_browser=False, **kwargs): if checksum is not None: downloadsum = hashlib.md5(open(basename, 'rb').read()).hexdigest() if downloadsum != checksum: - raise IOError("MD5 checksum for {} does not match. If this is your first " - "time receiving this message, please re-run the script. " - "Otherwise, please contact OpenMC developers by emailing " + raise IOError("MD5 checksum for {} does not match. If this is " + "your first time receiving this message, please " + "re-run the script. Otherwise, please contact " + "OpenMC developers by emailing " "openmc-users@googlegroups.com.".format(basename)) return basename From 2c7f23dc32a55834b2664c5c279f8e7d63f555a7 Mon Sep 17 00:00:00 2001 From: = <=> Date: Mon, 11 Nov 2019 14:03:25 -0600 Subject: [PATCH 2/2] tests the download function in _utils.py --- tests/unit_tests/test_utils.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 tests/unit_tests/test_utils.py diff --git a/tests/unit_tests/test_utils.py b/tests/unit_tests/test_utils.py new file mode 100644 index 0000000000..9906f5f387 --- /dev/null +++ b/tests/unit_tests/test_utils.py @@ -0,0 +1,26 @@ +import os +import filecmp + +from openmc import _utils +import pytest + +@pytest.fixture() +def download_photos(run_in_tmpdir): + """use _utils download() function to download the same picture three times, + twice to get unique names, & a third time to use the already downloaded + block of code""" + _utils.download("https://i.ibb.co/HhKFc8x/small.jpg") + _utils.download("https://tinyurl.com/y4t38ugb") + _utils.download("https://tinyurl.com/y4t38ugb", as_browser=True) + + +def test_checksum_error(run_in_tmpdir): + """use download() in such a way that will test the checksum error line""" + phrase = "MD5 checksum for y4t38ugb" + with pytest.raises(OSError, match=phrase): + _utils.download("https://tinyurl.com/y4t38ugb", as_browser=True, + checksum="not none") + + +def test_photos(download_photos): + assert filecmp.cmp("small.jpg", "y4t38ugb")