Skip to content

Commit

Permalink
tests: speedups, lowest-version, ... (#6812)
Browse files Browse the repository at this point in the history
  • Loading branch information
mhils committed Apr 21, 2024
1 parent 2c96c96 commit aedbde9
Show file tree
Hide file tree
Showing 9 changed files with 221 additions and 286 deletions.
16 changes: 15 additions & 1 deletion .github/workflows/main.yml
Expand Up @@ -77,6 +77,19 @@ jobs:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage.xml

test-old-dependencies:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
fetch-depth: 0
- uses: actions/setup-python@v5
with:
python-version-file: .github/python-version.txt
- run: pip install tox-uv
- run: tox -e old-dependencies

build:
strategy:
fail-fast: false
Expand Down Expand Up @@ -208,8 +221,9 @@ jobs:
- mypy
- individual-coverage
- test
- build
- test-old-dependencies
- test-web-ui
- build
- docs
uses: mhils/workflows/.github/workflows/alls-green.yml@main
with:
Expand Down
8 changes: 4 additions & 4 deletions mitmproxy/net/local_ip.py
Expand Up @@ -13,9 +13,9 @@ def get_local_ip(reachable: str = "8.8.8.8") -> str | None:
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
try:
s.connect((reachable, 80))
return s.getsockname()[0]
return s.getsockname()[0] # pragma: no cover
except OSError:
return None
return None # pragma: no cover
finally:
s.close()

Expand All @@ -29,8 +29,8 @@ def get_local_ip6(reachable: str = "2001:4860:4860::8888") -> str | None:
s = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
try:
s.connect((reachable, 80))
return s.getsockname()[0]
return s.getsockname()[0] # pragma: no cover
except OSError:
return None
return None # pragma: no cover
finally:
s.close()
12 changes: 9 additions & 3 deletions mitmproxy/proxy/mode_servers.py
Expand Up @@ -204,7 +204,9 @@ async def handle_stream(
else:
handler.layer.context.client.sockname = original_dst
handler.layer.context.server.address = original_dst
elif isinstance(self.mode, (mode_specs.WireGuardMode, mode_specs.LocalMode)):
elif isinstance(
self.mode, (mode_specs.WireGuardMode, mode_specs.LocalMode)
): # pragma: no cover on platforms without wg-test-client
handler.layer.context.server.address = writer.get_extra_info(
"remote_endpoint", handler.layer.context.client.sockname
)
Expand Down Expand Up @@ -325,7 +327,9 @@ class WireGuardServerInstance(ServerInstance[mode_specs.WireGuardMode]):
server_key: str
client_key: str

def make_top_layer(self, context: Context) -> Layer:
def make_top_layer(
self, context: Context
) -> Layer: # pragma: no cover on platforms without wg-test-client
return layers.modes.TransparentProxy(context)

@property
Expand Down Expand Up @@ -418,7 +422,9 @@ async def _stop(self) -> None:
finally:
self._server = None

async def wg_handle_stream(self, stream: mitmproxy_rs.Stream) -> None:
async def wg_handle_stream(
self, stream: mitmproxy_rs.Stream
) -> None: # pragma: no cover on platforms without wg-test-client
await self.handle_stream(stream, stream)


Expand Down
116 changes: 104 additions & 12 deletions pyproject.toml
Expand Up @@ -36,7 +36,7 @@ dependencies = [
"Brotli>=1.0,<1.2",
"certifi>=2019.9.11", # no semver here - this should always be on the last release!
"cryptography>=42.0,<42.1",
"flask>=1.1.1,<3.1",
"flask>=3.0,<3.1",
"h11>=0.11,<0.15",
"h2>=4.1,<5",
"hyperframe>=6.0,<7",
Expand All @@ -57,7 +57,7 @@ dependencies = [
"urwid-mitmproxy>=2.1.1,<2.2",
"wsproto>=1.0,<1.3",
"publicsuffix2>=2.20190812,<3",
"zstandard>=0.11,<0.23",
"zstandard>=0.15,<0.23",
]

[project.optional-dependencies]
Expand All @@ -66,11 +66,11 @@ dev = [
"hypothesis>=5.8,<7",
"pdoc>=4.0.0",
"pyinstaller==6.5.0",
"pytest-asyncio>=0.23,<0.24",
"pytest-cov>=2.7.1,<5.1",
"pytest-timeout>=1.3.3,<2.4",
"pytest-xdist>=2.1.0,<3.6",
"pytest>=6.1.0,<9",
"pytest-asyncio>=0.23.6,<0.24",
"pytest-cov>=5.0.0,<5.1",
"pytest-timeout>=2.3.1,<2.4",
"pytest-xdist>=3.6.0,<3.7",
"pytest>=8.1.1,<9",
"requests>=2.9.1,<3",
"tox>=3.5,<5",
"wheel>=0.36.2,<0.44",
Expand Down Expand Up @@ -137,6 +137,93 @@ filterwarnings = [
"default:coroutine 'ConnectionHandler.hook_task' was never awaited:RuntimeWarning",
]

[tool.pytest.individual_coverage]
exclude = [
"mitmproxy/addons/__init__.py",
"mitmproxy/addons/onboarding.py",
"mitmproxy/addons/onboardingapp/__init__.py",
"mitmproxy/contentviews/__init__.py",
"mitmproxy/contentviews/base.py",
"mitmproxy/contentviews/grpc.py",
"mitmproxy/contentviews/image/__init__.py",
"mitmproxy/contrib/*",
"mitmproxy/ctx.py",
"mitmproxy/exceptions.py",
"mitmproxy/flow.py",
"mitmproxy/io/__init__.py",
"mitmproxy/io/io.py",
"mitmproxy/io/tnetstring.py",
"mitmproxy/log.py",
"mitmproxy/master.py",
"mitmproxy/net/check.py",
"mitmproxy/net/http/cookies.py",
"mitmproxy/net/http/http1/__init__.py",
"mitmproxy/net/http/multipart.py",
"mitmproxy/net/tls.py",
"mitmproxy/platform/__init__.py",
"mitmproxy/platform/linux.py",
"mitmproxy/platform/openbsd.py",
"mitmproxy/platform/osx.py",
"mitmproxy/platform/pf.py",
"mitmproxy/platform/windows.py",
"mitmproxy/proxy/__init__.py",
"mitmproxy/proxy/layers/__init__.py",
"mitmproxy/proxy/layers/http/__init__.py",
"mitmproxy/proxy/layers/http/_base.py",
"mitmproxy/proxy/layers/http/_events.py",
"mitmproxy/proxy/layers/http/_hooks.py",
"mitmproxy/proxy/layers/http/_http1.py",
"mitmproxy/proxy/layers/http/_http2.py",
"mitmproxy/proxy/layers/http/_http3.py",
"mitmproxy/proxy/layers/http/_http_h2.py",
"mitmproxy/proxy/layers/http/_http_h3.py",
"mitmproxy/proxy/layers/http/_upstream_proxy.py",
"mitmproxy/proxy/layers/tls.py",
"mitmproxy/proxy/server.py",
"mitmproxy/script/__init__.py",
"mitmproxy/test/taddons.py",
"mitmproxy/test/tflow.py",
"mitmproxy/test/tutils.py",
"mitmproxy/tools/console/__init__.py",
"mitmproxy/tools/console/commander/commander.py",
"mitmproxy/tools/console/commandexecutor.py",
"mitmproxy/tools/console/commands.py",
"mitmproxy/tools/console/common.py",
"mitmproxy/tools/console/consoleaddons.py",
"mitmproxy/tools/console/eventlog.py",
"mitmproxy/tools/console/flowdetailview.py",
"mitmproxy/tools/console/flowlist.py",
"mitmproxy/tools/console/flowview.py",
"mitmproxy/tools/console/grideditor/__init__.py",
"mitmproxy/tools/console/grideditor/base.py",
"mitmproxy/tools/console/grideditor/col_bytes.py",
"mitmproxy/tools/console/grideditor/col_subgrid.py",
"mitmproxy/tools/console/grideditor/col_text.py",
"mitmproxy/tools/console/grideditor/col_viewany.py",
"mitmproxy/tools/console/grideditor/editors.py",
"mitmproxy/tools/console/help.py",
"mitmproxy/tools/console/keybindings.py",
"mitmproxy/tools/console/keymap.py",
"mitmproxy/tools/console/layoutwidget.py",
"mitmproxy/tools/console/master.py",
"mitmproxy/tools/console/options.py",
"mitmproxy/tools/console/overlay.py",
"mitmproxy/tools/console/quickhelp.py",
"mitmproxy/tools/console/searchable.py",
"mitmproxy/tools/console/signals.py",
"mitmproxy/tools/console/statusbar.py",
"mitmproxy/tools/console/tabs.py",
"mitmproxy/tools/console/window.py",
"mitmproxy/tools/main.py",
"mitmproxy/tools/web/__init__.py",
"mitmproxy/tools/web/app.py",
"mitmproxy/tools/web/master.py",
"mitmproxy/tools/web/webaddons.py",
"mitmproxy/utils/bits.py",
"mitmproxy/utils/pyinstaller/*",
"mitmproxy/utils/vt_codes.py",
]

[tool.mypy]
check_untyped_defs = true
ignore_missing_imports = true
Expand Down Expand Up @@ -164,12 +251,14 @@ module = "test.*"
ignore_errors = true

[tool.ruff]
select = ["E", "F", "I"]
extend-exclude = ["mitmproxy/contrib/"]

[tool.ruff.lint]
select = ["E", "F", "I"]
ignore = ["F541", "E501"]


[tool.ruff.isort]
[tool.ruff.lint.isort]
# these rules are a bit weird, but they mimic our existing reorder_python_imports style.
# if we break compatibility here, consider removing all customization + enforce absolute imports.
force-single-line = true
Expand All @@ -191,15 +280,18 @@ deps =
setenv = HOME = {envtmpdir}
commands =
mitmdump --version
pytest --timeout 60 -vv --cov-report xml \
pytest --timeout 60 -vv \
--cov-report xml \
--continue-on-collection-errors \
--cov=mitmproxy --cov=release \
--full-cov=mitmproxy/ \
{posargs}
[testenv:old-dependencies]
uv_resolution = lowest-direct
[testenv:lint]
deps =
ruff>=0.1.3,<0.2
ruff>=0.4.1,<0.5
commands =
ruff .
Expand Down
31 changes: 0 additions & 31 deletions setup.cfg

This file was deleted.

2 changes: 0 additions & 2 deletions test/conftest.py
Expand Up @@ -9,8 +9,6 @@

from mitmproxy.utils import data

pytest_plugins = ("test.full_coverage_plugin",)

skip_windows = pytest.mark.skipif(os.name == "nt", reason="Skipping due to Windows")

skip_not_windows = pytest.mark.skipif(
Expand Down

0 comments on commit aedbde9

Please sign in to comment.