Skip to content
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
2 changes: 1 addition & 1 deletion src/metacheck/scripts/pitfalls/p002.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def extract_license_from_file(somef_data: Dict) -> Optional[Dict[str, str]]:
for entry in license_entries:
if "source" in entry:
source = entry["source"]
if "LICENSE.md" in source:
if "license" in source.lower():
if "result" in entry and "value" in entry["result"]:
return {
"source": source,
Expand Down
5 changes: 5 additions & 0 deletions src/metacheck/scripts/pitfalls/p008.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ def check_url_status(url: str, timeout: int = 10) -> Dict:
result["error"] = "Invalid URL format"
return result

if url.startswith(('git+', 'git://', 'svn+', 'hg+', 'bzr+')):
result["is_accessible"] = True
result["status_code"] = 200
return result

try:
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'
Expand Down
20 changes: 10 additions & 10 deletions src/metacheck/scripts/tests/test_w003.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class TestDetectDualLicenseMissingCodemetaPitfall:
"""Test suite for detect_dual_license_missing_codemeta_pitfall function"""

@pytest.mark.parametrize(
"somef_data,file_name,expected_has_pitfall,expected_dual_indicator,expected_codemeta_count",
"somef_data,file_name,expected_has_warning,expected_dual_indicator,expected_codemeta_count",
[
# No license key
(
Expand Down Expand Up @@ -363,12 +363,12 @@ class TestDetectDualLicenseMissingCodemetaPitfall:
1
),
])
def test_detect_pitfall_scenarios(self, somef_data, file_name, expected_has_pitfall,
def test_detect_pitfall_scenarios(self, somef_data, file_name, expected_has_warning,
expected_dual_indicator, expected_codemeta_count):
"""Test various dual license missing codemeta scenarios"""
result = detect_dual_license_missing_codemeta_pitfall(somef_data, file_name)

assert result["has_pitfall"] == expected_has_pitfall
assert result["has_warning"] == expected_has_warning
assert result["file_name"] == file_name
assert result["has_dual_license_indicator"] == expected_dual_indicator
assert result["codemeta_license_count"] == expected_codemeta_count
Expand All @@ -381,7 +381,7 @@ def test_result_structure(self):
somef_data = {}
result = detect_dual_license_missing_codemeta_pitfall(somef_data, "test.json")

assert "has_pitfall" in result
assert "has_warning" in result
assert "file_name" in result
assert "has_dual_license_indicator" in result
assert "codemeta_license_count" in result
Expand Down Expand Up @@ -433,7 +433,7 @@ def test_multiple_codemeta_licenses_no_pitfall(self):
}

result = detect_dual_license_missing_codemeta_pitfall(somef_data, "test.json")
assert result["has_pitfall"] == False
assert result["has_warning"] == False
assert result["codemeta_license_count"] == 3

def test_all_dual_license_patterns(self):
Expand Down Expand Up @@ -469,7 +469,7 @@ def test_all_dual_license_patterns(self):

result = detect_dual_license_missing_codemeta_pitfall(somef_data, "test.json")
assert result["has_dual_license_indicator"] == True, f"Pattern '{pattern}' not detected"
assert result["has_pitfall"] == True
assert result["has_warning"] == True

def test_non_codemeta_technique_not_counted(self):
"""Test that non-code_parser technique doesn't count as codemeta license"""
Expand All @@ -489,7 +489,7 @@ def test_non_codemeta_technique_not_counted(self):

result = detect_dual_license_missing_codemeta_pitfall(somef_data, "test.json")
assert result["codemeta_license_count"] == 0
assert result["has_pitfall"] == True
assert result["has_warning"] == True

def test_first_dual_license_pattern_wins(self):
"""Test that first matching pattern sets the source"""
Expand Down Expand Up @@ -535,7 +535,7 @@ def test_missing_result_or_value_handled(self):
}

result = detect_dual_license_missing_codemeta_pitfall(somef_data, "test.json")
assert result["has_pitfall"] == False
assert result["has_warning"] == False
assert result["codemeta_license_count"] == 1

