Skip to content
This repository was archived by the owner on Apr 30, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions taskotron_python_versions/unversioned_shebangs.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,15 @@ def get_problematic_files(archive, query):
return problematic


def shebang_to_require(shebang):
"""Convert shebang to the format of requirement."""
return shebang.split()[0][2:].encode()
def shebang_to_require(shebang, use_bytes=True):
"""Convert shebang to the format of requirement.
If the use_bytes argument is set to False, executable path
is returned as a string instead of the default bytes type."""
executable_path = shebang.split()[0][2:]
if use_bytes:
return executable_path.encode()
else:
return executable_path


def get_scripts_summary(package):
Expand All @@ -52,8 +58,14 @@ def get_scripts_summary(package):

for shebang in FORBIDDEN_SHEBANGS:
if shebang_to_require(shebang) in package.require_names:
scripts_summary[shebang] = get_problematic_files(
package.path, shebang)
log.debug('Package {} requires {}'.format(
package.filename, shebang_to_require(
shebang, use_bytes=False)))
problematic = get_problematic_files(package.path, shebang)
if problematic:
log.debug('{} shebang was found in scripts: {}'.format(
shebang, ', '.join(problematic)))
scripts_summary[shebang] = problematic
return scripts_summary


Expand Down
Binary file not shown.
15 changes: 9 additions & 6 deletions test/functional/test_unversioned_shebangs.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,15 @@ def test_get_problematic_files(archive, query, expected):
assert get_problematic_files(gpkg_path(archive), query) == expected


@pytest.mark.parametrize(('shebang', 'expected'), (
("#!/foo", b"/foo"),
("#!/usr/bin/python", b"/usr/bin/python"),
("#!/usr/bin/env python", b"/usr/bin/env"),
@pytest.mark.parametrize(('shebang', 'use_bytes', 'expected'), (
("#!/foo", True, b"/foo"),
("#!/usr/bin/python", True, b"/usr/bin/python"),
("#!/usr/bin/env python", True, b"/usr/bin/env"),
("#!/usr/bin/python", False, "/usr/bin/python"),
("#!/usr/bin/env python", False, "/usr/bin/env"),
))
def test_shebang_to_require(shebang, expected):
assert shebang_to_require(shebang) == expected
def test_shebang_to_require(shebang, use_bytes, expected):
assert shebang_to_require(shebang, use_bytes) == expected


@pytest.mark.parametrize(('glob', 'expected'), (
Expand All @@ -58,6 +60,7 @@ def test_shebang_to_require(shebang, expected):
('/usr/lib/python3.6/site-packages/'
'django/conf/project_template/manage.py-tpl')}}),
('pyserial*', {}),
('nodejs-semver*', {}),
))
def test_get_scripts_summary(glob, expected):
assert get_scripts_summary(gpkg(glob)) == expected
9 changes: 6 additions & 3 deletions test/integration/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,13 @@ def results(request):
_docutils = fixtures_factory('python-docutils-0.13.1-4.fc26')
docutils = fixtures_factory('_docutils')

_nodejs = fixtures_factory('nodejs-semver-5.1.1-2.fc26')
nodejs = fixtures_factory('_nodejs')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add the new fixture to the first test, so all the downloading etc. happens at the beginning and all other tests happens at once?



@pytest.mark.parametrize('results', ('eric', 'six', 'admesh', 'tracer',
'copr', 'epub', 'twine', 'yum',
'vdirsyncer', 'docutils'))
'vdirsyncer', 'docutils', 'nodejs'))
def test_number_of_results(results, request):
# getting a fixture by name
# https://github.com/pytest-dev/pytest/issues/349#issuecomment-112203541
Expand Down Expand Up @@ -282,8 +285,8 @@ def test_artifact_contains_executables_and_looks_as_expected(
""").strip() in artifact.strip()


@pytest.mark.parametrize('results', ('eric', 'six', 'admesh',
'copr', 'epub', 'twine'))
@pytest.mark.parametrize('results', ('eric', 'six', 'admesh', 'copr',
'epub', 'twine', 'nodejs'))
def test_unvesioned_shebangs_passed(results, request):
results = request.getfixturevalue(results)
assert results['python-versions.unversioned_shebangs'].outcome == 'PASSED'
Expand Down