~mapperr/trl

ref: f9a6cd5ee6afd98e66b2adee799ee8be0ae18b11 trl/tests/unit/test_shortener.py -rw-r--r-- 4.1 KiB
f9a6cd5e — mapperr Refactor and tests 2 years ago
                                                                                
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import unittest
from typing import List
from unittest import mock
from unittest.mock import Mock

from trullo.shortcuttable import Shortcuttable
from trullo.shortener import Shortener
from trullo.trl_board import TrlBoard
from trullo.trl_card import TrlCard
from trullo.trl_list import TrlList


class TestShortener(unittest.TestCase):
    def test_matches(self):
        sh = Shortener
        start_match = sh.is_a_match('pil', 'pillow')
        self.assertTrue(start_match)
        middle_match = sh.is_a_match('grat', 'integration')
        self.assertTrue(middle_match)
        end_match = sh.is_a_match('ver', 'forever')
        self.assertTrue(end_match)

    def test_wrong_matches(self):
        sh = Shortener
        match = sh.is_a_match('spil', 'pillow')
        self.assertFalse(match)

    def test_matches_in_list(self):
        short1: Shortcuttable = \
            mock.create_autospec(Shortcuttable, spec_set=True)
        short1.get_normalized_name = Mock(return_value='qwerty')
        short2: Shortcuttable = \
            mock.create_autospec(Shortcuttable, spec_set=True)
        short2.get_normalized_name = Mock(return_value='asdfgh')
        short3: Shortcuttable = \
            mock.create_autospec(Shortcuttable, spec_set=True)
        short3.get_normalized_name = Mock(return_value='qwertyasdfgh')
        short4: Shortcuttable = \
            mock.create_autospec(Shortcuttable, spec_set=True)
        short4.get_normalized_name = Mock(return_value='')

        sh = Shortener
        shorties = [short1, short2]
        matches: List = sh.get_matches('er', shorties)
        self.assertEqual(1, len(matches))
        matches: List = sh.get_matches('df', shorties)
        self.assertEqual(1, len(matches))
        matches: List = sh.get_matches('mn', shorties)
        self.assertEqual(0, len(matches))
        matches: List = sh.get_matches('rty', shorties + [short3])
        self.assertEqual(2, len(matches))
        matches: List = sh.get_matches('er', shorties + [short4])
        self.assertEqual(1, len(matches))

    def test_normalization(self):
        card1 = TrlCard('idc1', shortLink := 'qWeRt1',
                        {'name': 'Design the project in 2 days',
                         'shortLink': shortLink})
        card2 = TrlCard('idc2', shortLink := 'AsD3gH',
                        {'name': 'Produce a non-techical doc, clear and easy',
                         'shortLink': shortLink})
        card3 = TrlCard('idc3', shortLink := 'zXcvb7',
                        {'name': ' Implement a trim() function',
                         'shortLink': shortLink})
        list1 = TrlList('idl1', {'name': 'To Do'})
        board1 = TrlBoard('idb1', shortLink := 'p01UyT', [list1],
                          [card1, card2, card3],
                          {'name': 'my Super Board',
                           'shortLink': shortLink})

        card1_n = card1.get_normalized_name()
        self.assertNotIn('D', card1_n)
        self.assertNotIn(' ', card1_n)
        self.assertIn('2', card1_n)
        self.assertIn('project', card1_n)
        self.assertIn('design', card1_n)
        self.assertIn('days', card1_n)

        card2_n = card2.get_normalized_name()
        self.assertNotIn('P', card2_n)
        self.assertNotIn(' ', card2_n)
        self.assertNotIn('-', card2_n)
        self.assertNotIn(',', card2_n)
        self.assertIn('nontech', card2_n)
        self.assertIn('docclear', card2_n)
        self.assertIn('produce', card2_n)

        card3_n = card3.get_normalized_name()
        self.assertNotIn('I', card3_n)
        self.assertNotIn(' ', card2_n)
        self.assertNotIn(' impl', card3_n)
        self.assertNotIn('(', card3_n)
        self.assertIn('trimfunc', card3_n)

        list1_n = list1.get_normalized_name()
        self.assertNotIn('T', list1_n)
        self.assertNotIn(' ', list1_n)
        self.assertIn('idl1', list1_n)
        self.assertIn('todo', list1_n)

        board1_n = board1.get_normalized_name()
        self.assertNotIn(' ', board1_n)
        self.assertNotIn('U', board1_n)
        self.assertIn('mysuper', board1_n)
        self.assertIn('p01u', board1_n)