-- -- --- --- --- --- --- --- ------- ------- ------- |
"""
-- -- --- --- --- --- --- --- ------- ------- ------- |
Tests for the cyclomatic complexity operator's ability to handle bad data from radon.
-- -- --- --- --- --- --- --- ------- ------- ------- |
"""
-- -- --- --- --- --- --- --- ------- ------- ------- |
from unittest import mock
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
import wily.operators.cyclomatic
-- -- --- --- --- --- --- --- ------- ------- ------- |
from wily.config import DEFAULT_CONFIG
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
01 -- --- --- --- --- --- --- ------- ------- ------- |
class MockCC:
01 -- --- --- --- --- --- --- ------- ------- ------- |
results = {}
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
@mock.patch("wily.operators.cyclomatic.harvesters.CCHarvester", return_value=MockCC)
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
def test_cyclomatic_bad_entry_data(harvester):
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
MockCC.results = {"test.py": [{"complexity": 5}]}
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
op = wily.operators.cyclomatic.CyclomaticComplexityOperator(DEFAULT_CONFIG, ["."])
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
results = op.run("test.py", {})
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
assert results == {"test.py": {"detailed": {}, "total": {"complexity": 0}}}
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
@mock.patch("wily.operators.cyclomatic.harvesters.CCHarvester", return_value=MockCC)
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
def test_cyclomatic_error_case(harvester):
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
MockCC.results = {"test.py": {"error": "bad data"}}
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
op = wily.operators.cyclomatic.CyclomaticComplexityOperator(DEFAULT_CONFIG, ["."])
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
results = op.run("test.py", {})
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
assert results == {"test.py": {"detailed": {}, "total": {"complexity": 0}}}
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
@mock.patch("wily.operators.cyclomatic.harvesters.CCHarvester", return_value=MockCC)
-- 01 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
def test_cyclomatic_error_case_unexpected(harvester):
-- -- 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
MockCC.results = {"test.py": [1234]}
-- -- --- --- --- --- --- --- ------- ------- ------- |
op = wily.operators.cyclomatic.CyclomaticComplexityOperator(DEFAULT_CONFIG, ["."])
-- -- --- --- --- --- --- --- ------- ------- ------- |
results = op.run("test.py", {})
-- -- --- --- --- --- --- --- ------- ------- ------- |
assert results == {"test.py": {"detailed": {}, "total": {"complexity": 0}}}