-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathtest_diff.py
More file actions
99 lines (82 loc) · 4.19 KB
/
test_diff.py
File metadata and controls
99 lines (82 loc) · 4.19 KB
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
import os
import unittest
from pathlib import Path
from mod_test.nicediff.diff import get_html_diff
from tests.base import load_file_lines
STATIC_MOCK_DIR = os.path.join(Path(__file__).parents[1], 'static_mock_files')
EXPECTED_RESULT_FILE = os.path.join(STATIC_MOCK_DIR, 'expected.txt')
OBTAINED_RESULT_FILE = os.path.join(STATIC_MOCK_DIR, 'obtained.txt')
class TestDiff(unittest.TestCase):
"""Test diff-related features."""
def test_if_same_diff_generated(self):
"""Test the diff generation."""
expected_sub = ['1\n', '00:00:12,340 --> 00:00:15,356\n', 'May the fourth be with you!\n']
obtained_sub = ['1\n', '00:00:12,300 --> 00:00:15,356\n', 'May the twenty fourth be with you!\n']
expected_diff = """
<table>
<tr>
<td class="diff-table-td" style="width: 30px;">n°</td>
<td class="diff-table-td">Result</td>
</tr>
<tr>
<td class="diff-table-td" style="width: 30px;"></td>
<td class="diff-table-td">Expected</td>
</tr>
</table>
<table>
<tr>
<td class="diff-table-td" style="width: 30px;">2</td>
<td class="diff-table-td"><div class="diff-div-text"><div class="diff-same-region" id="1_diff_same_test_result_1">00:00:12,</div>300<div class="diff-same-region" id="0_diff_same_test_result_1"> --> 00:00:15,356
</div></div></td>
</tr>
<tr>
<td class="diff-table-td" style="width: 30px;"></td>
<td class="diff-table-td"><div class="diff-div-text"><div class="diff-same-region" id="1_diff_same_correct_1">00:00:12,</div>340<div class="diff-same-region" id="0_diff_same_correct_1"> --> 00:00:15,356
</div></div></td>
</tr>
</table>
<table>
<tr>
<td class="diff-table-td" style="width: 30px;">3</td>
<td class="diff-table-td"><div class="diff-div-text"><div class="diff-same-region" id="1_diff_same_test_result_2">May the</div> twenty<div class="diff-same-region" id="0_diff_same_test_result_2"> fourth be with you!
</div></div></td>
</tr>
<tr>
<td class="diff-table-td" style="width: 30px;"></td>
<td class="diff-table-td"><div class="diff-div-text"><div class="diff-same-region" id="1_diff_same_correct_2">May the</div><div class="diff-same-region" id="0_diff_same_correct_2"> fourth be with you!
</div></div></td>
</tr>
</table>"""
obtained_diff = get_html_diff(expected_sub, obtained_sub)
self.assertEqual(expected_diff, obtained_diff)
def test_if_view_limit_respected(self):
"""Test that in view only first 50 diffs are sent."""
expected_tr_count = 102 # 2 table rows for each diff along with 2 table rows for headings
obtained = load_file_lines(OBTAINED_RESULT_FILE)
expected = load_file_lines(EXPECTED_RESULT_FILE)
obtained_diff = get_html_diff(expected, obtained, to_view=True)
obtained_tr_count = obtained_diff.count("</tr>")
self.assertEqual(expected_tr_count, obtained_tr_count)
def test_if_full_diff_download(self):
"""Test that in download mode all diff is sent."""
limit_tr_count = 102 # 2 table rows for each diff along with 2 table rows for headings
obtained = load_file_lines(OBTAINED_RESULT_FILE)
expected = load_file_lines(EXPECTED_RESULT_FILE)
obtained_diff = get_html_diff(expected, obtained, to_view=False)
obtained_tr_count = obtained_diff.count("</tr>")
self.assertGreater(obtained_tr_count, limit_tr_count)
def test_cascade_failure_missing_entry(self):
"""Test cascade-failure when subtitle entries are missing."""
expected_sub = [
'1\n', '00:00:01,000 --> 00:00:02,000\n', 'First line\n',
'2\n', '00:00:03,000 --> 00:00:04,000\n', 'Second line\n'
]
obtained_sub = [
'1\n', '00:00:01,000 --> 00:00:02,000\n', 'First line\n',
'3\n', '00:00:05,000 --> 00:00:06,000\n', 'Third line\n'
]
diff_html = get_html_diff(expected_sub, obtained_sub)
self.assertIn('Third', diff_html)
self.assertIn('Second', diff_html)
self.assertIn('05', diff_html)
self.assertIn('03', diff_html)