Skip to content

Commit aee6583

Browse files
committed
feat: SP-1801 Add unit tests to workflow file
1 parent 70665f2 commit aee6583

File tree

11 files changed

+285
-214
lines changed

11 files changed

+285
-214
lines changed

.github/workflows/python-local-test.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ jobs:
2929
python -m pip install --upgrade pip
3030
pip install -r requirements-dev.txt
3131
32+
- name: Run Unit Tests
33+
run: |
34+
python -m unittest
35+
3236
- name: Build Local Package
3337
run: make dist
3438

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,6 @@ bad*.txt
2323
*.gz
2424
*.zip
2525
local-*.txt
26-
docs/build
26+
docs/build
27+
28+
!tests/data/*.json

tests/__init__.py

Whitespace-only changes.

tests/data/scanoss.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"bom": {
3+
"include": [],
4+
"remove": [
5+
{
6+
"path": "scanoss_settings.py",
7+
"purl": "pkg:github/scanoss/scanoss.py"
8+
},
9+
{
10+
"path": "test_file_path.go",
11+
"purl": "pkg:github/scanoss/scanoss.py"
12+
},
13+
{
14+
"purl": "matching/purl"
15+
}
16+
],
17+
"replace": [
18+
{
19+
"path": "full_match_test.py",
20+
"purl": "pkg:github/scanoss/full_match_test.py",
21+
"replace_with": "pkg:github/scanoss/full_match_replaced.py"
22+
},
23+
{
24+
"purl": "pkg:github/scanoss/only_purl_match.py",
25+
"replace_with": "pkg:github/scanoss/only_purl_match_replaced.py"
26+
}
27+
]
28+
}
29+
}
30+

tests/grpc-client-test.py

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
"""
2-
SPDX-License-Identifier: MIT
2+
SPDX-License-Identifier: MIT
33
4-
Copyright (c) 2021, SCANOSS
4+
Copyright (c) 2021, SCANOSS
55
6-
Permission is hereby granted, free of charge, to any person obtaining a copy
7-
of this software and associated documentation files (the "Software"), to deal
8-
in the Software without restriction, including without limitation the rights
9-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10-
copies of the Software, and to permit persons to whom the Software is
11-
furnished to do so, subject to the following conditions:
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
1212
13-
The above copyright notice and this permission notice shall be included in
14-
all copies or substantial portions of the Software.
13+
The above copyright notice and this permission notice shall be included in
14+
all copies or substantial portions of the Software.
1515
16-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22-
THE SOFTWARE.
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
THE SOFTWARE.
2323
"""
24+
2425
import os
2526
import unittest
2627

@@ -32,17 +33,18 @@ class MyTestCase(unittest.TestCase):
3233
"""
3334
Unit test cases for GRPC comms
3435
"""
35-
TEST_LOCAL = os.getenv("SCANOSS_TEST_LOCAL", 'True').lower() in ('true', '1', 't', 'yes', 'y')
36+
37+
TEST_LOCAL = os.getenv('SCANOSS_TEST_LOCAL', 'True').lower() in ('true', '1', 't', 'yes', 'y')
3638

3739
def test_grpc_dep_echo(self):
3840
"""
3941
Test the basic echo rpc call on the local server
4042
"""
4143
if MyTestCase.TEST_LOCAL:
42-
server_type = "local"
44+
server_type = 'local'
4345
grpc_client = ScanossGrpc(debug=True, url='localhost:50051')
4446
else:
45-
server_type = "remote"
47+
server_type = 'remote'
4648
grpc_client = ScanossGrpc(debug=True)
4749
echo_resp = grpc_client.deps_echo(f'testing dep echo ({server_type})')
4850
print(f'Echo Resp ({server_type}): {echo_resp}')
@@ -53,23 +55,26 @@ def test_grpc_get_dependencies(self):
5355
Test getting dependencies from the local gRPC server
5456
"""
5557
sc_deps = ScancodeDeps(debug=True)
56-
dep_file = "data/scancode-deps.json"
58+
dep_file = 'data/scancode-deps.json'
5759
deps = sc_deps.produce_from_file(dep_file)
5860
print(f'Dependency JSON: {deps}')
5961
self.assertIsNotNone(deps)
6062
if MyTestCase.TEST_LOCAL:
61-
server_type = "local"
63+
server_type = 'local'
6264
grpc_client = ScanossGrpc(debug=True, url='localhost:50051')
6365
else:
64-
server_type = "remote"
66+
server_type = 'remote'
6567
grpc_client = ScanossGrpc(debug=True)
6668
resp = grpc_client.get_dependencies(deps)
6769
print(f'Resp ({server_type}): {resp}')
6870
self.assertIsNotNone(resp)
6971

70-
dep_files = resp.get("files")
72+
dep_files = resp.get('files')
7173
if dep_files and len(dep_files) > 0:
7274
for dep_file in dep_files:
73-
file = dep_file.pop("file", None)
75+
file = dep_file.pop('file', None)
7476
print(f'File: {file} - {dep_file}')
7577

78+
79+
if __name__ == '__main__':
80+
unittest.main()

0 commit comments

Comments
 (0)