Skip to content

Commit c8409f6

Browse files
committed
Make tests pass after cleanup
Some tests never ran and the underlying needed some minor updates. Signed-off-by: Philippe Ombredanne <[email protected]>
1 parent 63c681b commit c8409f6

File tree

8 files changed

+54
-39
lines changed

8 files changed

+54
-39
lines changed

src/cluecode/copyrights.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2517,7 +2517,8 @@ def build_detection_from_node(
25172517
COMPANY: {<COMPANY> <MAINT>} #19603
25182518
25192519
2520-
#######################################
2520+
################################# #COPYRIGHT: {<COPY> <COPY> <MIT>} #1802
2521+
######
25212522
# VARIOUS FORMS OF COPYRIGHT
25222523
#######################################
25232524
@@ -2572,6 +2573,8 @@ def build_detection_from_node(
25722573
25732574
COPYRIGHT: {<COPY> <COPY> <COMP>+} #1690
25742575
2576+
COPYRIGHT: {<COPY> <COPY> <MIT>} #1802
2577+
25752578
COPYRIGHT: {<COPY> <COPY> <NN>+ <COMPANY|NAME|NAME-EMAIL>+} #1710
25762579
25772580
COPYRIGHT: {<COPY> <COPY> <NN> <NNP> <NN> <COMPANY>} #1711

src/packagedcode/recognize.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from packagedcode import ALL_DATAFILE_HANDLERS
1717
from packagedcode import models
1818

19-
TRACE = False or os.environ.get('SCANCODE_DEBUG_PACKAGE_API', False)
19+
TRACE = os.environ.get('SCANCODE_DEBUG_PACKAGE_API', False)
2020

2121

2222
def logger_debug(*args):
@@ -62,7 +62,6 @@ def recognize_package_data(
6262
datafile_handlers = APPLICATION_PACKAGE_DATAFILE_HANDLERS
6363
elif system:
6464
datafile_handlers = SYSTEM_PACKAGE_DATAFILE_HANDLERS
65-
6665
return list(_parse(location, datafile_handlers=datafile_handlers))
6766

6867

@@ -78,6 +77,9 @@ def _parse(
7877
"""
7978

8079
for handler in datafile_handlers:
80+
if TRACE:
81+
logger_debug(f'_parse:.is_datafile: {handler}')
82+
8183
if not handler.is_datafile(location):
8284
continue
8385

src/packagedcode/rpm.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,9 @@ class RpmInstalledNdbDatabaseHandler(BaseRpmInstalledDatabaseHandler):
233233
# TODO: add dependencies!!!
234234
class RpmInstalledSqliteDatabaseHandler(BaseRpmInstalledDatabaseHandler):
235235
# used by newer RHEL/CentOS/Fedora/CoreOS
236+
# Filetype: SQLite 3.x database, ...
237+
# Mimetype: application/vnd.sqlite3
238+
236239
datasource_id = 'rpm_installed_database_sqlite'
237240
path_patterns = ('*rpm/rpmdb.sqlite',)
238241
default_package_type = 'rpm'

src/textcode/strings.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -180,33 +180,33 @@ def is_shared_object(s):
180180
return so(s)
181181

182182

183+
# TODO: implement me
184+
_posix = re.compile('^/[\\w_\\-].*$', re.IGNORECASE).match
183185
def is_posix_path(s):
184186
"""
185187
Return True if s looks like a posix path.
186188
Example: /usr/lib/librt.so.1 or /usr/lib
187189
"""
188-
# TODO: implement me
189-
posix = re.compile('^/[\\w_\\-].*$', re.IGNORECASE).match
190-
posix(s)
191-
return False
190+
return _posix(s)
192191

193192

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

202202

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

211211

212212
def is_c_source(s):

tests/packagedcode/test_maven.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ def test_get_top_level_resources(self):
274274
pom_resource = codebase.get_resource(
275275
'activiti-image-generator-7-201802-EA-sources.jar-extract/META-INF/maven/org.activiti/activiti-image-generator/pom.xml'
276276
)
277-
assert pom_resource is True
277+
assert pom_resource
278278
top_level_resources_paths = [
279279
r.path for r in maven.MavenPomXmlHandler.get_top_level_resources(pom_resource, codebase)
280280
]

tests/packagedcode/test_pypi.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -417,23 +417,23 @@ def test_parse_dependency_file_with_invalid_does_not_fail(self):
417417
expected_loc = self.get_test_loc('pypi/requirements_txt/invalid_spec/output.expected.json')
418418
self.check_packages_data(package, expected_loc, regen=REGEN_TEST_FIXTURES)
419419

420-
@pytest.mark.parametrize(
421-
'filename',
422-
[
423-
'dev-requirements.txt',
424-
'reqs.txt',
425-
'requirements/base.txt',
426-
'requirements-dev.txt',
427-
'requirements.in',
428-
'requirements.pip',
429-
'requirements.txt',
430-
'requirement.txt',
431-
'requires.txt',
432-
'some-requirements-dev.txt',
433-
]
434-
)
435-
def test_PipRequirementsFileHandler_is_datafile(self, filename):
436-
assert pypi.PipRequirementsFileHandler.is_datafile(filename, _bare_filename=True)
420+
@pytest.mark.parametrize(
421+
'filename',
422+
[
423+
'dev-requirements.txt',
424+
'reqs.txt',
425+
'requirements/base.txt',
426+
'requirements-dev.txt',
427+
'requirements.in',
428+
'requirements.pip',
429+
'requirements.txt',
430+
'requirement.txt',
431+
'requires.txt',
432+
'some-requirements-dev.txt',
433+
]
434+
)
435+
def test_PipRequirementsFileHandler_is_datafile(filename):
436+
assert pypi.PipRequirementsFileHandler.is_datafile(location=filename, _bare_filename=True)
437437

438438

439439
class TestPyPiPipfile(PackageTester):

tests/summarycode/test_summarizer.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -258,16 +258,15 @@ def test_get_primary_language(self):
258258
assert result_1 == expected_1
259259

260260
def test_get_holders_from_copyright(self):
261-
test_copyright = 'Copyright (c) 2017, The University of Chicago. All rights reserved.'
262-
expected_1 = ['The University of Chicago']
263-
result_1 = get_holders_from_copyright(test_copyright)
264-
assert result_1 == expected_1
261+
test_copyright_string = 'Copyright (c) 2017, The University of Chicago. All rights reserved.'
262+
result = list(get_holders_from_copyright(test_copyright_string))
263+
assert result == ['The University of Chicago']
265264

266-
test_copyrights = [
265+
test_copyright_lines = [
267266
'Copyright (c) 2017, The University of Chicago. All rights reserved.',
268267
'Copyright (c) MIT',
269268
'Copyright (c) Apache Software Foundation',
270269
]
271-
expected_2 = ['The University of Chicago', 'MIT', 'Apache Software Foundation']
272-
result_2 = get_holders_from_copyright(test_copyrights)
273-
assert result_2 == expected_2
270+
271+
result = list(get_holders_from_copyright(test_copyright_lines))
272+
assert result == ['The University of Chicago', 'MIT', 'Apache Software Foundation']

tests/textcode/test_strings.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@
1111
import json
1212
import os
1313

14+
import pytest
1415
from commoncode.testcase import FileBasedTesting
1516

1617
from scancode_config import REGEN_TEST_FIXTURES
1718
from textcode import strings
1819

1920

21+
2022
class TestStrings(FileBasedTesting):
2123
test_data_dir = os.path.join(os.path.dirname(__file__), 'data')
2224

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

162-
def test_is_relative_path(self):
164+
def test_is_relative_path_win(self):
163165
# Win Path
164166
path = "c:\\usr\\lib\\librt.so.1."
165-
assert strings.is_relative_path(path) is False
167+
assert not strings.is_relative_path(path)
168+
169+
@pytest.mark.xfail(reason="is_relative_path is not implemented on Windows")
170+
def test_is_relative_path_win2(self):
171+
path = "usr\\lib\\librt.so.1."
172+
assert strings.is_relative_path(path) is True
166173

174+
def test_is_relative_path_posix(self):
167175
# Relative Posix Path
168176
path = "usr/lib/librt.so.1"
169177
assert strings.is_relative_path(path) is True

0 commit comments

Comments
 (0)