Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions eng/tools/azure-sdk-tools/azpysdk/apistub.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ def run(self, args: argparse.Namespace) -> int:
cmds.extend(["--out-path", out_token_path])
if cross_language_mapping_path:
cmds.extend(["--mapping-path", cross_language_mapping_path])
if getattr(args, "generate_md", False):
cmds.append("--skip-pylint")

logger.info("Running apistub {}.".format(cmds))

Expand Down
80 changes: 80 additions & 0 deletions eng/tools/azure-sdk-tools/tests/test_apistub.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,83 @@ def fake_pwsh(cmd, **kwargs):
assert cmds[out_idx + 1] == os.path.abspath(staging)
assert os.path.exists(os.path.join(staging, "api.md"))
assert os.path.exists(os.path.join(staging, "azure-core_python.json"))

@patch(
"azpysdk.apistub.REPO_ROOT", os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", "..", ".."))
)
@patch("azpysdk.apistub.PYTHON_VERSION_LIMIT", (99, 99))
@patch("azpysdk.apistub.get_cross_language_mapping_path", return_value=None)
@patch("azpysdk.apistub.get_package_wheel_path", return_value="/fake/pkg.whl")
@patch("azpysdk.apistub.create_package_and_install")
@patch("azpysdk.apistub.install_into_venv")
@patch("azpysdk.apistub.set_envvar_defaults")
def test_generate_md_adds_skip_pylint(self, _env, _install, _create, _get_whl, _get_mapping, tmp_path, monkeypatch):
"""When --md is passed (generate_md=True), --skip-pylint must be in the cmds."""
monkeypatch.chdir(os.getcwd())
stub = apistub()
staging = str(tmp_path / "staging")
os.makedirs(staging, exist_ok=True)
fake_parsed = MagicMock()
fake_parsed.folder = str(tmp_path)
fake_parsed.name = "azure-core"

captured_cmds = []

def fake_apistub_run(exe, cmds, **kwargs):
captured_cmds.append(cmds)
# Create the token JSON so the markdown generation branch can proceed
out_idx = cmds.index("--out-path")
out_dir = cmds[out_idx + 1]
os.makedirs(out_dir, exist_ok=True)
open(os.path.join(out_dir, "azure-core_python.json"), "w").close()

def fake_pwsh(cmd, **kwargs):
return MagicMock(returncode=0, stdout=None)

with patch.object(stub, "get_targeted_directories", return_value=[fake_parsed]), patch.object(
stub, "get_executable", return_value=(sys.executable, staging)
), patch.object(stub, "install_dev_reqs"), patch.object(stub, "pip_freeze"), patch.object(
stub, "run_venv_command", side_effect=fake_apistub_run
), patch(
"azpysdk.apistub.run", side_effect=fake_pwsh
):
stub.run(self._make_args(generate_md=True))

assert len(captured_cmds) == 1
assert "--skip-pylint" in captured_cmds[0]

@patch(
"azpysdk.apistub.REPO_ROOT", os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", "..", ".."))
)
@patch("azpysdk.apistub.PYTHON_VERSION_LIMIT", (99, 99))
@patch("azpysdk.apistub.get_cross_language_mapping_path", return_value=None)
@patch("azpysdk.apistub.get_package_wheel_path", return_value="/fake/pkg.whl")
@patch("azpysdk.apistub.create_package_and_install")
@patch("azpysdk.apistub.install_into_venv")
@patch("azpysdk.apistub.set_envvar_defaults")
def test_no_generate_md_omits_skip_pylint(
self, _env, _install, _create, _get_whl, _get_mapping, tmp_path, monkeypatch
):
"""When --md is not passed (generate_md=False), --skip-pylint must not be in the cmds."""
monkeypatch.chdir(os.getcwd())
stub = apistub()
staging = str(tmp_path / "staging")
os.makedirs(staging, exist_ok=True)
fake_parsed = MagicMock()
fake_parsed.folder = str(tmp_path)
fake_parsed.name = "azure-core"

captured_cmds = []

def fake_apistub_run(exe, cmds, **kwargs):
captured_cmds.append(cmds)

with patch.object(stub, "get_targeted_directories", return_value=[fake_parsed]), patch.object(
stub, "get_executable", return_value=(sys.executable, staging)
), patch.object(stub, "install_dev_reqs"), patch.object(stub, "pip_freeze"), patch.object(
stub, "run_venv_command", side_effect=fake_apistub_run
):
stub.run(self._make_args(generate_md=False))

assert len(captured_cmds) == 1
assert "--skip-pylint" not in captured_cmds[0]
Loading