-
Notifications
You must be signed in to change notification settings - Fork 3
/
categorize_test.py
executable file
·43 lines (35 loc) · 1.51 KB
/
categorize_test.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
40
41
42
43
#!/usr/bin/env python3
"""Tests for categorize."""
import re
import unittest
import categorize
class CategorizeTest(unittest.TestCase):
version_re = re.compile(
r'[-_.]v?(\d+\.\d+\.\d+[a-z\d]*(-rc\d+)?)|(\d+\.\d+[a-z\d]*(-rc\d+)?)')
def test_samples(self):
with open('testdata/categorize_samples.txt', 'r') as samples:
for sample in samples:
(file, product, version, arch, os, packaging, installer, is_bin,
rest) = sample.strip().split('|')
with self.subTest(file=file):
m = self.version_re.search(file)
# Only use the default version if we can not find the common version
# pattern in the filename.
if m:
buckets = categorize.Categorize(file)
else:
buckets = categorize.Categorize(file,
default_version=version)
self.assertEqual(product, buckets.product, str(buckets))
self.assertEqual(version, buckets.version, str(buckets))
self.assertEqual(arch, str(buckets.arch), str(buckets))
self.assertEqual(os, str(buckets.os), str(buckets))
self.assertEqual(packaging, str(buckets.packaging), str(buckets))
self.assertEqual(installer, buckets.installer, str(buckets))
self.assertEqual(is_bin, str(buckets.is_bin), str(buckets))
self.assertEqual(
rest,
'{%s}%s' % (buckets.attributes, buckets.leftover),
str(buckets))
if __name__ == '__main__':
unittest.main()