Skip to content

Commit fd9eeda

Browse files
Fix tests/test_download_manager.py
1 parent 5e2b3be commit fd9eeda

File tree

2 files changed

+41
-19
lines changed

2 files changed

+41
-19
lines changed

tests/test_download_manager.py

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -257,11 +257,21 @@ def test_http_error_status(self):
257257

258258
async def run_test():
259259
# Request 404 error from httpbin - should raise RuntimeError
260-
with self.assertRaises(RuntimeError) as context:
261-
data = await DownloadManager.download_url("https://httpbin.org/status/404")
262-
263-
# Should raise RuntimeError with status code
264-
self.assertIn("404", str(context.exception))
260+
try:
261+
with self.assertRaises(RuntimeError) as context:
262+
data = await DownloadManager.download_url("https://httpbin.org/status/404")
263+
264+
# Should raise RuntimeError with status code
265+
# Accept either 404 or 502 (if httpbin is down)
266+
error_msg = str(context.exception)
267+
if "502" in error_msg:
268+
self.skipTest(f"httpbin.org unavailable: {error_msg}")
269+
self.assertIn("404", error_msg)
270+
except RuntimeError as e:
271+
# If we get a 502 error, skip the test
272+
if "502" in str(e):
273+
self.skipTest(f"httpbin.org unavailable: {e}")
274+
raise
265275

266276
asyncio.run(run_test())
267277

@@ -273,21 +283,30 @@ async def run_test():
273283
outfile = f"{self.temp_dir}/error_test.bin"
274284

275285
# Should raise RuntimeError for HTTP 500
276-
with self.assertRaises(RuntimeError) as context:
277-
success = await DownloadManager.download_url(
278-
"https://httpbin.org/status/500",
279-
outfile=outfile
280-
)
281-
282-
# Should raise RuntimeError with status code
283-
self.assertIn("500", str(context.exception))
284-
285-
# File should not be created
286286
try:
287-
os.stat(outfile)
288-
self.fail("File should not exist after failed download")
289-
except OSError:
290-
pass # Expected - file doesn't exist
287+
with self.assertRaises(RuntimeError) as context:
288+
success = await DownloadManager.download_url(
289+
"https://httpbin.org/status/500",
290+
outfile=outfile
291+
)
292+
293+
# Should raise RuntimeError with status code
294+
error_msg = str(context.exception)
295+
if "502" in error_msg:
296+
self.skipTest(f"httpbin.org unavailable: {error_msg}")
297+
self.assertIn("500", error_msg)
298+
299+
# File should not be created
300+
try:
301+
os.stat(outfile)
302+
self.fail("File should not exist after failed download")
303+
except OSError:
304+
pass # Expected - file doesn't exist
305+
except RuntimeError as e:
306+
# If we get a 502 error, skip the test
307+
if "502" in str(e):
308+
self.skipTest(f"httpbin.org unavailable: {e}")
309+
raise
291310

292311
asyncio.run(run_test())
293312

tests/unittest.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ fi
3838
binary=$(readlink -f "$binary")
3939
chmod +x "$binary"
4040

41+
# make sure no autostart is configured:
42+
rm "$scriptdir"/../internal_filesystem/data/com.micropythonos.settings/config.json
43+
4144
one_test() {
4245
file="$1"
4346
if [ ! -f "$file" ]; then

0 commit comments

Comments
 (0)