Skip to content

Commit fd0fd01

Browse files
Fix Type Constructor Classes in Code Level Metrics (#708)
* Fix CLM exception catching * Reorganize CLM Tests * Add type constructor tests to CLM * Fix line number * Pin tox version * Fix lambda tests in CLM * Fix lint issues * Turn helper func into pytest fixture Co-authored-by: Hannah Stepanek <[email protected]>
1 parent f977ba6 commit fd0fd01

File tree

4 files changed

+340
-142
lines changed

4 files changed

+340
-142
lines changed

.github/actions/setup-python-matrix/action.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,4 @@ runs:
4747
shell: bash
4848
run: |
4949
python3.10 -m pip install -U pip
50-
python3.10 -m pip install -U wheel setuptools tox virtualenv!=20.0.24
50+
python3.10 -m pip install -U wheel setuptools 'tox<4' virtualenv!=20.0.24

newrelic/core/code_level_metrics.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def extract_code_from_callable(func):
8989
# Use inspect to get file and line number
9090
file_path = inspect.getsourcefile(func)
9191
line_number = inspect.getsourcelines(func)[1]
92-
except TypeError:
92+
except Exception:
9393
pass
9494

9595
# Split function path to extract class name

tests/agent_features/_test_code_level_metrics.py

+38-3
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@
1313
# limitations under the License.
1414
import functools
1515

16+
1617
def exercise_function():
1718
return
1819

1920

20-
class ExerciseClass():
21+
class ExerciseClass(object):
2122
def exercise_method(self):
2223
return
2324

@@ -30,12 +31,46 @@ def exercise_class_method(cls):
3031
return
3132

3233

33-
class ExerciseClassCallable():
34+
class ExerciseClassCallable(object):
3435
def __call__(self):
3536
return
3637

38+
39+
def exercise_method(self):
40+
return
41+
42+
43+
@staticmethod
44+
def exercise_static_method():
45+
return
46+
47+
48+
@classmethod
49+
def exercise_class_method(cls):
50+
return
51+
52+
53+
def __call__(self):
54+
return
55+
56+
57+
type_dict = {
58+
"exercise_method": exercise_method,
59+
"exercise_static_method": exercise_static_method,
60+
"exercise_class_method": exercise_class_method,
61+
"exercise_lambda": lambda: None,
62+
}
63+
callable_type_dict = type_dict.copy()
64+
callable_type_dict["__call__"] = __call__
65+
66+
ExerciseTypeConstructor = type("ExerciseTypeConstructor", (object,), type_dict)
67+
ExerciseTypeConstructorCallable = type("ExerciseTypeConstructorCallable", (object,), callable_type_dict)
68+
69+
3770
CLASS_INSTANCE = ExerciseClass()
3871
CLASS_INSTANCE_CALLABLE = ExerciseClassCallable()
72+
TYPE_CONSTRUCTOR_CLASS_INSTANCE = ExerciseTypeConstructor()
73+
TYPE_CONSTRUCTOR_CALLABLE_CLASS_INSTANCE = ExerciseTypeConstructorCallable()
3974

40-
exercise_lambda = lambda: None
75+
exercise_lambda = lambda: None # noqa: E731
4176
exercise_partial = functools.partial(exercise_function)

0 commit comments

Comments
 (0)