def test_edge_case_exactly_one_codemeta_license(self):
Expand All @@ -556,7 +556,7 @@ def test_edge_case_exactly_one_codemeta_license(self):

result = detect_dual_license_missing_codemeta_pitfall(somef_data, "test.json")
assert result["codemeta_license_count"] == 1
assert result["has_pitfall"] == True
assert result["has_warning"] == True

def test_edge_case_exactly_two_codemeta_licenses(self):
"""Test boundary condition with exactly 2 codemeta licenses"""
Expand All @@ -581,4 +581,4 @@ def test_edge_case_exactly_two_codemeta_licenses(self):

result = detect_dual_license_missing_codemeta_pitfall(somef_data, "test.json")
assert result["codemeta_license_count"] == 2
assert result["has_pitfall"] == False
assert result["has_warning"] == False
18 changes: 9 additions & 9 deletions src/metacheck/scripts/tests/test_w009.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class TestDetectDevelopmentStatusUrlPitfall:
"""Test suite for detect_development_status_url_pitfall function"""

@pytest.mark.parametrize(
"somef_data,file_name,expected_has_pitfall,expected_status,expected_is_url", [
"somef_data,file_name,expected_has_warning,expected_status,expected_is_url", [
# No development_status key
(
{},
Expand Down Expand Up @@ -332,12 +332,12 @@ class TestDetectDevelopmentStatusUrlPitfall:
),
])
def test_detect_development_status_url_scenarios(self, somef_data, file_name,
expected_has_pitfall, expected_status,
expected_has_warning, expected_status,
expected_is_url):
"""Test various scenarios for development status URL detection"""
result = detect_development_status_url_pitfall(somef_data, file_name)

assert result["has_pitfall"] == expected_has_pitfall
assert result["has_warning"] == expected_has_warning
assert result["file_name"] == file_name
assert result["development_status"] == expected_status
assert result["is_url"] == expected_is_url
Expand All @@ -347,7 +347,7 @@ def test_result_structure(self):
somef_data = {}
result = detect_development_status_url_pitfall(somef_data, "test.json")

assert "has_pitfall" in result
assert "has_warning" in result
assert "file_name" in result
assert "development_status" in result
assert "source" in result
Expand All @@ -372,7 +372,7 @@ def test_stops_at_first_match(self):

result = detect_development_status_url_pitfall(somef_data, "test.json")

assert result["has_pitfall"] is True
assert result["has_warning"] is True
assert result["development_status"] == "https://example.com"

@pytest.mark.parametrize("url_value", [
Expand All @@ -394,7 +394,7 @@ def test_various_url_formats(self, url_value):
}

result = detect_development_status_url_pitfall(somef_data, "test.json")
assert result["has_pitfall"] is True
assert result["has_warning"] is True
assert result["development_status"] == url_value

@pytest.mark.parametrize("valid_status", [
Expand All @@ -420,7 +420,7 @@ def test_valid_status_strings(self, valid_status):
}

result = detect_development_status_url_pitfall(somef_data, "test.json")
assert result["has_pitfall"] is False
assert result["has_warning"] is False

def test_source_variations(self):
"""Test various source path formats for codemeta.json"""
Expand All @@ -445,7 +445,7 @@ def test_source_variations(self):
}

result = detect_development_status_url_pitfall(somef_data, "test.json")
assert result["has_pitfall"] == should_trigger, f"Failed for source: {source}"
assert result["has_warning"] == should_trigger, f"Failed for source: {source}"

def test_non_string_values(self):
"""Test that non-string values don't cause errors"""
Expand All @@ -467,4 +467,4 @@ def test_non_string_values(self):
}

result = detect_development_status_url_pitfall(somef_data, "test.json")
assert result["has_pitfall"] is False
assert result["has_warning"] is False
20 changes: 10 additions & 10 deletions src/metacheck/scripts/tests/test_w010.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class TestDetectGitRemoteShorthandPitfall:
"""Test suite for detect_git_remote_shorthand_pitfall function"""

@pytest.mark.parametrize(
"somef_data,file_name,expected_has_pitfall,expected_url,expected_source_file", [
"somef_data,file_name,expected_has_warning,expected_url,expected_source_file", [
# No code_repository key
(
{},
Expand Down Expand Up @@ -329,27 +329,27 @@ class TestDetectGitRemoteShorthandPitfall:
),
])
def test_detect_git_shorthand_scenarios(self, somef_data, file_name,
expected_has_pitfall, expected_url,
expected_has_warning, expected_url,
expected_source_file):
"""Test various scenarios for Git remote shorthand detection"""
with patch('metacheck.scripts.warnings.w010.extract_metadata_source_filename',
return_value=expected_source_file):
result = detect_git_remote_shorthand_pitfall(somef_data, file_name)

assert result["has_pitfall"] == expected_has_pitfall
assert result["has_warning"] == expected_has_warning
assert result["file_name"] == file_name
assert result["repository_url"] == expected_url
assert result["is_shorthand"] == expected_has_pitfall
assert result["is_shorthand"] == expected_has_warning

if expected_has_pitfall:
if expected_has_warning:
assert result["metadata_source_file"] == expected_source_file

def test_result_structure(self):
"""Test that result always has the expected structure"""
somef_data = {}
result = detect_git_remote_shorthand_pitfall(somef_data, "test.json")

assert "has_pitfall" in result
assert "has_warning" in result
assert "file_name" in result
assert "repository_url" in result
assert "source" in result
Expand All @@ -374,7 +374,7 @@ def test_all_metadata_sources(self, metadata_file):
with patch('metacheck.scripts.warnings.w010.extract_metadata_source_filename',
return_value=metadata_file):
result = detect_git_remote_shorthand_pitfall(somef_data, "test.json")
assert result["has_pitfall"] is True
assert result["has_warning"] is True
assert result["metadata_source_file"] == metadata_file

def test_stops_at_first_match(self):
Expand All @@ -398,7 +398,7 @@ def test_stops_at_first_match(self):
side_effect=["codemeta.json", "package.json"]):
result = detect_git_remote_shorthand_pitfall(somef_data, "test.json")

assert result["has_pitfall"] is True
assert result["has_warning"] is True
assert result["repository_url"] == "github.com:user/repo1.git"

@pytest.mark.parametrize("shorthand_url", [
Expand All @@ -421,7 +421,7 @@ def test_various_shorthand_formats(self, shorthand_url):
with patch('metacheck.scripts.warnings.w010.extract_metadata_source_filename',
return_value="codemeta.json"):
result = detect_git_remote_shorthand_pitfall(somef_data, "test.json")
assert result["has_pitfall"] is True
assert result["has_warning"] is True
assert result["repository_url"] == shorthand_url

def test_missing_technique_field(self):
Expand All @@ -437,4 +437,4 @@ def test_missing_technique_field(self):
return_value="codemeta.json"):
result = detect_git_remote_shorthand_pitfall(somef_data, "test.json")
# Should still detect based on source matching
assert result["has_pitfall"] is True
assert result["has_warning"] is True
4 changes: 2 additions & 2 deletions src/metacheck/utils/json_ld_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,10 @@ def format_evidence_text(pitfall_code: str, pitfall_result: Dict) -> str:
reqs = pitfall_result["unversioned_requirements"]
metadata_source = extract_metadata_source(pitfall_result)
if isinstance(reqs, list) and len(reqs) > 0:
clean_reqs = [str(req) for req in reqs if req is not None][:3]
clean_reqs = [str(req) for req in reqs if req is not None]
if clean_reqs:
req_list = ', '.join(clean_reqs)
return f"{evidence_base}{metadata_source} contains software requirements without versions: {req_list}{'...' if len(reqs) > 3 else ''}"
return f"{evidence_base}{metadata_source} contains software requirements without versions: {req_list}"
return f"{evidence_base}Software requirements found without version specifications"

elif pitfall_code == "W002":
Expand Down