From 1d79e959b54eb4972f486bb9faec60ed1ef1048c Mon Sep 17 00:00:00 2001 From: Wenqi Li Date: Sat, 12 Jun 2021 16:05:36 +0100 Subject: [PATCH 1/2] skip download if http 500 Signed-off-by: Wenqi Li --- tests/test_mmar_download.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/tests/test_mmar_download.py b/tests/test_mmar_download.py index 7149cc5a20..479a7cf4f3 100644 --- a/tests/test_mmar_download.py +++ b/tests/test_mmar_download.py @@ -12,6 +12,7 @@ import os import tempfile import unittest +from urllib.error import ContentTooShortError, HTTPError import numpy as np import torch @@ -85,18 +86,26 @@ class TestMMMARDownload(unittest.TestCase): @skip_if_quick @SkipIfBeforePyTorchVersion((1, 6)) def test_download(self, idx): - download_mmar(idx) - download_mmar(idx, progress=False) # repeated to check caching - with tempfile.TemporaryDirectory() as tmp_dir: - download_mmar(idx, mmar_dir=tmp_dir, progress=False) - download_mmar(idx, mmar_dir=tmp_dir, progress=False) # repeated to check caching - self.assertTrue(os.path.exists(os.path.join(tmp_dir, idx))) + try: + download_mmar(idx) + download_mmar(idx, progress=False) # repeated to check caching + with tempfile.TemporaryDirectory() as tmp_dir: + download_mmar(idx, mmar_dir=tmp_dir, progress=False) + download_mmar(idx, mmar_dir=tmp_dir, progress=False) # repeated to check caching + self.assertTrue(os.path.exists(os.path.join(tmp_dir, idx))) + except (ContentTooShortError, HTTPError, RuntimeError) as e: + print(str(e)) + return # skipping this test due the network connection errors @parameterized.expand(TEST_EXTRACT_CASES) @skip_if_quick @SkipIfBeforePyTorchVersion((1, 6)) def test_load_ckpt(self, input_args, expected_name, expected_val): - output = load_from_mmar(**input_args) + try: + output = load_from_mmar(**input_args) + except (ContentTooShortError, HTTPError, RuntimeError) as e: + print(str(e)) + return self.assertEqual(output.__class__.__name__, expected_name) x = next(output.parameters()) # verify the first element np.testing.assert_allclose(x[0][0].detach().cpu().numpy(), expected_val, rtol=1e-3, atol=1e-3) From 09d2bd78660383b14e1517339b4d4e89ac32ee2d Mon Sep 17 00:00:00 2001 From: Wenqi Li Date: Mon, 14 Jun 2021 17:05:53 +0100 Subject: [PATCH 2/2] update based on comments Signed-off-by: Wenqi Li --- tests/test_mmar_download.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/test_mmar_download.py b/tests/test_mmar_download.py index 479a7cf4f3..31c73b8b8f 100644 --- a/tests/test_mmar_download.py +++ b/tests/test_mmar_download.py @@ -95,6 +95,8 @@ def test_download(self, idx): self.assertTrue(os.path.exists(os.path.join(tmp_dir, idx))) except (ContentTooShortError, HTTPError, RuntimeError) as e: print(str(e)) + if isinstance(e, HTTPError): + self.assertTrue("500" in str(e)) # http error has the code 500 return # skipping this test due the network connection errors @parameterized.expand(TEST_EXTRACT_CASES) @@ -105,6 +107,8 @@ def test_load_ckpt(self, input_args, expected_name, expected_val): output = load_from_mmar(**input_args) except (ContentTooShortError, HTTPError, RuntimeError) as e: print(str(e)) + if isinstance(e, HTTPError): + self.assertTrue("500" in str(e)) # http error has the code 500 return self.assertEqual(output.__class__.__name__, expected_name) x = next(output.parameters()) # verify the first element