Skip to content

Commit

Permalink
Merge pull request #375 from PyAr/normalize-get-reqs
Browse files Browse the repository at this point in the history
Normalize get_req(s) definition and usage across test files.
  • Loading branch information
facundobatista committed Jun 19, 2019
2 parents 87b2f7a + 3e4bef8 commit 5e5002b
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 112 deletions.
10 changes: 8 additions & 2 deletions tests/__init__.py
@@ -1,4 +1,4 @@
# Copyright 2017 Facundo Batista, Nicolás Demarchi
# Copyright 2017-2019 Facundo Batista, Nicolás Demarchi
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 3, as published
Expand All @@ -17,9 +17,10 @@
"""Common code for the tests."""

import os

from tempfile import mkstemp

from pkg_resources import parse_requirements


def get_tempfile(testcase):
"""Return the name of a temp file that will be removed when the test finishes."""
Expand Down Expand Up @@ -55,3 +56,8 @@ def get_python_filepaths(roots):
if filename.endswith(".py"):
python_paths.append(os.path.join(dirpath, filename))
return python_paths


def get_reqs(*items):
"""Transform text requirements into pkg_resources objects."""
return list(parse_requirements(items))
7 changes: 1 addition & 6 deletions tests/test_cache/__init__.py
Expand Up @@ -16,12 +16,7 @@

"""Helpers for the Cache tests collection."""

from pkg_resources import parse_requirements, Distribution


def get_req(text):
"""Transform a text requirement into the pkg_resources object."""
return list(parse_requirements(text))
from pkg_resources import Distribution


def get_distrib(*dep_ver_pairs):
Expand Down
5 changes: 3 additions & 2 deletions tests/test_cache/test_comparisons.py
Expand Up @@ -19,7 +19,8 @@

from fades import parsing

from tests.test_cache import get_req, get_distrib
from tests import get_reqs
from tests.test_cache import get_distrib


