Skip to content

Commit 7892258

Browse files
committed
Merge branch 'letientai299-type-hint'
2 parents b65179b + b843a3f commit 7892258

File tree

15 files changed

+345
-8
lines changed

15 files changed

+345
-8
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
*~
33
.DS_Store
44
tags
5+
vader.vim/

CHANGES.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
Version 0.0.9
2+
-------------
3+
Released on Nov 20th 2016
4+
5+
- Add Vader integration tes
6+
see https://github.com/heavenshell/vim-pydocstring/pull/14
7+
Thx @letientai299
8+
19
Version 0.0.8
210
-------------
311
Released on Sep 1th 2016

autoload/pydocstring.vim

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
" Insert Docstring.
22
" Author: Shinya Ohyanagi <sohyanagi@gmail.com>
3-
" Version: 0.0.8
3+
" Version: 0.0.9
44
" License: This file is placed in the public domain.
55
" WebPage: http://github.com/heavenshell/vim-pydocstriong/
66
" Description: Generate Python docstring to your Python script file.
@@ -11,11 +11,10 @@ let s:save_cpo = &cpo
1111
set cpo&vim
1212

1313
" Path to docstring template.
14-
if exists('g:pydocstring_templates_dir')
15-
let s:tmpldir = g:pydocstring_templates_dir
16-
else
17-
let s:tmpldir = expand('<sfile>:p:h:h') . '/template/pydocstring/'
14+
if !exists('g:pydocstring_templates_dir')
15+
let g:pydocstring_templates_dir = expand('<sfile>:p:h:h') . '/template/pydocstring/'
1816
endif
17+
1918
" Use comment.txt when cursor is not on def|class keyword.
2019
if !exists('g:pydocstring_enable_comment')
2120
let g:pydocstring_enable_comment = 1
@@ -31,7 +30,13 @@ let s:regexs = {
3130
\ }
3231

3332
function! s:readtmpl(type)
34-
let path = expand(s:tmpldir . a:type . '.txt')
33+
let tmpldir = g:pydocstring_templates_dir
34+
" Append the back slash if needed.
35+
if g:pydocstring_templates_dir !~ '/$'
36+
let tmpldir = tmpldir . '/'
37+
endif
38+
39+
let path = expand(tmpldir . a:type . '.txt')
3540
if !filereadable(path)
3641
throw 'Template ' . path . ' is not exists.'
3742
endif

doc/pydocstring.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
*pydocstring.txt* Generate Python docstring to your Python code.
22

3-
Version: 0.0.8
3+
Version: 0.0.9
44
Author: Shinya Ohynagi <sohyanagi@gmail.com>
55
Repository: http://github.com/heavenshell/vim-pydocstring/
66
License: BSD, see LICENSE for more details.

ftplugin/python/pydocstring.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
" File: pydocstring.vim
22
" Author: Shinya Ohyanagi <sohyanagi@gmail.com>
3-
" Version: 0.0.8
3+
" Version: 0.0.9
44
" WebPage: http://github.com/heavenshell/vim-pydocstriong/
55
" Description: Generate Python docstring to your Python script file.
66
" License: BSD, see LICENSE for more details.

test/basic.vader

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
# vim:set et sw=4 ts=4 tw=79:
2+
3+
# Test def keyword
4+
#-------------------------------------------------------------------------------
5+
Given python (def foo):
6+
def foo():
7+
pass
8+
9+
Execute:
10+
Pydocstring
11+
12+
Expect python:
13+
def foo():
14+
"""foo"""
15+
pass
16+
17+
Given python (def foo with 1 param):
18+
def foo(arg):
19+
pass
20+
21+
Execute:
22+
Pydocstring
23+
24+
Expect python:
25+
def foo(arg):
26+
"""foo
27+
28+
:param arg:
29+
"""
30+
pass
31+
32+
Given python (def foo with 2 params):
33+
def foo(arg1, arg2):
34+
pass
35+
36+
Execute:
37+
Pydocstring
38+
39+
Expect python:
40+
def foo(arg1, arg2):
41+
"""foo
42+
43+
:param arg1:
44+
:param arg2:
45+
"""
46+
pass
47+
48+
Given python (def foo with variadic params):
49+
def foo(*arg):
50+
pass
51+
52+
Execute:
53+
Pydocstring
54+
Expect python:
55+
def foo(*arg):
56+
"""foo
57+
58+
:param *arg:
59+
"""
60+
pass
61+
62+
63+
# Test class keyword
64+
#-------------------------------------------------------------------------------
65+
66+
67+
Given python (class Foo):
68+
class Foo(object):
69+
def foo(self):
70+
pass
71+
72+
def arg1(self, arg1):
73+
pass
74+
75+
Execute:
76+
Pydocstring
77+
78+
Expect python:
79+
class Foo(object):
80+
"""Foo"""
81+
def foo(self):
82+
pass
83+
84+
def arg1(self, arg1):
85+
pass
86+
87+
88+
Given python (class Foo):
89+
class Foo(object):
90+
def foo(self):
91+
pass
92+
93+
def arg1(self, arg1):
94+
pass
95+
96+
Do (Put cursor to def foo(self)):
97+
j
98+
99+
Then Execute (Execute Pydocstring on def foo(self)):
100+
Pydocstring
101+
102+
Expect python:
103+
class Foo(object):
104+
def foo(self):
105+
"""foo"""
106+
pass
107+
108+
def arg1(self, arg1):
109+
pass
110+
111+
112+
Given python (class Foo):
113+
class Foo(object):
114+
def foo(self):
115+
pass
116+
117+
def arg1(self, arg1):
118+
pass
119+
120+
Do (Put cursor to def arg1(self, arg1)):
121+
4j
122+
123+
Then Execute (Execute Pydocstring on def arg1(self, arg1)):
124+
Pydocstring
125+
126+
Expect python:
127+
class Foo(object):
128+
def foo(self):
129+
pass
130+
131+
def arg1(self, arg1):
132+
"""arg1
133+
134+
:param arg1:
135+
"""
136+
pass
137+
138+
# Test aync/await keyword
139+
#-------------------------------------------------------------------------------
140+
Given python (async def foo):
141+
async def foo():
142+
pass
143+
144+
Execute:
145+
Pydocstring
146+
147+
Expect python:
148+
async def foo():
149+
"""foo"""
150+
pass
151+

