Skip to content

Commit 0a39e86

Browse files
author
Michael Schlenker
committed
tests: tests for the code
Signed-off-by: Michael Schlenker <[email protected]>
1 parent 01c8854 commit 0a39e86

File tree

33 files changed

+1847
-0
lines changed

33 files changed

+1847
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
UTF16License.txt binary
2+
License.rtf binary
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
A simple license.
2+
Do what you want.
Binary file not shown.
Binary file not shown.
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# This file is part of CycloneDX Python
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
# SPDX-License-Identifier: Apache-2.0
16+
# Copyright (c) OWASP Foundation. All Rights Reserved.
17+
18+
"""
19+
initialize this testbed.
20+
"""
21+
22+
from os import name as os_name
23+
from os.path import dirname, join
24+
from subprocess import CompletedProcess, run # nosec:B404
25+
from sys import executable
26+
from venv import EnvBuilder
27+
28+
__all__ = ['main']
29+
30+
this_dir = dirname(__file__)
31+
env_dir = join(this_dir, '.venv')
32+
33+
34+
def pip_run(*args: str) -> CompletedProcess:
35+
# pip is not API, but a CLI -- call it like that!
36+
call = (
37+
executable, '-m', 'pip',
38+
'--python', env_dir,
39+
*args
40+
)
41+
print('+ ', *call)
42+
res = run(call, cwd=this_dir, shell=False) # nosec:B603
43+
if res.returncode != 0:
44+
raise RuntimeError('process failed')
45+
return res
46+
47+
48+
def pip_install(*args: str) -> None:
49+
pip_run(
50+
'install', '--require-virtualenv', '--no-input', '--progress-bar=off', '--no-color',
51+
*args
52+
)
53+
54+
55+
def main() -> None:
56+
EnvBuilder(
57+
system_site_packages=False,
58+
symlinks=os_name != 'nt',
59+
with_pip=False,
60+
).create(env_dir)
61+
62+
pip_install(dirname(__file__))
63+
64+
65+
if __name__ == '__main__':
66+
main()
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[build-system]
2+
# Known broken version
3+
requires = ["setuptools == 78.1.0"]
4+
build-backend = "setuptools.build_meta"
5+
6+
[project]
7+
name = "badlicdepends"
8+
version = "0.1"
9+
# UTF-16 is simply bad encoding
10+
# RTF is technically 7-bit ASCII, but has application/rtf mimetype.
11+
license-files = ["GoodLicense.txt", "License.rtf", "UTF16License.txt"]
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# This file is part of CycloneDX Python
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
# SPDX-License-Identifier: Apache-2.0
16+
# Copyright (c) OWASP Foundation. All Rights Reserved.
17+
18+
"""
19+
initialize this testbed.
20+
"""
21+
22+
from os import name as os_name
23+
from os.path import dirname, join
24+
from subprocess import CompletedProcess, run # nosec:B404
25+
from sys import executable
26+
from venv import EnvBuilder
27+
28+
__all__ = ['main']
29+
30+
this_dir = dirname(__file__)
31+
env_dir = join(this_dir, '.venv')
32+
33+
34+
def pip_run(*args: str) -> CompletedProcess:
35+
# pip is not API, but a CLI -- call it like that!
36+
call = (
37+
executable, '-m', 'pip',
38+
'--python', env_dir,
39+
*args
40+
)
41+
print('+ ', *call)
42+
res = run(call, cwd=this_dir, shell=False) # nosec:B603
43+
if res.returncode != 0:
44+
raise RuntimeError('process failed')
45+
return res
46+
47+
48+
def pip_install(*args: str) -> None:
49+
pip_run(
50+
'install', '--require-virtualenv', '--no-input', '--progress-bar=off', '--no-color',
51+
*args
52+
)
53+
54+
55+
def main() -> None:
56+
EnvBuilder(
57+
system_site_packages=False,
58+
symlinks=os_name != 'nt',
59+
with_pip=False,
60+
).create(env_dir)
61+
pip_install(join(dirname(__file__), 'badlicdepends'))
62+
pip_install(dirname(__file__))
63+
64+
65+
if __name__ == '__main__':
66+
main()
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[build-system]
2+
# Known broken version
3+
requires = ["setuptools == 78.1.0"]
4+
build-backend = "setuptools.build_meta"
5+
6+
[project]
7+
name = "badlic"
8+
version = "0.1"
9+
dependencies = ["badlicdepends"]

tests/_data/snapshots/environment/badlic-texts_with-license-bad-file-recoverable_1.0.xml.bin

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/_data/snapshots/environment/badlic-texts_with-license-bad-file-recoverable_1.1.xml.bin

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)