@pytest.mark.parametrize("req,installed,expected", [
Expand Down Expand Up @@ -55,7 +56,7 @@
])
def test_check_versions(venvscache, req, installed, expected):
"""The comparison in the selection."""
reqs = {"pypi": get_req("dep" + req)}
reqs = {"pypi": get_reqs("dep" + req)}
interpreter = "pythonX.Y"
options = {"foo": "bar"}
venv = json.dumps({
Expand Down
34 changes: 17 additions & 17 deletions tests/test_cache/test_selection.py
Expand Up @@ -19,7 +19,7 @@
import uuid

from fades import helpers, parsing
from tests.test_cache import get_req
from tests import get_reqs


def test_empty(venvscache):
Expand All @@ -28,7 +28,7 @@ def test_empty(venvscache):


def test_nomatch_repo_dependency(venvscache):
reqs = {"repoloco": get_req('dep == 5')}
reqs = {"repoloco": get_reqs('dep == 5')}
interpreter = 'pythonX.Y'
options = {'foo': 'bar'}
venv = json.dumps({
Expand All @@ -42,7 +42,7 @@ def test_nomatch_repo_dependency(venvscache):


def test_nomatch_pypi_dependency(venvscache):
reqs = {'pypi': get_req('dep1 == 5')}
reqs = {'pypi': get_reqs('dep1 == 5')}
interpreter = 'pythonX.Y'
options = {'foo': 'bar'}
venv = json.dumps({
Expand Down Expand Up @@ -70,7 +70,7 @@ def test_nomatch_vcs_dependency(venvscache):


def test_nomatch_version(venvscache):
reqs = {'pypi': get_req('dep == 5')}
reqs = {'pypi': get_reqs('dep == 5')}
interpreter = 'pythonX.Y'
options = {'foo': 'bar'}
venv = json.dumps({
Expand All @@ -84,7 +84,7 @@ def test_nomatch_version(venvscache):


def test_simple_pypi_match(venvscache):
reqs = {'pypi': get_req('dep == 5')}
reqs = {'pypi': get_reqs('dep == 5')}
interpreter = 'pythonX.Y'
options = {'foo': 'bar'}
venv = json.dumps({
Expand Down Expand Up @@ -112,7 +112,7 @@ def test_simple_vcs_match(venvscache):


def test_match_mixed_single(venvscache):
reqs = {'vcs': [parsing.VCSDependency('someurl')], 'pypi': get_req('dep == 5')}
reqs = {'vcs': [parsing.VCSDependency('someurl')], 'pypi': get_reqs('dep == 5')}
interpreter = 'pythonX.Y'
options = {'foo': 'bar'}
venv1 = json.dumps({
Expand Down Expand Up @@ -140,7 +140,7 @@ def test_match_mixed_single(venvscache):

def test_match_mixed_multiple(venvscache):
reqs = {'vcs': [parsing.VCSDependency('url1'), parsing.VCSDependency('url2')],
'pypi': get_req(['dep1 == 5', 'dep2'])}
'pypi': get_reqs('dep1 == 5', 'dep2')}
interpreter = 'pythonX.Y'
options = {'foo': 'bar'}
venv = json.dumps({
Expand All @@ -156,7 +156,7 @@ def test_match_mixed_multiple(venvscache):


def test_match_noversion(venvscache):
reqs = {'pypi': get_req('dep')}
reqs = {'pypi': get_reqs('dep')}
interpreter = 'pythonX.Y'
options = {'foo': 'bar'}
venv = json.dumps({
Expand All @@ -170,7 +170,7 @@ def test_match_noversion(venvscache):


def test_middle_match(venvscache):
reqs = {'pypi': get_req('dep == 5')}
reqs = {'pypi': get_reqs('dep == 5')}
interpreter = 'pythonX.Y'
options = {'foo': 'bar'}
venv1 = json.dumps({
Expand All @@ -197,7 +197,7 @@ def test_middle_match(venvscache):


def test_multiple_match_bigger_version(venvscache):
reqs = {'pypi': get_req('dep')}
reqs = {'pypi': get_reqs('dep')}
interpreter = 'pythonX.Y'
options = {'foo': 'bar'}
venv1 = json.dumps({
Expand Down Expand Up @@ -226,7 +226,7 @@ def test_multiple_match_bigger_version(venvscache):


def test_multiple_deps_ok(venvscache):
reqs = {'pypi': get_req(['dep1 == 5', 'dep2 == 7'])}
reqs = {'pypi': get_reqs('dep1 == 5', 'dep2 == 7')}
interpreter = 'pythonX.Y'
options = {'foo': 'bar'}
venv = json.dumps({
Expand All @@ -240,7 +240,7 @@ def test_multiple_deps_ok(venvscache):


def test_multiple_deps_just_one(venvscache):
reqs = {'pypi': get_req(['dep1 == 5', 'dep2 == 7'])}
reqs = {'pypi': get_reqs('dep1 == 5', 'dep2 == 7')}
interpreter = 'pythonX.Y'
options = {'foo': 'bar'}
venv = json.dumps({
Expand All @@ -254,7 +254,7 @@ def test_multiple_deps_just_one(venvscache):


def test_not_too_crowded(venvscache):
reqs = {'pypi': get_req(['dep1'])}
reqs = {'pypi': get_reqs('dep1')}
interpreter = 'pythonX.Y'
options = {'foo': 'bar'}
venv = json.dumps({
Expand All @@ -268,7 +268,7 @@ def test_not_too_crowded(venvscache):


def test_same_quantity_different_deps(venvscache):
reqs = {'pypi': get_req(['dep1', 'dep2'])}
reqs = {'pypi': get_reqs('dep1', 'dep2')}
interpreter = 'pythonX.Y'
options = {'foo': 'bar'}
venv = json.dumps({
Expand Down Expand Up @@ -310,7 +310,7 @@ def test_no_requirements_empty_venv(venvscache):


def test_simple_match_empty_options(venvscache):
reqs = {'pypi': get_req('dep == 5')}
reqs = {'pypi': get_reqs('dep == 5')}
interpreter = 'pythonX.Y'
options = {}
venv = json.dumps({
Expand All @@ -324,7 +324,7 @@ def test_simple_match_empty_options(venvscache):


def test_no_match_due_to_options(venvscache):
reqs = {'pypi': get_req('dep == 5')}
reqs = {'pypi': get_reqs('dep == 5')}
interpreter = 'pythonX.Y'
options = {'foo': 'bar'}
venv = json.dumps({
Expand All @@ -338,7 +338,7 @@ def test_no_match_due_to_options(venvscache):


def test_match_due_to_options(venvscache):
reqs = {'pypi': get_req('dep == 5')}
reqs = {'pypi': get_reqs('dep == 5')}
interpreter = 'pythonX.Y'
options = {'foo': 'bar'}
venv1 = json.dumps({
Expand Down

0 comments on commit 5e5002b

Please sign in to comment.