1
0
mirror of https://github.com/badges/shields.git synced 2025-11-09 12:40:59 +03:00
Files
shields/services/python/python-version-from-toml.tester.js
jNullj e8b4467609 Add [PythonVersionFromToml] shield (#9516)
* Add PythonVersionFromToml

Added new shield per issue #9410
The shield display required python versions for packages based on pyproject.toml

* Add tests for PythonVersionFromToml

* Improve docs for tests regex

* Improve title and description

Rename and updated description to bring into focus that only PEP 621 complaint pyproject.toml files are supported.

Solves review https://github.com/badges/shields/pull/9516#discussion_r1310648023

* replace complex regex with @renovate/pep440

solves review https://github.com/badges/shields/pull/9516#discussion_r1310648881
2023-09-10 12:18:16 +00:00

28 lines
918 B
JavaScript

import Joi from 'joi'
import pep440 from '@renovate/pep440'
import { createServiceTester } from '../tester.js'
export const t = await createServiceTester()
const validatePep440 = (value, helpers) => {
if (!pep440.validRange(value)) {
return helpers.error('any.invalid')
}
return value
}
const isCommaSeparatedPythonVersions = Joi.string().custom(validatePep440)
t.create('python versions (valid)')
.get(
'/python/required-version-toml.json?tomlFilePath=https://raw.githubusercontent.com/numpy/numpy/main/pyproject.toml',
)
.expectBadge({ label: 'python', message: isCommaSeparatedPythonVersions })
t.create(
'python versions - valid toml with missing python-requires field (invalid)',
)
.get(
'/python/required-version-toml.json?tomlFilePath=https://raw.githubusercontent.com/django/django/main/pyproject.toml',
)
.expectBadge({ label: 'python', message: 'invalid response data' })