test/custom-template.vader

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# vim:set et sw=4 ts=4 tw=79:
2+
Execute (Setup template dir):
3+
Save g:pydocstring_templates_dir
4+
let g:pydocstring_templates_dir = './test-template/'
5+
6+
Given python (def foo):
7+
def foo():
8+
pass
9+
10+
Execute:
11+
Pydocstring
12+
13+
14+
Expect python:
15+
def foo():
16+
"""foo is """
17+
pass
18+
19+
20+
Given python (def foo with 1 params):
21+
def foo(arg1):
22+
pass
23+
24+
Execute:
25+
Pydocstring
26+
27+
Expect python:
28+
def foo(arg1):
29+
"""foo
30+
31+
arg1:
32+
arg1 is
33+
"""
34+
pass
35+
36+
37+
Given python (def foo with 2 params):
38+
def foo(arg1, arg2):
39+
pass
40+
41+
Execute:
42+
Pydocstring
43+
44+
Expect python:
45+
def foo(arg1, arg2):
46+
"""foo
47+
48+
arg1:
49+
arg1 is
50+
arg2:
51+
arg2 is
52+
"""
53+
pass
54+
55+
Execute (Clear pydocstring_templates_dir):
56+
Restore

test/minimal_vimrc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
" Minimal vimrc to run tests
2+
" --------------------------
3+
4+
set nocompatible
5+
set nu
6+
filetype off
7+
" Clear all rtp
8+
set rtp=$VIMRUNTIME
9+
10+
11+
" Add vader.vim to rtp
12+
set rtp+=./vader.vim
13+
14+
" Add pydocstring folder into rtp
15+
set rtp+=../
16+
filetype plugin indent on

test/nodemon.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"watch": "../",
3+
"ignore": [
4+
".git",
5+
"node_modules/**/node_modules",
6+
"vader.vim"
7+
],
8+
"verbose": true,
9+
"ext": "vader vim",
10+
"execMap": {
11+
"vader": "./run-single-test-file.sh"
12+
}
13+
}

test/readme.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
Test cases for vim-pydocstring
2+
==========================================
3+
4+
Prerequisite
5+
------------
6+
7+
- [vader.vim](https://github.com/junegunn/vader.vim)
8+
9+
Before running test, clone vader into this directory with:
10+
11+
```
12+
git clone https://github.com/junegunn/vader.vim
13+
```
14+
15+
16+
Run
17+
---
18+
19+
```
20+
./run.sh
21+
```
22+
23+
Note that the command need to be executed under `test` folder.
24+
25+
Use TDD during development (optional)
26+
-------------------------------------
27+
28+
You need [nodemon](https://github.com/remy/nodemon) to watch for files
29+
change and re-run the test cases in given file. Here I already provide
30+
nodemon configuration (see `nodemon.json`.)
31+
32+
Run (again, this need to be executed under `test` folder)
33+
34+
```
35+
nodemon <test-file>.vader
36+
```
37+
38+
Now, if you modify the `vader` or `vim` files in this project, nodemon will
39+
re-run all the test cases (via `run-single-test-file.sh`).
40+
41+
42+
### Know issue
43+
44+
Vim warns `Input is not from a terminal` when we run tests with
45+
`nodemon`. Neovim doesn't. That why in the scripts, we prefer to use
46+
`nvim` if it is found on path.

0 commit comments

Comments
 (0)