1
0
mirror of https://github.com/badges/shields.git synced 2025-04-26 09:48:52 +03:00
shields/services/pypi/pypi-python-versions.tester.js
Paul Melnikow e8d49f2504
Add dependency badge for Pipenv applications [GithubPipenv] (#4096)
I recently published https://github.com/metabolize/rq-dashboard-on-heroku and want to add badges to show the locked version of Python and rq-dashboard, the main dependency it’s wrapping.

This is along the lines of #2259, which was for package.json-based applications, and also included some discussion of a Python application that used `requirements.txt`. It’s useful for showing the pinned version of any dependency in a Python application that uses a lockfile.

In the future, as an alternative to reading Pipfile.lock, I could see expanding this to read Pipfile. However for my purposes I prefer to show the locked dependency, since that’s the version that a user of my package would actually get if they ran it on Heroku.
2019-10-02 15:24:14 -04:00

39 lines
1.1 KiB
JavaScript

'use strict'
const Joi = require('@hapi/joi')
const t = (module.exports = require('../tester').createServiceTester())
const isPipeSeparatedPythonVersions = Joi.string().regex(
/^([0-9]+\.[0-9]+(?: \| )?)+$/
)
t.create('python versions (valid, package version in request)')
.get('/requests/2.18.4.json')
.expectBadge({
label: 'python',
message: isPipeSeparatedPythonVersions,
})
t.create('python versions (valid, no package version specified)')
.get('/requests.json')
.expectBadge({
label: 'python',
message: isPipeSeparatedPythonVersions,
})
t.create('python versions ("Only" and others)')
.get('/uvloop/0.12.1.json')
.expectBadge({ label: 'python', message: '3.5 | 3.6 | 3.7' })
t.create('python versions ("Only" only)')
.get('/hashpipe/0.9.1.json')
.expectBadge({ label: 'python', message: '3' })
t.create('python versions (no versions specified)')
.get('/pyshp/1.2.12.json')
.expectBadge({ label: 'python', message: 'missing' })
t.create('python versions (invalid)')
.get('/not-a-package.json')
.expectBadge({ label: 'python', message: 'package or version not found' })