Exemplo n.º 1
0
 def test_find_argparse_throws_exception_if_not_found(self):
   with self.assertRaises(source_parser.ParserError):
     nodes = ast.parse(source_parser._openfile(self._module_with_noargparse))
     main_node = source_parser.find_main(nodes)
     self.assertEqual('main', main_node.name)
     try_nodes = source_parser.find_try_blocks(main_node)
     containing_block = source_parser.find_block_containing_argparse([main_node] + try_nodes)
Exemplo n.º 2
0
 def test_find_argparse_locates_assignment_stmnt_in_main(self):
   nodes = ast.parse(source_parser._openfile(self._module_with_argparse_in_main))
   main_node = source_parser.find_main(nodes)
   self.assertEqual('main', main_node.name)
   containing_block = source_parser.find_block_containing_argparse([main_node])
   self.assertTrue(containing_block is not None)
   self.assertEqual('main', containing_block.name)
Exemplo n.º 3
0
 def test_find_argparse_locates_assignment_stmnt_in_try_block(self):
   nodes = ast.parse(source_parser._openfile(self._module_with_arparse_in_try))
   main_node = source_parser.find_main(nodes)
   self.assertEqual('main', main_node.name)
   try_nodes = source_parser.find_try_blocks(main_node)
   self.assertTrue(len(try_nodes) > 0)
   containing_block = source_parser.find_block_containing_argparse([main_node] + try_nodes)
   self.assertEqual(ast.TryExcept, type(containing_block))
Exemplo n.º 4
0
 def test_find_argparse_throws_exception_if_not_found(self):
     with self.assertRaises(source_parser.ParserError):
         nodes = ast.parse(
             source_parser._openfile(self._module_with_noargparse))
         main_node = source_parser.find_main(nodes)
         self.assertEqual('main', main_node.name)
         try_nodes = source_parser.find_try_blocks(main_node)
         containing_block = source_parser.find_block_containing_argparse(
             [main_node] + try_nodes)
Exemplo n.º 5
0
 def test_find_argparse_locates_assignment_stmnt_in_main(self):
     nodes = ast.parse(
         source_parser._openfile(self._module_with_argparse_in_main))
     main_node = source_parser.find_main(nodes)
     self.assertEqual('main', main_node.name)
     containing_block = source_parser.find_block_containing_argparse(
         [main_node])
     self.assertTrue(containing_block is not None)
     self.assertEqual('main', containing_block.name)
Exemplo n.º 6
0
 def test_find_argparse_locates_assignment_stmnt_in_try_block(self):
     nodes = ast.parse(
         source_parser._openfile(self._module_with_arparse_in_try))
     main_node = source_parser.find_main(nodes)
     self.assertEqual('main', main_node.name)
     try_nodes = source_parser.find_try_blocks(main_node)
     self.assertTrue(len(try_nodes) > 0)
     containing_block = source_parser.find_block_containing_argparse(
         [main_node] + try_nodes)
     self.assertEqual(ast.TryExcept, type(containing_block))
Exemplo n.º 7
0
  def test_find_argparse_located_object_when_access_through_module_dot_notation(self):
    example_source = '''
def main():
  parser = argparse.ArgumentParser(description='Example Argparse Program', formatter_class=RawDescriptionHelpFormatter)
    '''
    nodes = ast.parse(example_source)
    main_node = source_parser.find_main(nodes)
    self.assertEqual('main', main_node.name)
    containing_block = source_parser.find_block_containing_argparse([main_node])
    self.assertTrue(containing_block is not None)
Exemplo n.º 8
0
    def test_find_argparse_located_object_when_imported_by_direct_name(self):
        example_source = '''
def main():
  parser = ArgumentParser(description='Example Argparse Program', formatter_class=RawDescriptionHelpFormatter)
    '''
        nodes = ast.parse(example_source)
        main_node = source_parser.find_main(nodes)
        self.assertEqual('main', main_node.name)
        containing_block = source_parser.find_block_containing_argparse(
            [main_node])
        self.assertTrue(containing_block is not None)