Beispiel #1
0
 def test_alt_syntax(self):
     command_module = create_command_module_for_file(
         os.path.join("examples", "simple.py"))
     command_method = command_module.commands[
         "documented_two_parameter_alt_syntax"]
     output = command_method.help("examples.simple")
     self.assertNotIn("No documentation provided.", output)
Beispiel #2
0
 def test_simple_method(self):
     command_module = create_command_module_for_file(
         os.path.join("examples", "simple.py"))
     command_method = command_module.commands["typed_return"]
     output = command_method.usage("some_module")
     result = read_doc_opt(output)
     self.assertEqual(result, output)
Beispiel #3
0
    def test_methods_in_module_help(self):
        command_module = create_command_module_for_file(
            os.path.join("examples", "simple.py"))
        output = command_module.help()

        for method in command_module.commands.values():
            self.assertTrue(method.name in output)
Beispiel #4
0
 def test_no_method_doc(self):
     command_module = create_command_module_for_file(
         os.path.join("examples", "simple.py"))
     command_method = command_module.commands["one_documented_parameter"]
     output = command_method.help("examples.simple")
     print(output)
     self.assertIn("No documentation provided.", output)
     self.assertIn("An argument.", output)
Beispiel #5
0
from clippy.command_method import CommandMethod, create_command_method
from clippy.command_module import create_command_module_for_file
from clippy.common import parse_ast, function_docs_from_string

all_modules = sorted(
    map(lambda x: os.path.join("clippy", x), os.listdir("clippy")))

docs = list()

for filename in all_modules:
    if not os.path.isfile(filename) or "__" in filename:
        print(f"Skipping {filename}")
        continue

    print(f"Parsing {filename}...")
    module = create_command_module_for_file(filename)
    docs.append(module.markdown())

    module_name = filename[:-3].replace(os.path.sep, ".")
    imported_module = importlib.import_module(module_name)
    parsed = parse_ast(filename)

    for item in parsed.body:
        if isinstance(item, FunctionDef):
            meth = create_command_method(item, imported_module)
            docs.append(meth.markdown())
        elif isinstance(item, ClassDef):
            docs.append(f"## {item.name}\n\n{ast.get_docstring(item)}\n")
            props = sorted(filter(lambda x: isinstance(x, FunctionDef),
                                  item.body),
                           key=lambda x: x.name)
Beispiel #6
0
 def test_simple_module(self):
     command_module = create_command_module_for_file(
         os.path.join("examples", "simple.py"))
     output = command_module.usage()
     result = read_doc_opt(output)
     self.assertEqual(result, output)
Beispiel #7
0
    def test_create_command_file_invalid(self, any_obj):
        with self.assertRaises(TypeError) as err:
            _ = create_command_module_for_file(any_obj)

        self.assertTrue("filename" in str(err.exception))
Beispiel #8
0
    def test_create_command_module_for_file(self, non):
        with self.assertRaises(ValueError) as err:
            _ = create_command_module_for_file(non)

        self.assertTrue("filename" in str(err.exception))
Beispiel #9
0
    def test_create_folder(self):
        with self.assertRaises(ValueError) as err:
            _ = create_command_module_for_file("tests")

        self.assertTrue("is not file" in str(err.exception))
Beispiel #10
0
    def test_create_no_file(self, file):
        with self.assertRaises(FileNotFoundError) as err:
            _ = create_command_module_for_file(file)

        self.assertTrue("File not found" in str(err.exception))