From a961387af92b8cd0b7b8c59e690b8720f39b2d4d Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Sat, 31 Oct 2015 21:27:10 +0100 Subject: [PATCH 1/2] Add doc on how to got code coverage --- README.rst | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README.rst b/README.rst index d70fa7d2..f2408f9d 100644 --- a/README.rst +++ b/README.rst @@ -113,4 +113,17 @@ and homebrew: http://brew.sh/. python3 setup.py install gns3server +Running tests +************* +Just run: + +.. code:: bash + + py.test -vv + +If you want test coverage: + +.. code:: bash + + py.test --cov=gns3server From bd54c55ae1ea96af545b133bcad5bb7e930267b4 Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Tue, 3 Nov 2015 12:34:22 +0100 Subject: [PATCH 2/2] Fix minor errors reported by codacy.com --- gns3server/modules/port_manager.py | 4 ++-- gns3server/web/logger.py | 1 - tests/conftest.py | 2 +- tests/handlers/test_upload.py | 8 ++++---- tests/modules/vpcs/test_vpcs_vm.py | 9 --------- 5 files changed, 7 insertions(+), 17 deletions(-) diff --git a/gns3server/modules/port_manager.py b/gns3server/modules/port_manager.py index 96f1f622..c74dbbc9 100644 --- a/gns3server/modules/port_manager.py +++ b/gns3server/modules/port_manager.py @@ -91,7 +91,7 @@ class PortManager: return self._console_port_range - @console_host.setter + @console_port_range.setter def console_port_range(self, new_range): assert isinstance(new_range, tuple) @@ -112,7 +112,7 @@ class PortManager: return self._udp_port_range - @udp_host.setter + @udp_port_range.setter def udp_port_range(self, new_range): assert isinstance(new_range, tuple) diff --git a/gns3server/web/logger.py b/gns3server/web/logger.py index 37b4882d..ba5c4736 100644 --- a/gns3server/web/logger.py +++ b/gns3server/web/logger.py @@ -94,7 +94,6 @@ class WinStreamHandler(logging.StreamHandler): stream.write(msg.encode(stream.encoding, errors="replace").decode(stream.encoding)) stream.write(self.terminator) self.flush() - pass except Exception: self.handleError(record) diff --git a/tests/conftest.py b/tests/conftest.py index 68d8a1af..c0b3e3d7 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -73,7 +73,7 @@ def _get_unused_port(): return port -@pytest.fixture(scope="session") +@pytest.fixture def server(request, loop, port_manager, monkeypatch): """A GNS3 server""" diff --git a/tests/handlers/test_upload.py b/tests/handlers/test_upload.py index 2ad8d49c..9381b484 100644 --- a/tests/handlers/test_upload.py +++ b/tests/handlers/test_upload.py @@ -144,10 +144,10 @@ def test_backup_images(server, tmpdir, loop): tar.close() assert os.path.exists(os.path.join('QEMU', 'a.img')) - open(os.path.join('QEMU', 'a.img')).read() == 'hello' + assert open(os.path.join('QEMU', 'a.img')).read() == 'hello' assert os.path.exists(os.path.join('QEMU', 'b.img')) - open(os.path.join('QEMU', 'b.img')).read() == 'world' + assert open(os.path.join('QEMU', 'b.img')).read() == 'world' def test_backup_projects(server, tmpdir, loop): @@ -176,7 +176,7 @@ def test_backup_projects(server, tmpdir, loop): tar.close() assert os.path.exists(os.path.join('a', 'a.gns3')) - open(os.path.join('a', 'a.gns3')).read() == 'hello' + assert open(os.path.join('a', 'a.gns3')).read() == 'hello' assert os.path.exists(os.path.join('b', 'b.gns3')) - open(os.path.join('b', 'b.gns3')).read() == 'world' + assert open(os.path.join('b', 'b.gns3')).read() == 'world' diff --git a/tests/modules/vpcs/test_vpcs_vm.py b/tests/modules/vpcs/test_vpcs_vm.py index df62957f..aef9d79a 100644 --- a/tests/modules/vpcs/test_vpcs_vm.py +++ b/tests/modules/vpcs/test_vpcs_vm.py @@ -171,15 +171,6 @@ def test_update_startup_script(vm): assert f.read() == content -def test_update_startup_script(vm): - content = "echo GNS3 VPCS\nip 192.168.1.2\n" - vm.startup_script = content - filepath = os.path.join(vm.working_dir, 'startup.vpc') - assert os.path.exists(filepath) - with open(filepath) as f: - assert f.read() == content - - def test_update_startup_script_h(vm): content = "setname %h\n" vm.name = "pc1"