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
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']}}
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']}}
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)