Skip to content

Commit

Permalink
Migrate rye_devtools unittest to pytest (astral-sh#892)
Browse files Browse the repository at this point in the history
  • Loading branch information
j178 authored Mar 15, 2024
1 parent 946c60c commit c98c681
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 38 deletions.
31 changes: 1 addition & 30 deletions rye-devtools/src/rye_devtools/find_downloads.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""This script is used to generate rye/src/downloads.inc.
"""This script is used to generate rye/src/sources/generated/python_downloads.inc.
It finds the latest Python releases, sorts them by
various factors (arch, platform, flavor) and generates download
Expand All @@ -11,7 +11,6 @@
import os
import re
import sys
import unittest
from dataclasses import dataclass
from enum import StrEnum
from urllib.parse import unquote
Expand Down Expand Up @@ -435,31 +434,3 @@ def main():

if __name__ == "__main__":
main()


class Tests(unittest.TestCase):
def test_parse_triplets(self):
expected = {
"aarch64-apple-darwin-lto": PlatformTriple("aarch64", "macos", None, "lto"),
"aarch64-unknown-linux-gnu-pgo+lto": PlatformTriple(
"aarch64", "linux", "gnu", "pgo+lto"
),
# "x86_64-unknown-linux-musl-debug": PlatformTriple(
# "x86_64", "linux", "musl", "debug"
# ),
"aarch64-unknown-linux-gnu-debug-full": PlatformTriple(
"aarch64", "linux", "gnu", "debug"
),
"x86_64-unknown-linux-gnu-debug": PlatformTriple(
"x86_64", "linux", "gnu", "debug"
),
"linux64": PlatformTriple("x86_64", "linux", "gnu", None),
"ppc64le-unknown-linux-gnu-noopt-full": None,
"x86_64_v3-unknown-linux-gnu-lto": None,
"x86_64-pc-windows-msvc-shared-pgo": PlatformTriple(
"x86_64", "windows", None, "shared-pgo"
),
}

for input, expected in expected.items():
self.assertEqual(CPythonFinder.parse_triple(input), expected, input)
4 changes: 2 additions & 2 deletions rye-devtools/src/rye_devtools/find_uv_downloads.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""This script is used to generate rye/src/generated/uv_downloads.inc.
"""This script is used to generate rye/src/sources/generated/uv_downloads.inc.
It finds the latest UV releases and generates rust code that can be included
into rye at build time.
Expand Down Expand Up @@ -91,7 +91,7 @@ def parse_triple(cls, url: str) -> PlatformTriple | None:
def render(downloads: list[UvDownload]):
print("// Generated by rye-devtools. DO NOT EDIT.")
print(
"// To regenerate, run `rye run uv-downloads > rye/src/generated/uv_downloads.inc` from the root of the repository."
"// To regenerate, run `rye run uv-downloads > rye/src/sources/generated/uv_downloads.inc` from the root of the repository."
)
print("use std::borrow::Cow;")
print("pub const UV_DOWNLOADS: &[UvDownload] = &[")
Expand Down
39 changes: 39 additions & 0 deletions rye-devtools/tests/test_basic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import pytest
from rye_devtools.find_downloads import CPythonFinder, PlatformTriple, batched


def test_batched():
assert list(batched("ABCDEFG", 3)) == [tuple("ABC"), tuple("DEF"), tuple("G")]


@pytest.mark.parametrize(
"input, expected",
[
("aarch64-apple-darwin-lto", PlatformTriple("aarch64", "macos", None, "lto")),
(
"aarch64-unknown-linux-gnu-pgo+lto",
PlatformTriple("aarch64", "linux", "gnu", "pgo+lto"),
),
# (
# "x86_64-unknown-linux-musl-debug",
# PlatformTriple("x86_64", "linux", "musl", "debug"),
# ),
(
"aarch64-unknown-linux-gnu-debug-full",
PlatformTriple("aarch64", "linux", "gnu", "debug"),
),
(
"x86_64-unknown-linux-gnu-debug",
PlatformTriple("x86_64", "linux", "gnu", "debug"),
),
("linux64", PlatformTriple("x86_64", "linux", "gnu", None)),
("ppc64le-unknown-linux-gnu-noopt-full", None),
("x86_64_v3-unknown-linux-gnu-lto", None),
(
"x86_64-pc-windows-msvc-shared-pgo",
PlatformTriple("x86_64", "windows", None, "shared-pgo"),
),
],
)
def test_parse_triplets(input, expected):
assert CPythonFinder.parse_triple(input) == expected
5 changes: 0 additions & 5 deletions rye-devtools/tests/test_batch.py

This file was deleted.

2 changes: 1 addition & 1 deletion rye/src/sources/generated/uv_downloads.inc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Generated by rye-devtools. DO NOT EDIT.
// To regenerate, run `rye run uv-downloads > rye/src/generated/uv_downloads.inc` from the root of the repository.
// To regenerate, run `rye run uv-downloads > rye/src/sources/generated/uv_downloads.inc` from the root of the repository.
use std::borrow::Cow;
pub const UV_DOWNLOADS: &[UvDownload] = &[
UvDownload {arch: Cow::Borrowed("aarch64"), os: Cow::Borrowed("macos"), major: 0, minor: 1, patch: 19, suffix: None, url: Cow::Borrowed("https://github.com/astral-sh/uv/releases/download/0.1.19/uv-aarch64-apple-darwin.tar.gz"), sha256: Cow::Borrowed("1ac97b4bedad801cd5860a83e92e092e9e04246fd7028393ba6b5c2f76fc1dff") },
Expand Down

0 comments on commit c98c681

Please sign in to comment.