def test_comments(): parsed = parsing._parse_requirement( io.StringIO(""" pypi::foo # some text # other text bar """)) assert parsed == {REPO_PYPI: get_reqs('foo') + get_reqs('bar')}
def test_other_lines_with_fades_string(): parsed = parsing._parse_content( io.StringIO(""" import bar # fades print("screen fades to black") """)) assert parsed == {REPO_PYPI: get_reqs('bar')}
def test_simple_default(): parsed = parsing._parse_content( io.StringIO(""" import time import foo # fades """)) assert parsed == {REPO_PYPI: get_reqs('foo')}
def test_mixed(): parsed = parsing.parse_manual( ["pypi::foo", "vcs::git+git://server.com/etc"]) assert parsed == { REPO_PYPI: get_reqs("foo"), REPO_VCS: [parsing.VCSDependency("git+git://server.com/etc")], }
def test_match_due_to_options(venvscache): reqs = {'pypi': get_reqs('dep == 5')} interpreter = 'pythonX.Y' options = {'foo': 'bar'} venv1 = json.dumps({ 'metadata': 'venv1', 'installed': { 'pypi': { 'dep': '5' } }, 'interpreter': 'pythonX.Y', 'options': {} }) venv2 = json.dumps({ 'metadata': 'venv2', 'installed': { 'pypi': { 'dep': '5' } }, 'interpreter': 'pythonX.Y', 'options': { 'foo': 'bar' } }) resp = venvscache._select([venv1, venv2], reqs, interpreter, uuid='', options=options) assert resp == "venv2"
def test_fades_and_hashtag_mentioned_in_code_mixed_with_imports(): parsed = parsing._parse_content( io.StringIO("""import requests # fades 'http://fades.readthedocs.io/en/release-7-0/readme.html#how-to-use-it' """)) assert parsed == {REPO_PYPI: get_reqs('requests')}
def test_nested_requirement_files_first_line(create_tmpfile): requirement_file = create_tmpfile(['foo']) requirement_file_nested = create_tmpfile( ['\n-r {}\nbar'.format(requirement_file)]) parsed = parsing.parse_reqfile(requirement_file_nested) assert parsed == {REPO_PYPI: get_reqs('foo', 'bar')}
def test_nested_requirement_files_not_pwd(create_tmpfile): requirement_file = create_tmpfile(['foo']) fname = os.path.basename(requirement_file) requirement_file_nested = create_tmpfile(['bar\n-r {}'.format(fname)]) parsed = parsing.parse_reqfile(requirement_file_nested) assert parsed, {REPO_PYPI: get_reqs('bar', 'foo')}
def test_nested_requirement_files_invalid_format(logged, create_tmpfile): requirement_file_nested = create_tmpfile(['foo\n-r']) parsed = parsing.parse_reqfile(requirement_file_nested) assert parsed == {REPO_PYPI: get_reqs('foo')} logged.assert_warning( "Invalid format to indicate a nested requirements file:")
def test_nested_requirement_files(create_tmpfile): requirement_file = create_tmpfile(['foo']) requirement_file_nested = create_tmpfile( ['bar\n-r {}'.format(requirement_file)]) parsed = parsing.parse_reqfile(requirement_file_nested) assert parsed == {REPO_PYPI: get_reqs('bar', 'foo')}
def test_match_mixed_multiple(venvscache): reqs = { 'vcs': [parsing.VCSDependency('url1'), parsing.VCSDependency('url2')], 'pypi': get_reqs('dep1 == 5', 'dep2') } interpreter = 'pythonX.Y' options = {'foo': 'bar'} venv = json.dumps({ 'metadata': 'foobar', 'installed': { 'vcs': { 'url1': None, 'url2': None }, 'pypi': { 'dep1': '5', 'dep2': '7' } }, 'interpreter': 'pythonX.Y', 'options': { 'foo': 'bar' } }) resp = venvscache._select([venv], reqs, interpreter, uuid='', options=options) assert resp == 'foobar'
def test_continuation_line(): parsed = parsing._parse_content( io.StringIO(""" import bar # fades > 2 import foo """)) assert parsed == {REPO_PYPI: get_reqs('foo > 2')}
def test_with_commented_line(logs): parsed = parsing._parse_content( io.StringIO(""" import bar # fades # a commented line """)) assert parsed == {REPO_PYPI: get_reqs('bar')} assert "Not understood fades" not in logs.warning
def test_with_fades_commented_line(logged): parsed = parsing._parse_content( io.StringIO(""" #import foo # fades import bar # fades """)) assert parsed == {REPO_PYPI: get_reqs('bar')} logged.assert_not_warning("Not understood fades")
def test_mixed(): parsed = parsing._parse_content( io.StringIO(""" import foo # fades vcs::superurl import bar # fades """)) assert parsed == { REPO_VCS: [parsing.VCSDependency('superurl')], REPO_PYPI: get_reqs('bar'), }
def test_mixed(): parsed = parsing._parse_requirement( io.StringIO(""" vcs::strangeurl pypi::foo """)) assert parsed == { REPO_VCS: [parsing.VCSDependency("strangeurl")], REPO_PYPI: get_reqs('foo'), }
def test_mixed_backends(): with open("tests/test_files/req_mixed_backends.py") as f: parsed = parsing._parse_docstring(f) # Only module requirements was found assert parsed == { REPO_PYPI: get_reqs("foo", "bar"), REPO_VCS: [ parsing.VCSDependency("git+http://whatever"), parsing.VCSDependency("anotherurl"), ], }
def test_match_mixed_single(venvscache): reqs = { 'vcs': [parsing.VCSDependency('someurl')], 'pypi': get_reqs('dep == 5') } interpreter = 'pythonX.Y' options = {'foo': 'bar'} venv1 = json.dumps({ 'metadata': 'foobar1', 'installed': { 'vcs': { 'someurl': None }, 'pypi': { 'dep': '5' } }, 'interpreter': 'pythonX.Y', 'options': { 'foo': 'bar' } }) venv2 = json.dumps({ 'metadata': 'foobar2', 'installed': { 'pypi': { 'dep': '5' } }, 'interpreter': 'pythonX.Y', 'options': { 'foo': 'bar' } }) venv3 = json.dumps({ 'metadata': 'foobar3', 'installed': { 'vcs': { 'someurl': None } }, 'interpreter': 'pythonX.Y', 'options': { 'foo': 'bar' } }) resp = venvscache._select([venv1, venv2, venv3], reqs, interpreter, uuid='', options=options) assert resp == 'foobar1'
def test_multiple_match_bigger_version(venvscache): reqs = {'pypi': get_reqs('dep')} interpreter = 'pythonX.Y' options = {'foo': 'bar'} venv1 = json.dumps({ 'metadata': 'venv1', 'installed': { 'pypi': { 'dep': '3' } }, 'interpreter': 'pythonX.Y', 'options': { 'foo': 'bar' } }) venv2 = json.dumps({ 'metadata': 'venv2', 'installed': { 'pypi': { 'dep': '7' } }, 'interpreter': 'pythonX.Y', 'options': { 'foo': 'bar' } }) venv3 = json.dumps({ 'metadata': 'venv3', 'installed': { 'pypi': { 'dep': '5' } }, 'interpreter': 'pythonX.Y', 'options': { 'foo': 'bar' } }) resp = venvscache._select([venv1, venv2, venv3], reqs, interpreter, uuid='', options=options) # matches venv2 because it has the bigger version for 'dep' (even if it's not the # latest virtualenv created) assert resp == 'venv2'
def test_simple_match_empty_options(venvscache): reqs = {'pypi': get_reqs('dep == 5')} interpreter = 'pythonX.Y' options = {} venv = json.dumps({ 'metadata': 'foobar', 'installed': { 'pypi': { 'dep': '5' } }, 'interpreter': 'pythonX.Y', 'options': {} }) resp = venvscache._select([venv], reqs, interpreter, uuid='', options=options) assert resp == "foobar"
def test_nomatch_pypi_dependency(venvscache): reqs = {'pypi': get_reqs('dep1 == 5')} interpreter = 'pythonX.Y' options = {'foo': 'bar'} venv = json.dumps({ 'metadata': 'foobar', 'installed': { 'pypi': { 'dep2': '5' } }, 'interpreter': 'pythonX.Y', 'options': { 'foo': 'bar' } }) resp = venvscache._select([venv], reqs, interpreter, uuid='', options=options) resp is None
def test_match_noversion(venvscache): reqs = {'pypi': get_reqs('dep')} interpreter = 'pythonX.Y' options = {'foo': 'bar'} venv = json.dumps({ 'metadata': 'foobar', 'installed': { 'pypi': { 'dep': '5' } }, 'interpreter': 'pythonX.Y', 'options': { 'foo': 'bar' } }) resp = venvscache._select([venv], reqs, interpreter, uuid='', options=options) assert resp == 'foobar'
def test_check_versions(venvscache, req, installed, expected): """The comparison in the selection.""" reqs = {"pypi": get_reqs("dep" + req)} interpreter = "pythonX.Y" options = {"foo": "bar"} venv = json.dumps({ "metadata": "ok", "installed": { "pypi": { "dep": installed } }, "interpreter": "pythonX.Y", "options": { "foo": "bar" } }) resp = venvscache._select([venv], reqs, interpreter, uuid="", options=options) assert resp == expected
def test_multiple_deps_ok(venvscache): reqs = {'pypi': get_reqs('dep1 == 5', 'dep2 == 7')} interpreter = 'pythonX.Y' options = {'foo': 'bar'} venv = json.dumps({ 'metadata': 'foobar', 'installed': { 'pypi': { 'dep1': '5', 'dep2': '7' } }, 'interpreter': 'pythonX.Y', 'options': { 'foo': 'bar' } }) resp = venvscache._select([venv], reqs, interpreter, uuid='', options=options) assert resp == 'foobar'
def test_not_too_crowded(venvscache): reqs = {'pypi': get_reqs('dep1')} interpreter = 'pythonX.Y' options = {'foo': 'bar'} venv = json.dumps({ 'metadata': 'foobar', 'installed': { 'pypi': { 'dep1': '5', 'dep2': '2' } }, 'interpreter': 'pythonX.Y', 'options': { 'foo': 'bar' } }) resp = venvscache._select([venv], reqs, interpreter, uuid='', options=options) assert resp is None
def test_same_quantity_different_deps(venvscache): reqs = {'pypi': get_reqs('dep1', 'dep2')} interpreter = 'pythonX.Y' options = {'foo': 'bar'} venv = json.dumps({ 'metadata': 'foobar', 'installed': { 'pypi': { 'dep1': '5', 'dep3': '2' } }, 'interpreter': 'pythonX.Y', 'options': { 'foo': 'bar' } }) resp = venvscache._select([venv], reqs, interpreter, uuid='', options=options) assert resp is None
def test_version_same_two_space_after(): parsed = parsing._parse_content( io.StringIO(""" import foo # fades== 3.5 """)) assert parsed == {REPO_PYPI: get_reqs('foo == 3.5')}
def test_version_different(): parsed = parsing._parse_content( io.StringIO(""" import foo # fades !=3.5 """)) assert parsed == {REPO_PYPI: get_reqs('foo !=3.5')}
def test_comma_separated_import(): parsed = parsing._parse_content( io.StringIO(""" from foo import bar, baz, qux # fades """)) assert parsed == {REPO_PYPI: get_reqs('foo')}
def test_projectname_pkgnamedb_version_othername(): parsed = parsing._parse_content( io.StringIO(""" import bs4 # fades othername >=5 """)) assert parsed == {REPO_PYPI: get_reqs('othername >=5')}