summaryrefslogtreecommitdiff
path: root/tests/test_context.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2018-09-28 20:06:48 -0400
committerNed Batchelder <ned@nedbatchelder.com>2018-09-28 20:06:48 -0400
commitf9cfc98ebf12f3f04479bee9fab9358fdf9d4559 (patch)
treedcb3a040d9965e98203e750476b554b7e4914c6b /tests/test_context.py
parent1cf8962099a98829761fcf24f38e9acf77802f9c (diff)
downloadpython-coveragepy-git-f9cfc98ebf12f3f04479bee9fab9358fdf9d4559.tar.gz
Get qualified names for method contexts
Diffstat (limited to 'tests/test_context.py')
-rw-r--r--tests/test_context.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/test_context.py b/tests/test_context.py
index 4339d336..eeca81cd 100644
--- a/tests/test_context.py
+++ b/tests/test_context.py
@@ -3,10 +3,12 @@
"""Tests for context support."""
+import inspect
import os.path
import coverage
from coverage import env
+from coverage.context import qualname_from_frame
from coverage.data import CoverageData
from coverage.misc import CoverageException
@@ -182,3 +184,44 @@ class DynamicContextWithPythonTracerTest(CoverageTest):
msg = r"Can't support dynamic contexts with PyTracer"
with self.assertRaisesRegex(CoverageException, msg):
cov.start()
+
+
+def get_qualname():
+ """Helper to return qualname_from_frame for the caller."""
+ caller_frame = inspect.stack()[1][0]
+ return qualname_from_frame(caller_frame)
+
+
+class Parent(object): # pylint: disable=missing-docstring
+ def meth(self):
+ return get_qualname()
+
+class Child(Parent): # pylint: disable=missing-docstring
+ pass
+
+class SomethingElse(object): # pylint: disable=missing-docstring
+ pass
+
+class MultiChild(SomethingElse, Child): # pylint: disable=missing-docstring
+ pass
+
+def fake_out(self): # pylint: disable=missing-docstring
+ return get_qualname()
+
+
+class QualnameTest(CoverageTest):
+ """Tests of qualname_from_frame."""
+
+ run_in_temp_dir = False
+
+ def test_method(self):
+ self.assertEqual(Parent().meth(), "Parent.meth")
+
+ def test_inherited_method(self):
+ self.assertEqual(Child().meth(), "Parent.meth")
+
+ def test_mi_inherited_method(self):
+ self.assertEqual(MultiChild().meth(), "Parent.meth")
+
+ def test_fake_out(self):
+ self.assertEqual(fake_out(0), "fake_out")