예제 #1
0
def test_raw_visitor_functions(code, expected):
    code = test_raw.dedent(code)
    raw_visitor = RawVisitor.from_code(code)
    # only one function in these tests
    raw_result = raw_visitor.functions[0]
    # exclude the details about function name, lineno, etc. for now
    formated_result = Module(*raw_result[7:])
    assert formated_result == Module(*expected), f"\
        \n input code: {code}\
        \n result: {formated_result} \
        \n expected: {Module(*expected)}"

    expected_loc = (formated_result.blank + formated_result.sloc +
                    formated_result.single_comments + formated_result.multi)
    assert formated_result.loc == expected_loc
예제 #2
0
def test_raw_to_dict():
    assert tools.raw_to_dict(Module(103, 123, 98, 8, 19, 5, 3)) == {
        'loc': 103,
        'lloc': 123,
        'sloc': 98,
        'comments': 8,
        'multi': 19,
        'blank': 5,
        'single_comments': 3,
    }
예제 #3
0
 def test_raw_to_dict(self):
     self.assertEqual(
         tools.raw_to_dict(Module(103, 123, 98, 8, 19, 5)), {
             'loc': 103,
             'lloc': 123,
             'sloc': 98,
             'comments': 8,
             'multi': 19,
             'blank': 5
         })