|
1 | 1 | import os.path |
2 | 2 | import platform |
| 3 | +import subprocess |
3 | 4 |
|
4 | 5 | import pytailwindcss |
5 | 6 | from pytailwindcss.installation import detect_target, format_target |
@@ -74,3 +75,43 @@ def test_format_target_uppercase_arch(): |
74 | 75 | assert format_target("linux", "X86_64") == "linux-x64" |
75 | 76 | assert format_target("linux", "AMD64") == "linux-x64" |
76 | 77 | assert format_target("linux", "AARCH64") == "linux-arm64" |
| 78 | + |
| 79 | + |
| 80 | +def test_cli_install_command_with_version(): |
| 81 | + """ |
| 82 | + It runs the 'tailwindcss_install' CLI command with TAILWINDCSS_VERSION set |
| 83 | + and verifies the correct version binary is installed. |
| 84 | + """ |
| 85 | + test_version = "v4.0.5" |
| 86 | + expected_bin_path = get_bin_path(test_version) |
| 87 | + |
| 88 | + with clean_dir(expected_bin_path): |
| 89 | + # Run the actual CLI command with environment variable |
| 90 | + env = os.environ.copy() |
| 91 | + env["TAILWINDCSS_VERSION"] = test_version |
| 92 | + result = subprocess.run(["tailwindcss_install"], env=env, capture_output=True, text=True) |
| 93 | + |
| 94 | + assert result.returncode == 0, f"CLI command failed with: {result.stderr}" |
| 95 | + assert os.path.isfile(expected_bin_path), f"Binary not installed at {expected_bin_path}" |
| 96 | + |
| 97 | + # Verify the correct version was installed |
| 98 | + version_check = pytailwindcss.run(version=test_version) |
| 99 | + assert "4.0.5" in version_check, f"Expected v4.0.5, got: {version_check}" |
| 100 | + |
| 101 | + |
| 102 | +def test_cli_install_command_without_version(): |
| 103 | + """ |
| 104 | + It runs the 'tailwindcss_install' CLI command without TAILWINDCSS_VERSION |
| 105 | + and verifies the 'latest' version binary is installed. |
| 106 | + """ |
| 107 | + expected_bin_path = get_bin_path("latest") |
| 108 | + |
| 109 | + with clean_dir(expected_bin_path): |
| 110 | + # Run the actual CLI command without TAILWINDCSS_VERSION |
| 111 | + env = os.environ.copy() |
| 112 | + # Remove TAILWINDCSS_VERSION if it exists |
| 113 | + env.pop("TAILWINDCSS_VERSION", None) |
| 114 | + result = subprocess.run(["tailwindcss_install"], env=env, capture_output=True, text=True) |
| 115 | + |
| 116 | + assert result.returncode == 0, f"CLI command failed with: {result.stderr}" |
| 117 | + assert os.path.isfile(expected_bin_path), f"Binary not installed at {expected_bin_path}" |
0 commit comments