Use pytest 2.8 so it's work with Python 3.5 without warning

This commit is contained in:
Julien Duponchelle 2015-11-02 16:34:34 +01:00
parent 82540e5366
commit 69c38c6414
5 changed files with 47 additions and 46 deletions

1
.gitignore vendored
View File

@ -24,6 +24,7 @@ pip-log.txt
# Unit test / coverage reports # Unit test / coverage reports
.coverage .coverage
.tox .tox
.cache
nosetests.xml nosetests.xml
# Translations # Translations

View File

@ -1,7 +1,7 @@
-rrequirements.txt -rrequirements.txt
sphinx==1.2.3 sphinx==1.2.3
pytest==2.6.4 pytest==2.8.2
pep8==1.5.7 pep8==1.5.7
pytest-timeout pytest-timeout
pytest-capturelog pytest-capturelog

View File

@ -1426,6 +1426,8 @@ class QemuVM(BaseVM):
:returns: Boolean True if we need to enable KVM :returns: Boolean True if we need to enable KVM
""" """
print(sys.platform.startswith("linux"))
print(self.manager.config.get_section_config("Qemu").getboolean("enable_kvm", True))
if sys.platform.startswith("linux") and self.manager.config.get_section_config("Qemu").getboolean("enable_kvm", True) \ if sys.platform.startswith("linux") and self.manager.config.get_section_config("Qemu").getboolean("enable_kvm", True) \
and "-no-kvm" not in options: and "-no-kvm" not in options:

View File

@ -77,7 +77,7 @@ def _get_unused_port():
return port return port
@pytest.fixture(scope="session") @pytest.fixture
def server(request, loop, port_manager, monkeypatch): def server(request, loop, port_manager, monkeypatch):
"""A GNS3 server""" """A GNS3 server"""

View File

