Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve CLI, refactor and document stubgen #6256

Merged
merged 35 commits into from
Jan 30, 2019
Merged
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
f3ec824
Add source mode and fix semanal
ilevkivskyi Jan 20, 2019
478dc42
Start the big overhaul
ilevkivskyi Jan 20, 2019
c4d9e77
Move doc related stuff to a separate module
Jan 21, 2019
09726fb
Some more cleanup
Jan 21, 2019
e465bea
Complete the main rewriting
Jan 21, 2019
9b92d37
Some more refactoring (also to simplify testing)
Jan 22, 2019
b767e3f
Add some docs
Jan 23, 2019
e65d60a
Fix existing tests
Jan 23, 2019
4c2e0e9
Merge remote-tracking branch 'upstream/master' into unify-stubgen
Jan 23, 2019
b959d42
Copy semanal changes to new semanal
Jan 23, 2019
b41b494
Some progress with tests
Jan 24, 2019
f204858
Another idea for testing
Jan 24, 2019
8c71965
Even better testing; add first semanal test
Jan 24, 2019
4011d06
Fix lint and self-check
Jan 24, 2019
f3d935f
One more test
Jan 25, 2019
6fadc15
Remove irrelevamt TODOs, add few more tests
Jan 25, 2019
cc8e108
Merge remote-tracking branch 'upstream/master' into unify-stubgen
ilevkivskyi Jan 25, 2019
3cf24da
Re-organize tests, and add few more
ilevkivskyi Jan 25, 2019
000082e
Fix self-check
ilevkivskyi Jan 25, 2019
3782291
Finish sentence in module doctring
ilevkivskyi Jan 25, 2019
01872fd
Fix tempdirs in tests
ilevkivskyi Jan 25, 2019
ac2a1cf
Fix windows
ilevkivskyi Jan 25, 2019
38f424f
One more Windows fix
Jan 25, 2019
1f41f91
A temporary change to debug Windows: DO NOT MERGE
Jan 25, 2019
ac7317d
Try reordering clean-up
Jan 25, 2019
d51d4f8
Docstring and comment fixes
Jan 25, 2019
b4ac2b4
Include private aliases only with flag
Jan 25, 2019
0549d3e
Add type argument for bare Final
Jan 25, 2019
bb00dad
Address CR
Jan 28, 2019
5544c11
Add support for abstract classes; add typeshed to paths
Jan 29, 2019
b6e366a
Sully's rst fixes
Jan 29, 2019
ded5482
Never return None from abstract methods
Jan 29, 2019
ccceb30
Merge remote-tracking branch 'upstream/master' into unify-stubgen
Jan 29, 2019
be4e8eb
The rest of the merge
Jan 29, 2019
84c1926
Fix lint
Jan 29, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Some progress with tests
Ivan Levkivskyi committed Jan 24, 2019
commit b41b494370c2008a66c874bd551ee19c2c96799b
29 changes: 18 additions & 11 deletions mypy/test/teststubgen.py
Original file line number Diff line number Diff line change
@@ -18,6 +18,16 @@
infer_sig_from_docstring, infer_prop_type_from_docstring
)

MYPY = False
if MYPY:
from typing_extensions import Final

TEST_DIR = 'stubgen-test-path' # type: Final


class StubgenCmdLineSuite(Suite):
pass


class StubgenCliParseSuite(Suite):
def test_walk_packages(self) -> None:
@@ -137,35 +147,32 @@ def run_case(self, testcase: DataDrivenTestCase) -> None:
test_stubgen(testcase)


def parse_flags(program_text: str) -> Options:
def parse_flags(program_text: str, extra: List[str]) -> Options:
flags = re.search('# flags: (.*)$', program_text, flags=re.MULTILINE)
if flags:
flag_list = flags.group(1).split()
else:
flag_list = []
return parse_options(flag_list + ['dummy.py'])
return parse_options(flag_list + extra)


def test_stubgen(testcase: DataDrivenTestCase) -> None:
if 'stubgen-test-path' not in sys.path:
sys.path.insert(0, 'stubgen-test-path')
os.mkdir('stubgen-test-path')
if TEST_DIR not in sys.path:
sys.path.insert(0, TEST_DIR)
os.mkdir(TEST_DIR)
source = '\n'.join(testcase.input)
options = parse_flags(source)
handle = tempfile.NamedTemporaryFile(prefix='prog_', suffix='.py', dir='stubgen-test-path',
handle = tempfile.NamedTemporaryFile(prefix='prog_', suffix='.py', dir=TEST_DIR,
delete=False)
assert os.path.isabs(handle.name)
mod = os.path.basename(handle.name)[:-3]
options.files = []
options.modules = [mod]
options.search_path = ['stubgen-test-path']
options = parse_flags(source, ['--search-path', TEST_DIR, '-m', mod])
out_dir = 'out'
try:
handle.write(bytes(source, 'ascii'))
handle.close()
# Without this we may sometimes be unable to import the module below, as importlib
# caches os.listdir() results in Python 3.3+ (Guido explained this to me).
reset_importlib_cache('stubgen-test-path')
reset_importlib_cache(TEST_DIR)
try:
if not testcase.name.endswith('_import'):
options.no_import = True
11 changes: 11 additions & 0 deletions test-data/unit/stubgen.test
Original file line number Diff line number Diff line change
@@ -1232,3 +1232,14 @@ class F:

@t.coroutine
def g(): ...

[case testCrossModule_semanal]
[file a.py]
import b
class A: ...
B = b.B
[file b.py]
import a
class B: ...
A = a.A
[out]