|
| 1 | +#!/usr/bin/env python3 |
| 2 | +# SPDX-License-Identifier: Apache-2.0 |
| 3 | +# SPDX-FileCopyrightText: Copyright the Vortex contributors |
| 4 | + |
| 5 | +from __future__ import annotations |
| 6 | + |
| 7 | +from pathlib import Path |
| 8 | +import subprocess |
| 9 | +import sys |
| 10 | +import tempfile |
| 11 | +import unittest |
| 12 | + |
| 13 | + |
| 14 | +SCRIPT = Path(__file__).with_name("version_pair.py") |
| 15 | +FIXTURES = Path(__file__).parent / "fixtures" / "version_pair" |
| 16 | + |
| 17 | + |
| 18 | +class VersionPairCliTest(unittest.TestCase): |
| 19 | + def test_tag_and_mismatched_datafusion_versions(self) -> None: |
| 20 | + result = self.run_script("tag", "--lockfile", fixture("current.lock")) |
| 21 | + |
| 22 | + self.assertEqual(result.returncode, 0, result.stderr) |
| 23 | + self.assertEqual(result.stdout.strip(), "0.69.0-53.1.0") |
| 24 | + |
| 25 | + result = self.run_script("tag", "--lockfile", fixture("mismatched.lock")) |
| 26 | + |
| 27 | + self.assertNotEqual(result.returncode, 0) |
| 28 | + self.assertIn("resolves datafusion 53.1.0", result.stderr) |
| 29 | + self.assertIn("datafusion-cli 54.0.0", result.stderr) |
| 30 | + |
| 31 | + def test_changed_lockfiles(self) -> None: |
| 32 | + result = self.run_script( |
| 33 | + "changed", |
| 34 | + "--old", |
| 35 | + fixture("current.lock"), |
| 36 | + "--new", |
| 37 | + fixture("current.lock"), |
| 38 | + ) |
| 39 | + |
| 40 | + self.assertEqual(result.returncode, 0, result.stderr) |
| 41 | + self.assertIn("no release needed", result.stdout) |
| 42 | + |
| 43 | + with tempfile.NamedTemporaryFile() as output: |
| 44 | + result = self.run_script( |
| 45 | + "changed", |
| 46 | + "--old", |
| 47 | + fixture("current.lock"), |
| 48 | + "--new", |
| 49 | + fixture("both-changed.lock"), |
| 50 | + "--github-output", |
| 51 | + output.name, |
| 52 | + ) |
| 53 | + output.seek(0) |
| 54 | + github_output = output.read().decode("utf-8") |
| 55 | + |
| 56 | + self.assertEqual(result.returncode, 0, result.stderr) |
| 57 | + self.assertIn("release needed", result.stdout) |
| 58 | + self.assertIn("release_needed=true\n", github_output) |
| 59 | + self.assertIn("old_tag=0.69.0-53.1.0\n", github_output) |
| 60 | + self.assertIn("new_tag=0.70.0-54.0.0\n", github_output) |
| 61 | + self.assertIn("changes=vortex-datafusion,datafusion/datafusion-cli\n", github_output) |
| 62 | + |
| 63 | + def run_script(self, *args: str) -> subprocess.CompletedProcess[str]: |
| 64 | + return subprocess.run( |
| 65 | + [sys.executable, str(SCRIPT), *args], |
| 66 | + check=False, |
| 67 | + text=True, |
| 68 | + capture_output=True, |
| 69 | + ) |
| 70 | + |
| 71 | + |
| 72 | +def fixture(name: str) -> str: |
| 73 | + return str(FIXTURES / name) |
| 74 | + |
| 75 | + |
| 76 | +if __name__ == "__main__": |
| 77 | + unittest.main() |
0 commit comments