Skip to content

Commit

Permalink
refactor: clean up web framework tests
Browse files Browse the repository at this point in the history
Only specify the need to rewrite assertions for
_appmap.test.web_framework once. Improve lint score a bit, too.
  • Loading branch information
apotterri committed Mar 7, 2024
1 parent fa786ce commit 5811e44
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 22 deletions.
4 changes: 2 additions & 2 deletions _appmap/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ def __new__(cls, scope, fn, static_fn):
def fntype(self):
if self.scope == Scope.MODULE:
return FnType.MODULE
else:
return FnType.classify(self.static_fn)

return FnType.classify(self.static_fn)


class Filter(ABC): # pylint: disable=too-few-public-methods
Expand Down
1 change: 0 additions & 1 deletion _appmap/metadata.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Shared metadata gathering"""

import platform
import re
from functools import lru_cache

from . import utils
Expand Down
5 changes: 5 additions & 0 deletions _appmap/test/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import pytest

# Make sure assertions in web_framework get rewritten (e.g. to show
# diffs in generated appmaps)
pytest.register_assert_rewrite("_appmap.test.web_framework")
15 changes: 8 additions & 7 deletions _appmap/test/test_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,39 +84,40 @@ def test_config_no_message(caplog):
assert caplog.text == ""


cf = lambda: ConfigFilter(NullFilter())
def cf():
return ConfigFilter(NullFilter())


@pytest.mark.appmap_enabled(config="appmap-class.yml")
def test_class_included():
f = Filterable("package1.package2.Mod1Class", None)
f = Filterable(None, "package1.package2.Mod1Class", None)
assert cf().filter(f) is True


@pytest.mark.appmap_enabled(config="appmap-func.yml")
def test_function_included():
f = Filterable("package1.package2.Mod1Class.func", None)
f = Filterable(None, "package1.package2.Mod1Class.func", None)
assert cf().filter(f) is True


@pytest.mark.appmap_enabled(config="appmap-class.yml")
def test_function_included_by_class():
f = Filterable("package1.package2.Mod1Class.func", None)
f = Filterable(None, "package1.package2.Mod1Class.func", None)
assert cf().filter(f) is True


@pytest.mark.appmap_enabled
class TestConfiguration:
def test_package_included(self):
f = Filterable("package1.cls", None)
f = Filterable(None, "package1.cls", None)
assert cf().filter(f) is True

def test_function_included_by_package(self):
f = Filterable("package1.package2.Mod1Class.func", None)
f = Filterable(None, "package1.package2.Mod1Class.func", None)
assert cf().filter(f) is True

def test_class_prefix_doesnt_match(self):
f = Filterable("package1_prefix.cls", None)
f = Filterable(None, "package1_prefix.cls", None)
assert cf().filter(f) is False


Expand Down
5 changes: 0 additions & 5 deletions _appmap/test/test_django.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@
from _appmap.metadata import Metadata

from ..test.helpers import DictIncluding

# Make sure assertions in web_framework get rewritten (e.g. to show
# diffs in generated appmaps)
pytest.register_assert_rewrite("_appmap.test.web_framework")

# pylint: disable=unused-import,wrong-import-position
from .web_framework import TestRemoteRecording # pyright:ignore
from .web_framework import TestRequestCapture # pyright: ignore
Expand Down
5 changes: 0 additions & 5 deletions _appmap/test/test_flask.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@
from appmap.flask import AppmapFlask

from ..test.helpers import DictIncluding

# Make sure assertions in web_framework get rewritten (e.g. to show
# diffs in generated appmaps)
pytest.register_assert_rewrite("_appmap.test.web_framework")

# pylint: disable=unused-import,wrong-import-position
from .web_framework import TestRemoteRecording # pyright:ignore
from .web_framework import TestRequestCapture # pyright: ignore
Expand Down
2 changes: 0 additions & 2 deletions appmap/flask.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
import re
import time

import flask
import flask.cli
import jinja2
from flask import g, got_request_exception, request, request_finished, request_started
from flask.cli import ScriptInfo
Expand Down

0 comments on commit 5811e44

Please sign in to comment.