refactor: ruff autofixes

This commit is contained in:
Mark Paronyan committed 2026-09-27 15:55:10 +03:00
1 parent 2ac637c662
commit a0450b6bce
455 files changed
+12322 -14762

No files matched your search

+48 -59
View File
@@ -49,48 +49,48 @@ def test_images_directories(tmpdir, config):
def test_md5sum(tmpdir):
fake_img = str(tmpdir / 'hello载')
fake_img = str(tmpdir / "hello载")
with open(fake_img, 'w+') as f:
f.write('hello')
with open(fake_img, "w+") as f:
f.write("hello")
assert md5sum(fake_img) == '5d41402abc4b2a76b9719d911017c592'
with open(str(tmpdir / 'hello载.md5sum')) as f:
assert f.read() == '5d41402abc4b2a76b9719d911017c592'
assert md5sum(fake_img) == "5d41402abc4b2a76b9719d911017c592"
with open(str(tmpdir / "hello载.md5sum")) as f:
assert f.read() == "5d41402abc4b2a76b9719d911017c592"
def test_md5sum_stopped_event(tmpdir):
fake_img = str(tmpdir / 'hello_stopped')
with open(fake_img, 'w+') as f:
f.write('hello')
fake_img = str(tmpdir / "hello_stopped")
with open(fake_img, "w+") as f:
f.write("hello")
event = threading.Event()
event.set()
assert md5sum(fake_img, stopped_event=event) is None
assert not os.path.exists(str(tmpdir / 'hello_stopped.md5sum'))
assert not os.path.exists(str(tmpdir / "hello_stopped.md5sum"))
def test_md5sum_existing_digest(tmpdir):
fake_img = str(tmpdir / 'hello')
fake_img = str(tmpdir / "hello")
with open(fake_img, 'w+') as f:
f.write('hello')
with open(fake_img, "w+") as f:
f.write("hello")
with open(str(tmpdir / 'hello.md5sum'), 'w+') as f:
f.write('aaaaa02abc4b2a76b9719d911017c592')
with open(str(tmpdir / "hello.md5sum"), "w+") as f:
f.write("aaaaa02abc4b2a76b9719d911017c592")
assert md5sum(fake_img) == 'aaaaa02abc4b2a76b9719d911017c592'
assert md5sum(fake_img) == "aaaaa02abc4b2a76b9719d911017c592"
def test_md5sum_existing_digest_but_missing_image(tmpdir):
fake_img = str(tmpdir / 'hello')
fake_img = str(tmpdir / "hello")
with open(str(tmpdir / 'hello.md5sum'), 'w+') as f:
f.write('aaaaa02abc4b2a76b9719d911017c592')
with open(str(tmpdir / "hello.md5sum"), "w+") as f:
f.write("aaaaa02abc4b2a76b9719d911017c592")
assert md5sum(fake_img) is None
@@ -102,13 +102,13 @@ def test_md5sum_none(tmpdir):
def test_remove_checksum(tmpdir):
with open(str(tmpdir / 'hello.md5sum'), 'w+') as f:
f.write('aaaaa02abc4b2a76b9719d911017c592')
remove_checksum(str(tmpdir / 'hello'))
with open(str(tmpdir / "hello.md5sum"), "w+") as f:
f.write("aaaaa02abc4b2a76b9719d911017c592")
remove_checksum(str(tmpdir / "hello"))
assert not os.path.exists(str(tmpdir / 'hello.md5sum'))
assert not os.path.exists(str(tmpdir / "hello.md5sum"))
remove_checksum(str(tmpdir / 'not_exists'))
remove_checksum(str(tmpdir / "not_exists"))
@pytest.mark.asyncio
@@ -116,34 +116,33 @@ async def test_list_images(tmpdir, config):
# IOS image in the images directory
ios_image_1 = tmpdir / "images1" / "IOS" / "ios_image_1.image"
ios_image_1.write(b'\x7fELF\x01\x02\x01', ensure=True)
ios_image_1.write(b"\x7fELF\x01\x02\x01", ensure=True)
ios_image_1 = force_unix_path(str(ios_image_1))
# IOS image in an additional images path
ios_image_2 = tmpdir / "images2" / "ios_image_2.image"
ios_image_2.write(b'\x7fELF\x01\x02\x01', ensure=True)
ios_image_2.write(b"\x7fELF\x01\x02\x01", ensure=True)
ios_image_2 = force_unix_path(str(ios_image_2))
# Not a valid elf file
not_elf_file = tmpdir / "images1" / "IOS" / "not_elf.image"
not_elf_file.write(b'NOTANELF', ensure=True)
not_elf_file.write(b"NOTANELF", ensure=True)
not_elf_file = force_unix_path(str(not_elf_file))
# Invalid image because it is very small
small_file = tmpdir / "images1" / "too_small.image"
small_file.write(b'1', ensure=True)
small_file.write(b"1", ensure=True)
if sys.platform.startswith("linux"):
# 64-bit IOU image
iou_image_1 = tmpdir / "images1" / "IOU" / "iou64.bin"
iou_image_1.write(b'\x7fELF\x02\x01\x01', ensure=True)
iou_image_1.write(b"\x7fELF\x02\x01\x01", ensure=True)
iou_image_1 = force_unix_path(str(iou_image_1))
# 32-bit IOU image
iou_image_2 = tmpdir / "images1" / "IOU" / "iou32.bin"
iou_image_2.write(b'\x7fELF\x01\x01\x01', ensure=True) # 32-bit IOU image
iou_image_2.write(b"\x7fELF\x01\x01\x01", ensure=True) # 32-bit IOU image
iou_image_2 = force_unix_path(str(iou_image_2))
# Qemu image
qemu_image_1 = tmpdir / "images1" / "QEMU" / "qemu_image.qcow2"
qemu_image_1.write("1234567", ensure=True)
@@ -151,7 +150,7 @@ async def test_list_images(tmpdir, config):
# ELF file inside the Qemu
elf_file = tmpdir / "images1" / "QEMU" / "elf_file.bin"
elf_file.write(b'\x7fELF\x02\x01\x01', ensure=True) # ELF file
elf_file.write(b"\x7fELF\x02\x01\x01", ensure=True) # ELF file
elf_file = force_unix_path(str(elf_file))
md5sum_file = tmpdir / "images1" / "QEMU" / "image.qcow2.md5sum"
@@ -161,42 +160,32 @@ async def test_list_images(tmpdir, config):
config.settings.Server.images_path = str(tmpdir / "images1")
config.settings.Server.additional_images_paths = "/tmp/null24564;" + str(tmpdir / "images2")
assert sorted(await list_images("dynamips"), key=lambda k: k['filename']) == [
assert sorted(await list_images("dynamips"), key=lambda k: k["filename"]) == [
{
'filename': 'ios_image_1.image',
'filesize': 7,
'md5sum': 'b0d5aa897d937aced5a6b1046e8f7e2e',
'path': 'ios_image_1.image'
"filename": "ios_image_1.image",
"filesize": 7,
"md5sum": "b0d5aa897d937aced5a6b1046e8f7e2e",
"path": "ios_image_1.image",
},
{
'filename': 'ios_image_2.image',
'filesize': 7,
'md5sum': 'b0d5aa897d937aced5a6b1046e8f7e2e',
'path': str(ios_image_2)
}
"filename": "ios_image_2.image",
"filesize": 7,
"md5sum": "b0d5aa897d937aced5a6b1046e8f7e2e",
"path": str(ios_image_2),
},
]
if sys.platform.startswith("linux"):
assert sorted(await list_images("iou"), key=lambda k: k['filename']) == [
{
'filename': 'iou32.bin',
'filesize': 7,
'md5sum': 'e573e8f5c93c6c00783f20c7a170aa6c',
'path': 'iou32.bin'
},
{
'filename': 'iou64.bin',
'filesize': 7,
'md5sum': 'c73626d23469519894d58bc98bee9655',
'path': 'iou64.bin'
}
assert sorted(await list_images("iou"), key=lambda k: k["filename"]) == [
{"filename": "iou32.bin", "filesize": 7, "md5sum": "e573e8f5c93c6c00783f20c7a170aa6c", "path": "iou32.bin"},
{"filename": "iou64.bin", "filesize": 7, "md5sum": "c73626d23469519894d58bc98bee9655", "path": "iou64.bin"},
]
assert await list_images("qemu") == [
{
'filename': 'qemu_image.qcow2',
'filesize': 7,
'md5sum': 'fcea920f7412b5da7be0cf42b8c93759',
'path': 'qemu_image.qcow2'
"filename": "qemu_image.qcow2",
"filesize": 7,
"md5sum": "fcea920f7412b5da7be0cf42b8c93759",
"path": "qemu_image.qcow2",
}
]