コード例 #1
0
def test_do_not_dump_empty_stub(tmp_path: Path):
    root = tmp_path / 'project'
    root.mkdir()
    (root / '__init__.py').touch()
    source_path = (root / 'example.py')
    source_path.write_text('def func(): return 1')
    stub_path = generate_stub(path=source_path)
    assert not stub_path.exists()
    assert stub_path.name == 'example.json'
    assert stub_path.parent == root
コード例 #2
0
def test_generate_stub(tmp_path: Path):
    root = tmp_path / 'project'
    root.mkdir()
    (root / '__init__.py').touch()
    source_path = (root / 'example.py')
    source_path.write_text('def func(): 1/0')
    stub_path = generate_stub(path=source_path)
    content = json.loads(stub_path.read_text())
    assert stub_path.name == 'example.json'
    assert stub_path.parent == root
    assert content == {'func': {'raises': ['ZeroDivisionError']}}
コード例 #3
0
ファイル: test_stub.py プロジェクト: toonarmycaptain/deal
def test_generate_stub_markers(tmp_path: Path):
    root = tmp_path / 'project'
    root.mkdir()
    (root / '__init__.py').touch()
    source_path = (root / 'example.py')
    source_path.write_text('def func(): print("oh hi mark")')
    stub_path = generate_stub(path=source_path)
    content = json.loads(stub_path.read_text())
    assert stub_path.name == 'example.json'
    assert stub_path.parent == root
    assert content == {'func': {'has': ['stdout']}}
コード例 #4
0
def test_generate_stub_bad_ext(tmp_path: Path):
    path = tmp_path / 'example.com'
    with pytest.raises(ValueError, match='invalid.* file extension.*'):
        generate_stub(path=path)