Is there any *testability-explorer* like tool for Python?
testability-explorer is a tool for measuring how hard to unit test java开发者_StackOverflow中文版 program. Is there any tool like this for Python?
Since Python is a dynamic language, "examining" the bytecode may reveal approximately nothing useful. A Python program can use exec
, execfile()
and __import__()
to introduce code "on-the-fly", defeating bytecode analysis.
Non-Mockable Total Recursive Cyclomatic Complexity. Assuming the bytecode is actually all of the code being executed, the Total Recursive Cyclomatic Complexity can be computed. The idea of non-mockable, however, doesn't apply to Python. Python has monkey-patching, making it very easy to mock almost anything in Python.
Assuming that there are exec
, execfile()
and __import__()
operations involved means that the only way to compute the actual total cyclomatic complexity is a combination of analysis plus execution.
Global Mutable State. There are module globals plus proper global
globals. The module globals are "free variables" and can be found by examination of the bytecode. The global
globals are all specifically labeled with global
and can be found in the source just as easily as the byte code.
Law of Demeter. This is interesting and could be found through an examination of the bytecode. However, the caveats above apply. It would only be useful assuming that there are no exec
, execfile()
or __import__()
operations.
Since most of the analysis in the testability explorer can't easily be applied to Python, it's not surprising that folks don't spend a lot of time trying to write a tool like that.
精彩评论