Coverage for tests / eclipse / care / legal / test_recommended_files.py: 96%
82 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-03-24 09:38 +0100
« prev ^ index » next coverage.py v7.13.5, created at 2026-03-24 09:38 +0100
1# Copyright (c) 2025 The Eclipse Foundation
2#
3# This program and the accompanying materials are made available under the
4# terms of the Eclipse Public License 2.0 which is available at
5# http://www.eclipse.org/legal/epl-2.0.
6#
7# SPDX-License-Identifier: EPL-2.0
9from pprint import pprint
10import configparser
12import care.legal.recommended_files as rf
14test_org = 'eclipse-dash'
15test_repo_gh = 'eclipse-dash/dash-licenses'
16test_group = 'eclipse/technology/dash'
17test_repo_gl = test_group + '/documentation-util'
19file_conf = 'eclipse_conf.ini'
21def setup_credentials():
22 # Read .ini config file.
23 parser = configparser.ConfigParser(interpolation=None)
24 try:
25 with open(file_conf, "r") as f:
26 data = f.read()
27 parser.read_string(data)
28 except Exception as e:
29 print("Error reading " + file_conf + " file:" + str(e) + ".")
30 exit()
32 # Get the GH token from the config file.
33 section = parser["GitHub"]
34 gh_token = section["gh_token"]
36 # Get the GL token from the config file.
37 section = parser["GitLab"]
38 gl_token = section["gl_token"]
40 creds = {"GH_TOKEN": gh_token, "GL_TOKEN": gl_token}
41 return creds
44def test_find_file_in_list():
45 file_found = rf.find_file_in_list(
46 files_repo = ["one", "two", "three"],
47 files_lookup = ["one", "six"]
48 )
49 assert file_found == "one"
51 file_found = rf.find_file_in_list(
52 files_repo = ["one.txt", "tWO", "three"],
53 files_lookup = [r".ne"]
54 )
55 pprint(file_found)
56 assert file_found == "one.txt"
58 file_found = rf.find_file_in_list(
59 files_repo = ["one.txt", "tWO", "three"],
60 files_lookup = ["two"]
61 )
62 pprint(file_found)
63 assert file_found == "tWO"
66def test_gh_analyse():
67 creds = setup_credentials()
68 repo_files = rf.gh_analyse(organisation=test_org, credentials=creds)
69 pprint(repo_files)
70 assert test_repo_gh in repo_files
71 assert 'conduct' in repo_files[test_repo_gh]
72 assert repo_files[test_repo_gh]['conduct'] == "CODE_OF_CONDUCT.md"
73 assert 'contributing' in repo_files[test_repo_gh]
74 assert repo_files[test_repo_gh]['contributing'] == "CONTRIBUTING.md"
75 assert 'license' in repo_files[test_repo_gh]
76 assert repo_files[test_repo_gh]['license'] == "LICENSE"
77 assert 'readme' in repo_files[test_repo_gh]
78 assert repo_files[test_repo_gh]['readme'] == "README.md"
81def test_gh_analyse_nok():
82 creds = setup_credentials()
83 repo_files = rf.gh_analyse(organisation="nonexistent", credentials=creds)
84 pprint(repo_files)
85 assert repo_files is None
88def test_gl_analyse():
89 creds = setup_credentials()
90 repo_files = rf.gl_analyse(organisation=test_group, credentials=creds)
91 pprint(repo_files)
92 assert test_repo_gl in repo_files
93 assert 'conduct' in repo_files[test_repo_gl]
94 assert repo_files[test_repo_gl]['conduct'] == "CODE_OF_CONDUCT.md"
95 assert 'contributing' in repo_files[test_repo_gl]
96 assert repo_files[test_repo_gl]['contributing'] == "CONTRIBUTING.md"
97 assert 'license' in repo_files[test_repo_gl]
98 assert repo_files[test_repo_gl]['license'] == "LICENSE"
99 assert 'readme' in repo_files[test_repo_gl]
100 assert repo_files[test_repo_gl]['readme'] is None
103def test_gl_analyse_nok():
104 creds = setup_credentials()
105 repo_files = rf.gl_analyse(organisation="nonexistent", credentials=creds)
106 pprint(repo_files)
107 assert repo_files is None
110def test_analyse_project():
111 creds = setup_credentials()
112 out = rf.analyse_project(project_id='technology.dash', credentials=creds)
113 pprint(out)
114 assert 'eclipse-dash/.github' in out
115 assert out['eclipse-dash/.github']['license'] is None
116 assert out['eclipse-dash/.github']['readme'] == "README.md"
117 assert 'eclipse-dash/dash-licenses' in out
118 assert len(out['eclipse-dash/nodejs-wrapper']) == 4
121def test_analyse_project_nok():
122 creds = setup_credentials()
123 out = rf.analyse_project(project_id='technology.nonexistent', credentials=creds)
124 pprint(out)
125 assert out is None