Skip to content

Commit 9a2cfe9

Browse files
committed
fix(build): test failure and dependency missing
Fixed failing tests due to dependency on now removed VERSION file Added flake8 officially as a DEV dependency to poetry Signed-off-by: Paul Horton <[email protected]>
1 parent f9119d4 commit 9a2cfe9

File tree

3 files changed

+68
-18
lines changed

3 files changed

+68
-18
lines changed

poetry.lock

Lines changed: 55 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ importlib-metadata = "^4.8.1"
4646
[tool.poetry.dev-dependencies]
4747
tox = "^3.24.3"
4848
coverage = "^5.5"
49+
flake8 = "^3.9.2"
4950

5051
[build-system]
5152
requires = ["poetry-core>=1.0.0"]

tests/test_e2e_environment.py

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,49 +18,44 @@
1818
# Copyright (c) OWASP Foundation. All Rights Reserved.
1919

2020
import json
21-
import os
2221
from unittest import TestCase
2322
from xml.etree import ElementTree
2423

24+
import pkg_resources
25+
2526
from cyclonedx.model.bom import Bom
2627
from cyclonedx.output import get_instance, OutputFormat
2728
from cyclonedx.output.json import Json
2829
from cyclonedx.output.xml import Xml
2930
from cyclonedx.parser.environment import EnvironmentParser
3031

32+
OUR_PACKAGE_NAME: str = 'cyclonedx-python-lib'
33+
OUR_PACKAGE_VERSION: str = pkg_resources.get_distribution(OUR_PACKAGE_NAME).version
3134

32-
class TestE2EEnvironment(TestCase):
33-
_our_package_version: str
34-
35-
@classmethod
36-
def setUpClass(cls) -> None:
37-
with open(os.path.join(os.path.realpath(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../')),
38-
'VERSION')) as _our_version:
39-
cls._our_package_version = _our_version.read()
4035

41-
_our_version.close()
36+
class TestE2EEnvironment(TestCase):
4237

4338
def test_json_defaults(self):
4439
outputter: Json = get_instance(bom=Bom.from_parser(EnvironmentParser()), output_format=OutputFormat.JSON)
4540
bom_json = json.loads(outputter.output_as_string())
4641
component_this_library = next(
4742
(x for x in bom_json['components'] if
48-
x['purl'] == 'pkg:pypi/cyclonedx-python-lib@{}'.format(TestE2EEnvironment._our_package_version)), None
43+
x['purl'] == 'pkg:pypi/{}@{}'.format(OUR_PACKAGE_NAME, OUR_PACKAGE_VERSION)), None
4944
)
5045

5146
self.assertTrue('author' in component_this_library.keys(), 'author is missing from JSON BOM')
5247
self.assertEqual(component_this_library['author'], 'Sonatype Community')
53-
self.assertEqual(component_this_library['name'], 'cyclonedx-python-lib')
54-
self.assertEqual(component_this_library['version'], TestE2EEnvironment._our_package_version)
48+
self.assertEqual(component_this_library['name'], OUR_PACKAGE_NAME)
49+
self.assertEqual(component_this_library['version'], OUR_PACKAGE_VERSION)
5550

5651
def test_xml_defaults(self):
5752
outputter: Xml = get_instance(bom=Bom.from_parser(EnvironmentParser()))
5853

5954
# Check we have cyclonedx-python-lib with Author, Name and Version
6055
bom_xml_e = ElementTree.fromstring(outputter.output_as_string())
6156
component_this_library = bom_xml_e.find('./{{{}}}components/{{{}}}component[@bom-ref=\'pkg:pypi/{}\']'.format(
62-
outputter.get_target_namespace(), outputter.get_target_namespace(), 'cyclonedx-python-lib@{}'.format(
63-
TestE2EEnvironment._our_package_version
57+
outputter.get_target_namespace(), outputter.get_target_namespace(), '{}@{}'.format(
58+
OUR_PACKAGE_NAME, OUR_PACKAGE_VERSION
6459
)
6560
))
6661

@@ -70,8 +65,8 @@ def test_xml_defaults(self):
7065

7166
name = component_this_library.find('./{{{}}}name'.format(outputter.get_target_namespace()))
7267
self.assertIsNotNone(name, 'No name element but one was expected.')
73-
self.assertEqual(name.text, 'cyclonedx-python-lib')
68+
self.assertEqual(name.text, OUR_PACKAGE_NAME)
7469

7570
version = component_this_library.find('./{{{}}}version'.format(outputter.get_target_namespace()))
7671
self.assertIsNotNone(version, 'No version element but one was expected.')
77-
self.assertEqual(version.text, TestE2EEnvironment._our_package_version)
72+
self.assertEqual(version.text, OUR_PACKAGE_VERSION)

0 commit comments

Comments
 (0)