File: test_hiermatch.py

package info (click to toggle)
reportbug 13.2.0
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,248 kB
  • sloc: python: 9,838; sh: 70; makefile: 41; lisp: 31
file content (46 lines) | stat: -rw-r--r-- 1,721 bytes parent folder | download | duplicates (2)
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
44
45
46
import unittest

from reportbug import hiermatch, exceptions

test_strings_list = ['Beautiful is better than ugly.',
                     'Explicit is better than implicit.',
                     'Simple is better than complex.',
                     'Complex is better than complicated.',
                     'Flat is better than nested.',
                     'Sparse is better than dense.']

test_hierarchy = [
    ('normal', ['had better work', 'makes funny noise']),
    ('serious', ['better listen to your children', 'please behave']),
    ('minor', ['oh, sorry', 'you can do better!']),
    ('wishlist', ['looks better than I thought', 'better is good']),
    ('critical', ['hehe', 'hoho']),
]


class TestHiermatch(unittest.TestCase):

    def test_egrep_list(self):
        res = hiermatch.egrep_list(None, '')
        self.assertIsNone(res)

        with self.assertRaises(exceptions.InvalidRegex):
            matches = hiermatch.egrep_list(test_strings_list, 42)

        matches = hiermatch.egrep_list(test_strings_list, 'better')
        self.assertEqual(len(matches), 6)
        self.assertEqual(matches, [0, 1, 2, 3, 4, 5])

    def test_egrep_hierarchy(self):
        res = hiermatch.egrep_hierarchy(test_hierarchy, 'better')
        self.assertEqual(res, [[0], [0], [1], [0, 1], []])

    def test_matched_hierarchy(self):
        res = hiermatch.matched_hierarchy(test_hierarchy, 'better')
        self.assertEqual(len(res), 4)
        self.assertEqual(res, [
            ('normal', ['had better work']),
            ('serious', ['better listen to your children']),
            ('minor', ['you can do better!']),
            ('wishlist', ['looks better than I thought', 'better is good']),
        ])