Skip to content

Commit e2be444

Browse files
test: extend TestRequirementsParser to check hashes (#368)
* Extend TestRequirementsParser.test_example_with_hashes() to check hashes Signed-off-by: Rodney Richardson <rodney.richardson@cambridgeconsultants.com> * Add additional test for hash. Signed-off-by: Rodney Richardson <rodney.richardson@cambridgeconsultants.com>
1 parent eecf04a commit e2be444

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

tests/test_parser_requirements.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
import os
2121
from unittest import TestCase
2222

23+
from cyclonedx.model import HashAlgorithm, HashType
24+
from cyclonedx.model.component import Component
25+
2326
from cyclonedx_py.parser.requirements import RequirementsFileParser, RequirementsParser
2427

2528

@@ -68,6 +71,11 @@ def test_example_multilines_with_comments(self) -> None:
6871

6972
self.assertFalse(parser.has_warnings(), f'{parser.get_warnings()}')
7073
self.assertEqual(1, len(components), f'{components}')
74+
component: Component = components[0]
75+
self.assertEqual(1, len(component.hashes))
76+
hash: HashType = component.hashes.pop()
77+
self.assertEqual(HashAlgorithm.SHA_256, hash.alg)
78+
self.assertNotEqual(0, len(hash.content), f'{hash.content}')
7179

7280
def test_example_local_packages(self) -> None:
7381
with open(os.path.join(os.path.dirname(__file__),
@@ -125,6 +133,14 @@ def test_example_with_hashes(self) -> None:
125133
self.assertFalse(parser.has_warnings(), f'{parser.get_warnings()}')
126134
self.assertEqual(5, len(components), f'{components}')
127135

136+
c_idna = next(filter(lambda c: c.name == 'idna', components), None)
137+
self.assertIsNotNone(c_idna)
138+
self.assertEqual('idna', c_idna.name)
139+
self.assertEqual(2, len(c_idna.hashes), f'{c_idna.hashes}')
140+
hash: HashType = c_idna.hashes.pop()
141+
self.assertEqual(HashAlgorithm.SHA_256, hash.alg)
142+
self.assertNotEqual(0, len(hash.content), f'{hash.content}')
143+
128144
def test_example_without_pinned_versions_warns(self) -> None:
129145
with open(os.path.join(os.path.dirname(__file__),
130146
'fixtures/requirements-without-pinned-versions.txt')) as r:

0 commit comments

Comments
 (0)