You've already forked MicroPythonOS
mirror of
https://github.com/m5stack/MicroPythonOS.git
synced 2026-05-20 11:51:27 -07:00
Fix tests/test_download_manager.py
This commit is contained in:
@@ -257,11 +257,21 @@ class TestDownloadManager(unittest.TestCase):
|
||||
|
||||
async def run_test():
|
||||
# Request 404 error from httpbin - should raise RuntimeError
|
||||
with self.assertRaises(RuntimeError) as context:
|
||||
data = await DownloadManager.download_url("https://httpbin.org/status/404")
|
||||
try:
|
||||
with self.assertRaises(RuntimeError) as context:
|
||||
data = await DownloadManager.download_url("https://httpbin.org/status/404")
|
||||
|
||||
# Should raise RuntimeError with status code
|
||||
self.assertIn("404", str(context.exception))
|
||||
# Should raise RuntimeError with status code
|
||||
# Accept either 404 or 502 (if httpbin is down)
|
||||
error_msg = str(context.exception)
|
||||
if "502" in error_msg:
|
||||
self.skipTest(f"httpbin.org unavailable: {error_msg}")
|
||||
self.assertIn("404", error_msg)
|
||||
except RuntimeError as e:
|
||||
# If we get a 502 error, skip the test
|
||||
if "502" in str(e):
|
||||
self.skipTest(f"httpbin.org unavailable: {e}")
|
||||
raise
|
||||
|
||||
asyncio.run(run_test())
|
||||
|
||||
@@ -273,21 +283,30 @@ class TestDownloadManager(unittest.TestCase):
|
||||
outfile = f"{self.temp_dir}/error_test.bin"
|
||||
|
||||
# Should raise RuntimeError for HTTP 500
|
||||
with self.assertRaises(RuntimeError) as context:
|
||||
success = await DownloadManager.download_url(
|
||||
"https://httpbin.org/status/500",
|
||||
outfile=outfile
|
||||
)
|
||||
|
||||
# Should raise RuntimeError with status code
|
||||
self.assertIn("500", str(context.exception))
|
||||
|
||||
# File should not be created
|
||||
try:
|
||||
os.stat(outfile)
|
||||
self.fail("File should not exist after failed download")
|
||||
except OSError:
|
||||
pass # Expected - file doesn't exist
|
||||
with self.assertRaises(RuntimeError) as context:
|
||||
success = await DownloadManager.download_url(
|
||||
"https://httpbin.org/status/500",
|
||||
outfile=outfile
|
||||
)
|
||||
|
||||
# Should raise RuntimeError with status code
|
||||
error_msg = str(context.exception)
|
||||
if "502" in error_msg:
|
||||
self.skipTest(f"httpbin.org unavailable: {error_msg}")
|
||||
self.assertIn("500", error_msg)
|
||||
|
||||
# File should not be created
|
||||
try:
|
||||
os.stat(outfile)
|
||||
self.fail("File should not exist after failed download")
|
||||
except OSError:
|
||||
pass # Expected - file doesn't exist
|
||||
except RuntimeError as e:
|
||||
# If we get a 502 error, skip the test
|
||||
if "502" in str(e):
|
||||
self.skipTest(f"httpbin.org unavailable: {e}")
|
||||
raise
|
||||
|
||||
asyncio.run(run_test())
|
||||
|
||||
|
||||
@@ -38,6 +38,9 @@ fi
|
||||
binary=$(readlink -f "$binary")
|
||||
chmod +x "$binary"
|
||||
|
||||
# make sure no autostart is configured:
|
||||
rm "$scriptdir"/../internal_filesystem/data/com.micropythonos.settings/config.json
|
||||
|
||||
one_test() {
|
||||
file="$1"
|
||||
if [ ! -f "$file" ]; then
|
||||
|
||||
Reference in New Issue
Block a user