From 181aa4d5149fbf1b19fbf93650bc9a62ab948138 Mon Sep 17 00:00:00 2001 From: gpotter2 <10530980+gpotter2@users.noreply.github.com> Date: Thu, 9 Mar 2023 21:58:23 +0100 Subject: [PATCH] Minor tests & coverage fixes (#3924) * Lord of the fix: The Return of the tests * Various minor test fixes * Appveyor: use new codecov * Better codecov rules --- .appveyor.yml | 3 ++- pyproject.toml | 10 +++------- test/imports.uts | 1 + test/linux.uts | 17 ++++++++++------- test/pipetool.uts | 3 ++- test/regression.uts | 2 +- tox.ini | 21 ++++----------------- 7 files changed, 23 insertions(+), 34 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index c3f0d173c39..65292730e40 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -50,4 +50,5 @@ test_script: after_test: # Run codecov - - "%PYTHON%\\python -m tox -e codecov" + - ps: $ProgressPreference = 'SilentlyContinue'; Invoke-WebRequest -Uri https://uploader.codecov.io/latest/windows/codecov.exe -Outfile codecov.exe + - codecov.exe diff --git a/pyproject.toml b/pyproject.toml index ef7f4453fac..382201cdce9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -79,18 +79,14 @@ version = { attr="scapy.VERSION" } # coverage -[tool.coverage] -concurrency = "multiprocessing" +[tool.coverage.run] +concurrency = [ "thread", "multiprocessing" ] +source = [ "scapy" ] omit = [ # Scapy specific paths "scapy/tools/UTscapy.py", - "test/*", # Scapy external modules "scapy/libs/six.py", "scapy/libs/winpcapy.py", "scapy/libs/ethertypes.py", - # .tox specific path - ".tox/*", - # OS specific paths - "/private/*", ] diff --git a/test/imports.uts b/test/imports.uts index 5984fe57260..a9dca268acc 100644 --- a/test/imports.uts +++ b/test/imports.uts @@ -1,4 +1,5 @@ % Import tests +~ not_pypy + Import tests ~ imports diff --git a/test/linux.uts b/test/linux.uts index 589f1897ac0..67d0d7ba3dd 100644 --- a/test/linux.uts +++ b/test/linux.uts @@ -134,15 +134,14 @@ with patch("scapy.layers.l2.get_if_hwaddr") as mgih: conf.iface = bck_conf_iface conf.route6.resync() -= IPv6 -~ linux += IPv6 - check OS routes +~ linux ipv6 addrs = in6_getifaddr() -if len(addrs) == 0: - assert True -else: - assert all([in6_isvalid(addr[0]) for addr in in6_getifaddr()]) - assert set([addr[2] for addr in in6_getifaddr()]) == conf.route6.ipv6_ifaces +if addrs: + assert all(in6_isvalid(addr[0]) for addr in in6_getifaddr()), 'invalid ipv6 address' + ifaces6 = [addr[2] for addr in in6_getifaddr()] + assert all(iface in ifaces6 for iface in conf.route6.ipv6_ifaces), 'ipv6 interface has route but no real' = veth interface error handling @@ -314,8 +313,12 @@ assert _interface_selection(None, IP(dst="8.8.8.8")/UDP()) == conf.iface exit_status = os.system("ip link add name scapy0 type dummy") exit_status = os.system("ip addr add 192.0.2.1/24 dev scapy0") exit_status = os.system("ip link set scapy0 up") +conf.ifaces.reload() +conf.route.resync() assert _interface_selection(None, IP(dst="192.0.2.42")/UDP()) == "scapy0" exit_status = os.system("ip link del name dev scapy0") +conf.ifaces.reload() +conf.route.resync() = Test 802.Q sniffing ~ linux needs_root veth diff --git a/test/pipetool.uts b/test/pipetool.uts index c1673b25f99..7689e52d998 100644 --- a/test/pipetool.uts +++ b/test/pipetool.uts @@ -720,5 +720,6 @@ s.send(bytes(HTTP()/HTTPRequest(Host="www.google.com"))) result = c.q.get(timeout=10) p.stop() -assert result.startswith(b"HTTP/1.1 200 OK") +result +assert result.startswith(b"HTTP/1.1 200 OK") or result.startswith(b"HTTP/1.1 302 Found") diff --git a/test/regression.uts b/test/regression.uts index 338ece79135..6797ca7c6cb 100644 --- a/test/regression.uts +++ b/test/regression.uts @@ -225,7 +225,7 @@ except: assert not conf.use_bpf = Configuration conf.use_pcap -~ linux +~ linux libpcap if not conf.use_pcap: assert not conf.iface.provider.libpcap diff --git a/tox.ini b/tox.ini index 50466219968..cd85bd7c808 100644 --- a/tox.ini +++ b/tox.ini @@ -3,8 +3,8 @@ [tox] -envlist = py{27,34,35,36,37,38,39,310,py27,py39}-{linux,bsd}_{non_root,root}, - py{27,34,35,36,37,38,39,310,py27,py39}-windows, +envlist = py{27,34,35,36,37,38,39,310,311,py27,py39}-{linux,bsd}_{non_root,root}, + py{27,34,35,36,37,38,39,310,311,py27,py39}-windows, skip_missing_interpreters = true minversion = 4.0 @@ -44,6 +44,7 @@ commands = bsd_non_root: {envpython} {env:SCAPY_PY_OPTS:-m coverage run} -m scapy.tools.UTscapy -c test/configs/bsd.utsc -K manufdb -K tshark -N {posargs} bsd_root: sudo -E {envpython} {env:SCAPY_PY_OPTS:-m coverage run} -m scapy.tools.UTscapy -c test/configs/bsd.utsc -K manufdb -K tshark {posargs} windows: {envpython} {env:SCAPY_PY_OPTS:-m coverage run} -m scapy.tools.UTscapy -c test/configs/windows.utsc {posargs} + coverage combine coverage xml -i # Variants of the main tests @@ -72,6 +73,7 @@ commands = bash -c "rm -rf /tmp/can-utils /tmp/can-isotp" lsmod sudo -E {envpython} -m coverage run -m scapy.tools.UTscapy -c ./test/configs/linux.utsc {posargs} + coverage combine coverage xml -i # Test used by upstream pyca/cryptography @@ -83,21 +85,6 @@ commands = python -c "import cryptography; print('DEBUG: cryptography %s' % cryptography.__version__)" python -m scapy.tools.UTscapy -c ./test/configs/cryptography.utsc -# Specific functions or tests - -[testenv:codecov] -description = "Upload coverage results to codecov" -passenv = - TOXENV - CI - TRAVIS - TRAVIS_* - APPVEYOR - APPVEYOR_* -deps = codecov -commands = codecov -e TOXENV - - # The files listed past the first argument of the sphinx-apidoc command are ignored [testenv:apitree] description = "Regenerates the API reference doc tree"