|
3 | 3 | import shutil |
4 | 4 | import subprocess |
5 | 5 | from pathlib import Path |
6 | | -from unittest.mock import patch |
| 6 | +from unittest.mock import patch, Mock |
7 | 7 | from textwrap import dedent |
8 | 8 |
|
9 | 9 | import pytest |
@@ -406,10 +406,13 @@ def test_proxy_to_wrangler_unknown_command(mock_proxy_to_wrangler): |
406 | 406 | ) |
407 | 407 |
|
408 | 408 |
|
| 409 | +@patch("pywrangler.sync.check_wrangler_version") |
409 | 410 | @patch("pywrangler.cli._proxy_to_wrangler") |
410 | 411 | @patch("pywrangler.cli.sync_command") |
411 | 412 | @patch("sys.argv", ["pywrangler", "dev", "--local"]) |
412 | | -def test_proxy_auto_sync_commands(mock_sync_command, mock_proxy_to_wrangler): |
| 413 | +def test_proxy_auto_sync_commands( |
| 414 | + mock_sync_command, mock_proxy_to_wrangler, mock_check_wrangler_version |
| 415 | +): |
413 | 416 | """Test that dev, publish, and deploy commands automatically run sync first.""" |
414 | 417 | runner = CliRunner() |
415 | 418 |
|
@@ -530,3 +533,42 @@ def test_sync_recreates_venv_on_python_version_mismatch(clean_test_dir): |
530 | 533 | assert "3.13" in version_result.stdout, ( |
531 | 534 | f"Python version is not 3.13: {version_result.stdout}" |
532 | 535 | ) |
| 536 | + |
| 537 | + |
| 538 | +# Wrangler version check tests |
| 539 | +@patch("pywrangler.sync.run_command") |
| 540 | +def test_check_wrangler_version_sufficient(mock_run_command): |
| 541 | + """Test that check_wrangler_version passes with sufficient version.""" |
| 542 | + from pywrangler.sync import check_wrangler_version |
| 543 | + |
| 544 | + # Mock successful wrangler version output |
| 545 | + mock_result = Mock() |
| 546 | + mock_result.returncode = 0 |
| 547 | + mock_result.stdout = "wrangler 4.42.1" |
| 548 | + mock_run_command.return_value = mock_result |
| 549 | + |
| 550 | + # Should not raise an exception |
| 551 | + check_wrangler_version() |
| 552 | + |
| 553 | + # Verify the command was called correctly |
| 554 | + mock_run_command.assert_called_once_with( |
| 555 | + ["npx", "--yes", "wrangler", "--version"], capture_output=True, check=False |
| 556 | + ) |
| 557 | + |
| 558 | + |
| 559 | +@patch("pywrangler.sync.run_command") |
| 560 | +def test_check_wrangler_version_insufficient(mock_run_command): |
| 561 | + """Test that check_wrangler_version fails with insufficient version.""" |
| 562 | + from pywrangler.sync import check_wrangler_version |
| 563 | + |
| 564 | + # Mock wrangler version output with old version |
| 565 | + mock_result = Mock() |
| 566 | + mock_result.returncode = 0 |
| 567 | + mock_result.stdout = "⛅️ wrangler 4.40.0" |
| 568 | + mock_run_command.return_value = mock_result |
| 569 | + |
| 570 | + # Should raise SystemExit |
| 571 | + import click |
| 572 | + |
| 573 | + with pytest.raises(click.exceptions.Exit): |
| 574 | + check_wrangler_version() |
0 commit comments