Пример #1
0
    def test_find_functions_but_not_parseable(self):
        source_lines = [
            "def f1():",
            "    \"\"\"this is a docstring\"\"\"",
            "    this is not valie python code"
        ]

        with self.assertRaises(SyntaxError):
            extract.find_functions_in_source_having_docstring("\n".join(source_lines))
Пример #2
0
def extract_functions_from_ipynb_files(glob_path):
    result_str = ""
    paths = glob.glob(glob_path)
    for path in sorted(paths):
        ipynb_python_source_str = ipynb_to_python_source_str(path)
        result_str += "# === functions from {} ===\n\n".format(path)
        print "# === functions from {} ===\n\n".format(path)
        result_str += extract.extract_source_parts(ipynb_python_source_str, extract.find_functions_in_source_having_docstring(ipynb_python_source_str))
        result_str += "\n\n\n\n"
    return result_str
Пример #3
0
 def test_find_functions(self):
     source_lines = [
         "def f1():",
         "    \"\"\"this is a docstring\"\"\"",
         "    return 1",
         "",
         "def f2():",
         "    f1()",
         "    return 2",
         "",
         "f2()",
         "x = 2+3",
         "",
         "def f3():",
         "    \"\"\"this is a docstring\"\"\"",
         "    wont_work_but_should_parse()"
     ]
     result = extract.find_functions_in_source_having_docstring("\n".join(source_lines))
     self.assertEqual([
         {"name": "f1", "start":0, "end":3},
         {"name": "f3", "start":11, "end":14}
     ], result)