@ -389,45 +389,50 @@ def test_build_command_with_invalid_options(vm, loop, fake_qemu_binary):
def test_hda_disk_image(vm, tmpdir): def test_hda_disk_image(vm, tmpdir):
with patch("gns3server.config.Config.get_section_config", return_value={"images_path": str(tmpdir)}): vm.manager.config.set("Server", "images_path", str(tmpdir))
vm.hda_disk_image = "/tmp/test"
assert vm.hda_disk_image == "/tmp/test" vm.hda_disk_image = "/tmp/test"
vm.hda_disk_image = "test" assert vm.hda_disk_image == "/tmp/test"
assert vm.hda_disk_image == str(tmpdir / "QEMU" / "test") vm.hda_disk_image = "test"
assert vm.hda_disk_image == str(tmpdir / "QEMU" / "test")
def test_hda_disk_image_ova(vm, tmpdir): def test_hda_disk_image_ova(vm, tmpdir):
with patch("gns3server.config.Config.get_section_config", return_value={"images_path": str(tmpdir)}): vm.manager.config.set("Server", "images_path", str(tmpdir))
vm.hda_disk_image = "test.ovf/test.vmdk"
assert vm.hda_disk_image == str(tmpdir / "QEMU" / "test.ovf" / "test.vmdk") vm.hda_disk_image = "test.ovf/test.vmdk"
assert vm.hda_disk_image == str(tmpdir / "QEMU" / "test.ovf" / "test.vmdk")
def test_hdb_disk_image(vm, tmpdir): def test_hdb_disk_image(vm, tmpdir):
with patch("gns3server.config.Config.get_section_config", return_value={"images_path": str(tmpdir)}): vm.manager.config.set("Server", "images_path", str(tmpdir))
vm.hdb_disk_image = "/tmp/test"
assert vm.hdb_disk_image == "/tmp/test" vm.hdb_disk_image = "/tmp/test"
vm.hdb_disk_image = "test" assert vm.hdb_disk_image == "/tmp/test"
assert vm.hdb_disk_image == str(tmpdir / "QEMU" / "test") vm.hdb_disk_image = "test"
assert vm.hdb_disk_image == str(tmpdir / "QEMU" / "test")
def test_hdc_disk_image(vm, tmpdir): def test_hdc_disk_image(vm, tmpdir):
with patch("gns3server.config.Config.get_section_config", return_value={"images_path": str(tmpdir)}): vm.manager.config.set("Server", "images_path", str(tmpdir))
vm.hdc_disk_image = "/tmp/test"
assert vm.hdc_disk_image == "/tmp/test" vm.hdc_disk_image = "/tmp/test"
vm.hdc_disk_image = "test" assert vm.hdc_disk_image == "/tmp/test"
assert vm.hdc_disk_image == str(tmpdir / "QEMU" / "test") vm.hdc_disk_image = "test"
assert vm.hdc_disk_image == str(tmpdir / "QEMU" / "test")
def test_hdd_disk_image(vm, tmpdir): def test_hdd_disk_image(vm, tmpdir):
with patch("gns3server.config.Config.get_section_config", return_value={"images_path": str(tmpdir)}): vm.manager.config.set("Server", "images_path", str(tmpdir))
vm.hdd_disk_image = "/tmp/test"
assert vm.hdd_disk_image == "/tmp/test" vm.hdd_disk_image = "/tmp/test"
vm.hdd_disk_image = "test" assert vm.hdd_disk_image == "/tmp/test"
assert vm.hdd_disk_image == str(tmpdir / "QEMU" / "test") vm.hdd_disk_image = "test"
assert vm.hdd_disk_image == str(tmpdir / "QEMU" / "test")
def test_options(vm): def test_options(vm):
@ -455,48 +460,41 @@ def test_get_qemu_img_not_exist(vm, tmpdir):
def test_run_with_kvm_darwin(darwin_platform, vm): def test_run_with_kvm_darwin(darwin_platform, vm):
with patch("configparser.SectionProxy.getboolean", return_value=True): vm.manager.config.set("Qemu", "enable_kvm", False)
assert vm._run_with_kvm("qemu-system-x86_64", "") is False assert vm._run_with_kvm("qemu-system-x86_64", "") is False
def test_run_with_kvm_windows(windows_platform, vm): def test_run_with_kvm_windows(windows_platform, vm):
with patch("configparser.SectionProxy.getboolean", return_value=True): vm.manager.config.set("Qemu", "enable_kvm", False)
assert vm._run_with_kvm("qemu-system-x86_64.exe", "") is False assert vm._run_with_kvm("qemu-system-x86_64.exe", "") is False
def test_run_with_kvm_linux(linux_platform, vm): def test_run_with_kvm_linux(linux_platform, vm):
with patch("os.path.exists", return_value=True) as os_path: with patch("os.path.exists", return_value=True) as os_path:
with patch("configparser.SectionProxy.getboolean", return_value=True): vm.manager.config.set("Qemu", "enable_kvm", True)
assert vm._run_with_kvm("qemu-system-x86_64", "") is True assert vm._run_with_kvm("qemu-system-x86_64", "") is True
os_path.assert_called_with("/dev/kvm") os_path.assert_called_with("/dev/kvm")
def test_run_with_kvm_linux_config_desactivated(linux_platform, vm):
with patch("os.path.exists", return_value=True) as os_path:
with patch("configparser.SectionProxy.getboolean", return_value=False):
assert vm._run_with_kvm("qemu-system-x86_64", "") is False
def test_run_with_kvm_linux_options_no_kvm(linux_platform, vm): def test_run_with_kvm_linux_options_no_kvm(linux_platform, vm):
with patch("os.path.exists", return_value=True) as os_path: with patch("os.path.exists", return_value=True) as os_path:
with patch("configparser.SectionProxy.getboolean", return_value=True): vm.manager.config.set("Qemu", "enable_kvm", True)
assert vm._run_with_kvm("qemu-system-x86_64", "-no-kvm") is False assert vm._run_with_kvm("qemu-system-x86_64", "-no-kvm") is False
def test_run_with_kvm_not_x86(linux_platform, vm): def test_run_with_kvm_not_x86(linux_platform, vm):
with patch("os.path.exists", return_value=True) as os_path: with patch("os.path.exists", return_value=True) as os_path:
with patch("configparser.SectionProxy.getboolean", return_value=True): vm.manager.config.set("Qemu", "enable_kvm", True)
assert vm._run_with_kvm("qemu-system-arm", "") is False assert vm._run_with_kvm("qemu-system-arm", "") is False
def test_run_with_kvm_linux_dev_kvm_missing(linux_platform, vm): def test_run_with_kvm_linux_dev_kvm_missing(linux_platform, vm):
with patch("os.path.exists", return_value=False) as os_path: with patch("os.path.exists", return_value=False) as os_path:
with patch("configparser.SectionProxy.getboolean", return_value=True): vm.manager.config.set("Qemu", "enable_kvm", True)
with pytest.raises(QemuError): with pytest.raises(QemuError):
vm._run_with_kvm("qemu-system-x86_64", "") vm._run_with_kvm("qemu-system-x86_64", "")