From 688b1ac0e4113940d096875d86639f6678de782e Mon Sep 17 00:00:00 2001 From: grossmj Date: Wed, 8 Jan 2020 07:10:33 +0800 Subject: [PATCH] Fix tests. --- tests/compute/test_manager.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tests/compute/test_manager.py b/tests/compute/test_manager.py index 8a1634fb..43a5e41b 100644 --- a/tests/compute/test_manager.py +++ b/tests/compute/test_manager.py @@ -224,11 +224,13 @@ def test_get_relative_image_path(qemu, tmpdir, config): def test_list_images(loop, qemu, tmpdir): fake_images = ["a.qcow2", "b.qcow2", ".blu.qcow2", "a.qcow2.md5sum"] + tmp_images_dir = os.path.join(tmpdir, "images") + os.makedirs(tmp_images_dir, exist_ok=True) for image in fake_images: - with open(str(tmpdir / image), "w+") as f: + with open(os.path.join(tmp_images_dir, image), "w+") as f: f.write("1") - with patch("gns3server.utils.images.default_images_directory", return_value=str(tmpdir)): + with patch("gns3server.utils.images.default_images_directory", return_value=str(tmp_images_dir)): assert sorted(loop.run_until_complete(qemu.list_images()), key=lambda k: k['filename']) == [ {"filename": "a.qcow2", "path": "a.qcow2", "md5sum": "c4ca4238a0b923820dcc509a6f75849b", "filesize": 1}, {"filename": "b.qcow2", "path": "b.qcow2", "md5sum": "c4ca4238a0b923820dcc509a6f75849b", "filesize": 1} @@ -237,17 +239,19 @@ def test_list_images(loop, qemu, tmpdir): def test_list_images_recursives(loop, qemu, tmpdir): + tmp_images_dir = os.path.join(tmpdir, "images") + os.makedirs(tmp_images_dir, exist_ok=True) fake_images = ["a.qcow2", "b.qcow2", ".blu.qcow2", "a.qcow2.md5sum"] for image in fake_images: - with open(str(tmpdir / image), "w+") as f: + with open(os.path.join(tmp_images_dir, image), "w+") as f: f.write("1") - os.makedirs(str(tmpdir / "c")) + os.makedirs(os.path.join(tmp_images_dir, "c")) fake_images = ["c.qcow2", "c.qcow2.md5sum"] for image in fake_images: - with open(str(tmpdir / "c" / image), "w+") as f: + with open(os.path.join(tmp_images_dir, "c", image), "w+") as f: f.write("1") - with patch("gns3server.utils.images.default_images_directory", return_value=str(tmpdir)): + with patch("gns3server.utils.images.default_images_directory", return_value=str(tmp_images_dir)): assert sorted(loop.run_until_complete(qemu.list_images()), key=lambda k: k['filename']) == [ {"filename": "a.qcow2", "path": "a.qcow2", "md5sum": "c4ca4238a0b923820dcc509a6f75849b", "filesize": 1},