Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

Commit

Permalink
Merge pull request #136 from webscopeio/fix/analyzeDuplicities
Browse files Browse the repository at this point in the history
fix: analyze duplicities
  • Loading branch information
jvorcak committed Jun 24, 2020
2 parents 13b9831 + e96673d commit aa4bcfe
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
4 changes: 4 additions & 0 deletions license_sh/analyze/analyze_shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ def get_node_analyze_dict(directory: str) -> Dict:
with open(item.get("path"), "r") as license_file:
license_text = license_file.read()
license_result = item.get("result", {})
if license_text in [
item.get("data") for item in data_dict.get(node_id)
]:
continue
data_dict[node_id].append(
{
"data": license_text,
Expand Down
25 changes: 25 additions & 0 deletions tests/analyze/test_analyze_shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,31 @@ def test_get_node_analyze_dict(
"LICENSE",
)

@mock.patch("os.path.isfile", return_value=True)
@mock.patch("builtins.open", new_callable=mock_open, read_data="License_text")
@mock.patch("json.load")
@mock.patch("license_sh.analyze.analyze_shared.run_askalono")
def test_get_node_analyze_dict_duplicities(
self, mock_askalono, mock_json_load, mock_open, mock_isFile
):
project_name = "project_name"
project_version = "project_version"
mock_askalono.return_value = [
{
"path": "../license-sh/node_modules/react/LICENSE",
"result": {"score": 0.9993655, "license": {"name": "Apache-2.0"}},
},
{
"path": "../license-sh/node_modules/package/react/LICENSE",
"result": {"score": 0.9993655, "license": {"name": "Apache-2.0"}},
},
]
mock_json_load.return_value = {"name": project_name, "version": project_version}
result = get_node_analyze_dict("shouldnt/matter")
self.assertEqual(
len(result.get(get_node_id(project_name, project_version))), 1,
)


if __name__ == "__main__":
unittest.main()

0 comments on commit aa4bcfe

Please sign in to comment.