-
Notifications
You must be signed in to change notification settings - Fork 83
/
tests.py
39 lines (29 loc) · 1.08 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import json
import unittest
from packaging.specifiers import InvalidSpecifier, SpecifierSet
from parameterized import parameterized
from safety_db import INSECURE, INSECURE_FULL
def generatePackageSpecifiers():
with open("data/insecure.json") as f:
database = json.loads(f.read())
for pkg, all_specs in database.items():
for spec in all_specs:
if pkg == '$meta':
continue
else:
yield pkg, spec
class TestData(unittest.TestCase):
@parameterized.expand(generatePackageSpecifiers)
def test_using_valid_specifier_sets(self, pkg, spec):
message = f"Bad specifier for {pkg}: {spec!r}"
try:
specifier_set = SpecifierSet(spec)
except InvalidSpecifier:
specifier_set = None
self.failUnless(specifier_set, msg=message)
self.assertIsInstance(specifier_set, SpecifierSet, message)
def test_main_module(self):
self.assertTrue(len(INSECURE) > 0)
self.assertTrue(len(INSECURE_FULL) > 0)
if __name__ == '__main__':
unittest.main()