def test_dont_count_block_comments_spanning_two_lines():
    code = """int i = 0;
              /* a comment
              that spans two lines */
              int j = 1;"""
    line_count = count(code)
    assert(line_count == 2)
def test_dont_count_block_comments_spanning_two_lines():
    code = """int i = 0;
              /* a comment
              that spans two lines */
              int j = 1;"""
    line_count = count(code)
    assert (line_count == 2)
示例#3
0
def run_single_file(filename):
    try:
        with open(filename, 'r') as f:
            contents = f.read()
            functions = calculate_complexity(contents)
            globals_vars = find_globals(contents)
            loc = count(contents)
            # Find the maximum complexity (scc) of all functions.
            max_scc = find_max_complexity(functions)
            # Calculate the spaghetti factor.
            ksf = max_scc + (5 * len(globals_vars)) + (loc // 20)
            return {
                'filename': filename,
                'functions': functions,
                'max_scc': max_scc,
                'globals_vars': globals_vars,
                'loc': loc,
                'ksf': ksf
            }
    except:
        # There was an error parsing this file.
        return ParsingError(filename, traceback.format_exc())
def test_multiple_lines():
    code = """int i = 0;
              int j = 1;"""
    line_count = count(code)
    assert(line_count == 2)
def test_dont_count_single_line_block_comments():
    code = """int i = 0;
              /* a comment */
              int j = 1;"""
    line_count = count(code)
    assert(line_count == 2)
def test_count_lines_with_trailing_comments():
    code = """int i = 0;
              bool x = true; // a comment
              int j = 1;"""
    line_count = count(code)
    assert(line_count == 3)
def test_single_line():
    code = "int i = 0;"
    line_count = count(code)
    assert(line_count == 1)
def test_dont_count_comment_lines():
    code = """int i = 0;
              // a comment
              int j = 1;"""
    line_count = count(code)
    assert(line_count == 2)
def test_dont_count_blank_lines():
    code = """int i = 0;
    
              int j = 1;"""
    line_count = count(code)
    assert(line_count == 2)
示例#10
0
def test_multiple_lines():
    code = """int i = 0;
              int j = 1;"""
    line_count = count(code)
    assert (line_count == 2)
示例#11
0
def test_dont_count_single_line_block_comments():
    code = """int i = 0;
              /* a comment */
              int j = 1;"""
    line_count = count(code)
    assert (line_count == 2)
示例#12
0
def test_count_lines_with_trailing_comments():
    code = """int i = 0;
              bool x = true; // a comment
              int j = 1;"""
    line_count = count(code)
    assert (line_count == 3)
示例#13
0
def test_single_line():
    code = "int i = 0;"
    line_count = count(code)
    assert (line_count == 1)
示例#14
0
def test_dont_count_comment_lines():
    code = """int i = 0;
              // a comment
              int j = 1;"""
    line_count = count(code)
    assert (line_count == 2)
示例#15
0
def test_dont_count_blank_lines():
    code = """int i = 0;
    
              int j = 1;"""
    line_count = count(code)
    assert (line_count == 2)