Skip to content

Instantly share code, notes, and snippets.

@bollwyvl
Created June 13, 2024 22:38
Show Gist options
  • Save bollwyvl/8c1c5792727c72f4d36bc41e85e6650f to your computer and use it in GitHub Desktop.
Save bollwyvl/8c1c5792727c72f4d36bc41e85e6650f to your computer and use it in GitHub Desktop.
import os
import pytest
from conda_forge_tick.url_transforms import gen_transformed_urls
TRANFORM_URLS = {
# test_url_transform_jinja
"""{{version}}""": r"""
v{{ version }}
{{ version }}
{{version}}
""",
"""<{version}}""": r"""
v{{ version }}
{{ version }}
<{version}}
""",
"""<<{version}}""": r"""
v{{ version }}
{{ version }}
<<{version}}
""",
# test_url_transform_jinja_mixed
"""{{version}}/{{name }}""": r"""
v{{ version }}/{{ name }}
v{{ version }}/{{name }}
{{ version }}/{{ name }}
{{ version }}/{{name }}
{{version}}/{{name }}
{{version}}/{{ name }}
""",
"""{{version}}/<{name}}""": r"""
v{{ version }}/{{ name }}
v{{ version }}/<{name}}
{{ version }}/{{ name }}
{{ version }}/<{name}}
{{version}}/<{name}}
{{version}}/{{ name }}
""",
# test_url_transform_version
"""{{ version }}""": r"""
v{{ version }}
{{ version }}
""",
"""blah.tar.gz""": r"""
blah.tar.gz
blah.tgz
blah.tar
blah.tar.bz2
blah.zip
blah.tar.xz
""",
# test_url_transform_pypi
"""https://pypi.io/{{ name }}/{{ name }}-barf""": r"""
https://files.pythonhosted.org/{{ name }}/{{ name }}-barf
https://files.pythonhosted.org/{{ name }}/{{ name.replace('-', '_') }}-barf
https://files.pythonhosted.org/{{ name }}/{{ name.replace('_', '-') }}-barf
https://pypi.io/{{ name }}/{{ name }}-barf
https://pypi.io/{{ name }}/{{ name.replace('-', '_') }}-barf
https://pypi.io/{{ name }}/{{ name.replace('_', '-') }}-barf
""",
"""https://pypi.io/{{ name }}/{{ name.replace('_','-') }}-barf""": r"""
https://files.pythonhosted.org/{{ name }}/{{ name }}-barf
https://files.pythonhosted.org/{{ name }}/{{ name.replace('_','-') }}-barf
https://pypi.io/{{ name }}/{{ name }}-barf
https://pypi.io/{{ name }}/{{ name.replace('_','-') }}-barf
""",
"""https://pypi.io/{{ name }}/{{ name|replace('_','-') }}-barf""": r"""
https://files.pythonhosted.org/{{ name }}/{{ name }}-barf
https://files.pythonhosted.org/{{ name }}/{{ name|replace('_','-') }}-barf
https://pypi.io/{{ name }}/{{ name }}-barf
https://pypi.io/{{ name }}/{{ name|replace('_','-') }}-barf
""",
"""https://pypi.io/{{ name }}/{{ name.replace("_", "-") }}-barf""": r"""
https://files.pythonhosted.org/{{ name }}/{{ name }}-barf
https://files.pythonhosted.org/{{ name }}/{{ name.replace("_", "-") }}-barf
https://pypi.io/{{ name }}/{{ name }}-barf
https://pypi.io/{{ name }}/{{ name.replace("_", "-") }}-barf
""",
# test_url_transform_github
"""
https://github.com/releases/download/v{{ version }}/{{ name }}/{{ name }}-{{ version }}
""": r"""
https://github.com/releases/download/v{{ version }}/{{ name }}/{{ name }}-{{ version }}
https://github.com/releases/download/{{ version }}/{{ name }}/{{ name }}-{{ version }}
https://github.com/archive/{{ name }}/v{{ version }}
https://github.com/archive/{{ name }}/{{ version }}
""",
# test_url_transform_complicated
"blah-{{ version }}.tar.gz": r"""
blah-{{ version }}.tar.gz
blah-{{ version }}.tgz
blah-{{ version }}.tar
blah-{{ version }}.tar.bz2
blah-{{ version }}.zip
blah-{{ version }}.tar.xz
blah-v{{ version }}.tar.gz
blah-v{{ version }}.tgz
blah-v{{ version }}.tar
blah-v{{ version }}.tar.bz2
blah-v{{ version }}.zip
blah-v{{ version }}.tar.xz
""",
# test_url_transform_complicated_pypi
"""https://pypi.io/{{ name }}/{{ name.replace('_', '-') }}-{{ version }}.tgz""": r"""
https://files.pythonhosted.org/{{ name }}/{{ name.replace('_', '-') }}-{{ version }}.tgz
https://files.pythonhosted.org/{{ name }}/{{ name.replace('_', '-') }}-{{ version }}.tar.gz
https://files.pythonhosted.org/{{ name }}/{{ name.replace('_', '-') }}-{{ version }}.zip
https://files.pythonhosted.org/{{ name }}/{{ name.replace('_', '-') }}-{{ version }}.tar
https://files.pythonhosted.org/{{ name }}/{{ name.replace('_', '-') }}-{{ version }}.tar.bz2
https://files.pythonhosted.org/{{ name }}/{{ name.replace('_', '-') }}-{{ version }}.tar.xz
https://files.pythonhosted.org/{{ name }}/{{ name.replace('_', '-') }}-v{{ version }}.tgz
https://files.pythonhosted.org/{{ name }}/{{ name.replace('_', '-') }}-v{{ version }}.tar.gz
https://files.pythonhosted.org/{{ name }}/{{ name.replace('_', '-') }}-v{{ version }}.zip
https://files.pythonhosted.org/{{ name }}/{{ name.replace('_', '-') }}-v{{ version }}.tar
https://files.pythonhosted.org/{{ name }}/{{ name.replace('_', '-') }}-v{{ version }}.tar.bz2
https://files.pythonhosted.org/{{ name }}/{{ name.replace('_', '-') }}-v{{ version }}.tar.xz
https://files.pythonhosted.org/{{ name }}/{{ name }}-{{ version }}.tgz
https://files.pythonhosted.org/{{ name }}/{{ name }}-{{ version }}.tar.gz
https://files.pythonhosted.org/{{ name }}/{{ name }}-{{ version }}.zip
https://files.pythonhosted.org/{{ name }}/{{ name }}-{{ version }}.tar
https://files.pythonhosted.org/{{ name }}/{{ name }}-{{ version }}.tar.bz2
https://files.pythonhosted.org/{{ name }}/{{ name }}-{{ version }}.tar.xz
https://files.pythonhosted.org/{{ name }}/{{ name }}-v{{ version }}.tgz
https://files.pythonhosted.org/{{ name }}/{{ name }}-v{{ version }}.tar.gz
https://files.pythonhosted.org/{{ name }}/{{ name }}-v{{ version }}.zip
https://files.pythonhosted.org/{{ name }}/{{ name }}-v{{ version }}.tar
https://files.pythonhosted.org/{{ name }}/{{ name }}-v{{ version }}.tar.bz2
https://files.pythonhosted.org/{{ name }}/{{ name }}-v{{ version }}.tar.xz
https://pypi.io/{{ name }}/{{ name.replace('_', '-') }}-{{ version }}.tgz
https://pypi.io/{{ name }}/{{ name.replace('_', '-') }}-{{ version }}.tar.gz
https://pypi.io/{{ name }}/{{ name.replace('_', '-') }}-{{ version }}.zip
https://pypi.io/{{ name }}/{{ name.replace('_', '-') }}-{{ version }}.tar
https://pypi.io/{{ name }}/{{ name.replace('_', '-') }}-{{ version }}.tar.bz2
https://pypi.io/{{ name }}/{{ name.replace('_', '-') }}-{{ version }}.tar.xz
https://pypi.io/{{ name }}/{{ name.replace('_', '-') }}-v{{ version }}.tgz
https://pypi.io/{{ name }}/{{ name.replace('_', '-') }}-v{{ version }}.tar.gz
https://pypi.io/{{ name }}/{{ name.replace('_', '-') }}-v{{ version }}.zip
https://pypi.io/{{ name }}/{{ name.replace('_', '-') }}-v{{ version }}.tar
https://pypi.io/{{ name }}/{{ name.replace('_', '-') }}-v{{ version }}.tar.bz2
https://pypi.io/{{ name }}/{{ name.replace('_', '-') }}-v{{ version }}.tar.xz
https://pypi.io/{{ name }}/{{ name }}-{{ version }}.tgz
https://pypi.io/{{ name }}/{{ name }}-{{ version }}.tar.gz
https://pypi.io/{{ name }}/{{ name }}-{{ version }}.zip
https://pypi.io/{{ name }}/{{ name }}-{{ version }}.tar
https://pypi.io/{{ name }}/{{ name }}-{{ version }}.tar.bz2
https://pypi.io/{{ name }}/{{ name }}-{{ version }}.tar.xz
https://pypi.io/{{ name }}/{{ name }}-v{{ version }}.tgz
https://pypi.io/{{ name }}/{{ name }}-v{{ version }}.tar.gz
https://pypi.io/{{ name }}/{{ name }}-v{{ version }}.zip
https://pypi.io/{{ name }}/{{ name }}-v{{ version }}.tar
https://pypi.io/{{ name }}/{{ name }}-v{{ version }}.tar.bz2
https://pypi.io/{{ name }}/{{ name }}-v{{ version }}.tar.xz
""",
# test_url_transform_complicated_github
"""https://github.com/archive/{{ name }}/v{{ version }}.tgz""": r"""
https://github.com/archive/{{ name }}/v{{ version }}.tgz
https://github.com/archive/{{ name }}/v{{ version }}.tar.gz
https://github.com/archive/{{ name }}/v{{ version }}.zip
https://github.com/archive/{{ name }}/v{{ version }}.tar
https://github.com/archive/{{ name }}/v{{ version }}.tar.bz2
https://github.com/archive/{{ name }}/v{{ version }}.tar.xz
https://github.com/archive/{{ name }}/{{ version }}.tgz
https://github.com/archive/{{ name }}/{{ version }}.tar.gz
https://github.com/archive/{{ name }}/{{ version }}.zip
https://github.com/archive/{{ name }}/{{ version }}.tar
https://github.com/archive/{{ name }}/{{ version }}.tar.bz2
https://github.com/archive/{{ name }}/{{ version }}.tar.xz
https://github.com/releases/download/v{{ version }}/{{ name }}/{{ name }}-v{{ version }}.tgz
https://github.com/releases/download/v{{ version }}/{{ name }}/{{ name }}-v{{ version }}.tar.gz
https://github.com/releases/download/v{{ version }}/{{ name }}/{{ name }}-v{{ version }}.zip
https://github.com/releases/download/v{{ version }}/{{ name }}/{{ name }}-v{{ version }}.tar
https://github.com/releases/download/v{{ version }}/{{ name }}/{{ name }}-v{{ version }}.tar.bz2
https://github.com/releases/download/v{{ version }}/{{ name }}/{{ name }}-v{{ version }}.tar.xz
https://github.com/releases/download/{{ version }}/{{ name }}/{{ name }}-{{ version }}.tgz
https://github.com/releases/download/{{ version }}/{{ name }}/{{ name }}-{{ version }}.tar.gz
https://github.com/releases/download/{{ version }}/{{ name }}/{{ name }}-{{ version }}.zip
https://github.com/releases/download/{{ version }}/{{ name }}/{{ name }}-{{ version }}.tar
https://github.com/releases/download/{{ version }}/{{ name }}/{{ name }}-{{ version }}.tar.bz2
https://github.com/releases/download/{{ version }}/{{ name }}/{{ name }}-{{ version }}.tar.xz
""",
}
@pytest.parametrize("url", TRANFORM_URLS)
def test_url_transform(url: str):
urls = {*gen_transformed_urls(url.strip())}
expected = {line.strip() for line in TRANFORM_URLS[url].splitlines().strip()}
assert urls == expected
def test_url_transforms_pypi_name():
urls = set(
list(
gen_transformed_urls(
"https://pypi.io/packages/source/{{ name[0] }}/{{ name }}"
"/dash_extensions-{{ version }}.tar.gz",
),
),
)
assert any("{{ name }}-{{ version }}" in os.path.basename(url) for url in urls)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment