mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-06 13:06:53 +00:00
42 lines
841 B
Python
42 lines
841 B
Python
# -*- coding: utf-8 -*-
|
|
import unittest
|
|
import sys
|
|
try:
|
|
from StringIO import StringIO
|
|
except ImportError:
|
|
from io import StringIO # NOQA
|
|
|
|
from flake8.mccabe import get_code_complexity
|
|
|
|
|
|
_GLOBAL = """\
|
|
|
|
for i in range(10):
|
|
pass
|
|
|
|
def a():
|
|
def b():
|
|
def c():
|
|
pass
|
|
c()
|
|
b()
|
|
|
|
"""
|
|
|
|
|
|
class McCabeTest(unittest.TestCase):
|
|
|
|
def setUp(self):
|
|
self.old = sys.stdout
|
|
self.out = sys.stdout = StringIO()
|
|
|
|
def tearDown(self):
|
|
sys.sdtout = self.old
|
|
|
|
def test_sample(self):
|
|
self.assertEqual(get_code_complexity(_GLOBAL, 1), 2)
|
|
self.out.seek(0)
|
|
res = self.out.read().strip().split('\n')
|
|
wanted = ["stdin:5:1: C901 'a' is too complex (4)",
|
|
"stdin:2:1: C901 'Loop 2' is too complex (2)"]
|
|
self.assertEqual(res, wanted)
|