Skip to content

Commit

Permalink
Make tests pass after cleanup
Browse files Browse the repository at this point in the history
Some tests never ran and the underlying needed some minor updates.

Signed-off-by: Philippe Ombredanne <[email protected]>
  • Loading branch information
pombredanne committed Feb 24, 2024
1 parent 63c681b commit c8409f6
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 39 deletions.
5 changes: 4 additions & 1 deletion src/cluecode/copyrights.py
Original file line number Diff line number Diff line change
Expand Up @@ -2517,7 +2517,8 @@ def build_detection_from_node(
COMPANY: {<COMPANY> <MAINT>} #19603
#######################################
################################# #COPYRIGHT: {<COPY> <COPY> <MIT>} #1802
######
# VARIOUS FORMS OF COPYRIGHT
#######################################
Expand Down Expand Up @@ -2572,6 +2573,8 @@ def build_detection_from_node(
COPYRIGHT: {<COPY> <COPY> <COMP>+} #1690
COPYRIGHT: {<COPY> <COPY> <MIT>} #1802
COPYRIGHT: {<COPY> <COPY> <NN>+ <COMPANY|NAME|NAME-EMAIL>+} #1710
COPYRIGHT: {<COPY> <COPY> <NN> <NNP> <NN> <COMPANY>} #1711
Expand Down
6 changes: 4 additions & 2 deletions src/packagedcode/recognize.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from packagedcode import ALL_DATAFILE_HANDLERS
from packagedcode import models

TRACE = False or os.environ.get('SCANCODE_DEBUG_PACKAGE_API', False)
TRACE = os.environ.get('SCANCODE_DEBUG_PACKAGE_API', False)


def logger_debug(*args):
Expand Down Expand Up @@ -62,7 +62,6 @@ def recognize_package_data(
datafile_handlers = APPLICATION_PACKAGE_DATAFILE_HANDLERS
elif system:
datafile_handlers = SYSTEM_PACKAGE_DATAFILE_HANDLERS

return list(_parse(location, datafile_handlers=datafile_handlers))


Expand All @@ -78,6 +77,9 @@ def _parse(
"""

for handler in datafile_handlers:
if TRACE:
logger_debug(f'_parse:.is_datafile: {handler}')

if not handler.is_datafile(location):
continue

Expand Down
3 changes: 3 additions & 0 deletions src/packagedcode/rpm.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@ class RpmInstalledNdbDatabaseHandler(BaseRpmInstalledDatabaseHandler):
# TODO: add dependencies!!!
class RpmInstalledSqliteDatabaseHandler(BaseRpmInstalledDatabaseHandler):
# used by newer RHEL/CentOS/Fedora/CoreOS
# Filetype: SQLite 3.x database, ...
# Mimetype: application/vnd.sqlite3

datasource_id = 'rpm_installed_database_sqlite'
path_patterns = ('*rpm/rpmdb.sqlite',)
default_package_type = 'rpm'
Expand Down
16 changes: 8 additions & 8 deletions src/textcode/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,33 +180,33 @@ def is_shared_object(s):
return so(s)


# TODO: implement me
_posix = re.compile('^/[\\w_\\-].*$', re.IGNORECASE).match
def is_posix_path(s):
"""
Return True if s looks like a posix path.
Example: /usr/lib/librt.so.1 or /usr/lib
"""
# TODO: implement me
posix = re.compile('^/[\\w_\\-].*$', re.IGNORECASE).match
posix(s)
return False
return _posix(s)


# TODO: implement me
_relative = re.compile('^(?:([^/]|\\.\\.)[\\w_\\-]+/.*$)', re.IGNORECASE).match
def is_relative_path(s):
"""
Return True if s looks like a relative posix path.
Example: usr/lib/librt.so.1 or ../usr/lib
"""
relative = re.compile('^(?:([^/]|\\.\\.)[\\w_\\-]+/.*$)', re.IGNORECASE).match
return relative(s)
return bool(_relative(s))


_winpath = re.compile('^[\\w_\\-]+\\.so\\.[0-9]+\\.*.[0-9]*$', re.IGNORECASE).match
def is_win_path(s):
"""
Return True if s looks like a win path.
Example: c:\\usr\\lib\\librt.so.1.
"""
winpath = re.compile('^[\\w_\\-]+\\.so\\.[0-9]+\\.*.[0-9]*$', re.IGNORECASE).match
return winpath(s)
return _winpath(s)


def is_c_source(s):
Expand Down
2 changes: 1 addition & 1 deletion tests/packagedcode/test_maven.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ def test_get_top_level_resources(self):
pom_resource = codebase.get_resource(
'activiti-image-generator-7-201802-EA-sources.jar-extract/META-INF/maven/org.activiti/activiti-image-generator/pom.xml'
)
assert pom_resource is True
assert pom_resource
top_level_resources_paths = [
r.path for r in maven.MavenPomXmlHandler.get_top_level_resources(pom_resource, codebase)
]
Expand Down
34 changes: 17 additions & 17 deletions tests/packagedcode/test_pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,23 +417,23 @@ def test_parse_dependency_file_with_invalid_does_not_fail(self):
expected_loc = self.get_test_loc('pypi/requirements_txt/invalid_spec/output.expected.json')
self.check_packages_data(package, expected_loc, regen=REGEN_TEST_FIXTURES)

@pytest.mark.parametrize(
'filename',
[
'dev-requirements.txt',
'reqs.txt',
'requirements/base.txt',
'requirements-dev.txt',
'requirements.in',
'requirements.pip',
'requirements.txt',
'requirement.txt',
'requires.txt',
'some-requirements-dev.txt',
]
)
def test_PipRequirementsFileHandler_is_datafile(self, filename):
assert pypi.PipRequirementsFileHandler.is_datafile(filename, _bare_filename=True)
@pytest.mark.parametrize(
'filename',
[
'dev-requirements.txt',
'reqs.txt',
'requirements/base.txt',
'requirements-dev.txt',
'requirements.in',
'requirements.pip',
'requirements.txt',
'requirement.txt',
'requires.txt',
'some-requirements-dev.txt',
]
)
def test_PipRequirementsFileHandler_is_datafile(filename):
assert pypi.PipRequirementsFileHandler.is_datafile(location=filename, _bare_filename=True)


class TestPyPiPipfile(PackageTester):
Expand Down
15 changes: 7 additions & 8 deletions tests/summarycode/test_summarizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,16 +258,15 @@ def test_get_primary_language(self):
assert result_1 == expected_1

def test_get_holders_from_copyright(self):
test_copyright = 'Copyright (c) 2017, The University of Chicago. All rights reserved.'
expected_1 = ['The University of Chicago']
result_1 = get_holders_from_copyright(test_copyright)
assert result_1 == expected_1
test_copyright_string = 'Copyright (c) 2017, The University of Chicago. All rights reserved.'
result = list(get_holders_from_copyright(test_copyright_string))
assert result == ['The University of Chicago']

test_copyrights = [
test_copyright_lines = [
'Copyright (c) 2017, The University of Chicago. All rights reserved.',
'Copyright (c) MIT',
'Copyright (c) Apache Software Foundation',
]
expected_2 = ['The University of Chicago', 'MIT', 'Apache Software Foundation']
result_2 = get_holders_from_copyright(test_copyrights)
assert result_2 == expected_2

result = list(get_holders_from_copyright(test_copyright_lines))
assert result == ['The University of Chicago', 'MIT', 'Apache Software Foundation']
12 changes: 10 additions & 2 deletions tests/textcode/test_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
import json
import os

import pytest
from commoncode.testcase import FileBasedTesting

from scancode_config import REGEN_TEST_FIXTURES
from textcode import strings



class TestStrings(FileBasedTesting):
test_data_dir = os.path.join(os.path.dirname(__file__), 'data')

Expand Down Expand Up @@ -159,11 +161,17 @@ def test_strings_in_all_bin(self):
expected_file = os.path.join(expec_dir, tf + '.strings')
self.check_file_strings(test_file, expected_file)

def test_is_relative_path(self):
def test_is_relative_path_win(self):
# Win Path
path = "c:\\usr\\lib\\librt.so.1."
assert strings.is_relative_path(path) is False
assert not strings.is_relative_path(path)

@pytest.mark.xfail(reason="is_relative_path is not implemented on Windows")
def test_is_relative_path_win2(self):
path = "usr\\lib\\librt.so.1."
assert strings.is_relative_path(path) is True

def test_is_relative_path_posix(self):
# Relative Posix Path
path = "usr/lib/librt.so.1"
assert strings.is_relative_path(path) is True
Expand Down

0 comments on commit c8409f6

Please sign in to comment.