forked from zync/zync-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
analytics_unittests.py
150 lines (101 loc) · 4.48 KB
/
analytics_unittests.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
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/usr/bin/env python
# """Unittests for analytics.py"""
import unittest
import analytics
class TestAnalytics(unittest.TestCase):
def test_format_error_should_shorten_stack_traces(self):
error = """Traceback (most recent call last):
File "/usr/local/zync/analytics.py", line 154, in main
test_exception()
File "/usr/local/zync/analytics.py", line 140, in test_exception
raise Exception('test error2')
Exception: test error2
"""
result = analytics.format_error(error)
expected = """/u/l/z/analytics.py:154, in main
test_exception()
/u/l/z/analytics.py:140, in test_exception
raise Exception('test error2')
Exception: test error2"""
self.assertEqual(expected, result)
def test_format_error_should_cut_least_important_part_of_stack_trace(self):
error = """Traceback (most recent call last):
File "/usr/local/zync/analytics.py", line 154, in main
test_exception()
File "/usr/local/zync/analytics.py", line 140, in test_exception
raise Exception('test error2')
Exception: test error2
"""
result = analytics.format_error(error, limit=100)
expected = """/u/l/z/analytics.py:140, in test_exception
raise Exception('test error2')
Exception: test error2"""
self.assertEqual(expected, result)
def test_format_error_should_shorten_paths_with_spaces(self):
error = """File "c:\\Programs and Files\\Secret App\\app.py", line 140, in test_exception
raise Exception('test error2')
Exception: Invalid "c:\\Programs and Files\\Secret App\\secret texture.tx"
"""
result = analytics.format_error(error)
expected = '''c:/P/S/app.py:140, in test_exception
raise Exception('test error2')
Exception: Invalid "c:/P/S/s.tx"'''
self.assertEqual(expected, result)
def test_format_error_should_truncate_error(self):
error = "A long error message"
result = analytics.format_error(error, limit=12)
expected = "A long error"
self.assertEqual(expected, result)
def test_format_error_should_mask_filename(self):
error = "File /home/file.txt does not exist."
result = analytics.format_error(error)
expected = "File /h/f.txt does not exist."
self.assertEqual(expected, result)
def test_format_error_should_shorten_linux_absolute_paths(self):
error = "File /home/secret_user_name/file.txt does not exist."
result = analytics.format_error(error)
expected = "File /h/s/f.txt does not exist."
self.assertEqual(expected, result)
def test_format_error_should_shorten_windows_absolute_paths(self):
error = "File c:\\users\\secret_user_name\\file.txt does not exist."
result = analytics.format_error(error)
expected = "File c:/u/s/f.txt does not exist."
self.assertEqual(expected, result)
def test_format_error_should_shorten_path_with_spaces(self):
error = "File c:\\Program Files\\secret_user_name\\file.txt does not exist."
result = analytics.format_error(error)
expected = "File c:/P F/s/f.txt does not exist."
self.assertEqual(expected, result)
def test_format_error_should_shorten_two_part_linux_absolute_paths(self):
error = "File /home/file.txt does not exist."
result = analytics.format_error(error)
expected = "File /h/f.txt does not exist."
self.assertEqual(expected, result)
def test_format_error_should_shorten_short_windows_absolute_paths(self):
error = "File c:\\users\\file.txt does not exist."
result = analytics.format_error(error)
expected = "File c:/u/f.txt does not exist."
self.assertEqual(expected, result)
def test_format_error_should_shorten_linux_relative_paths(self):
error = "File home/secret_user_name/file.txt does not exist."
result = analytics.format_error(error)
expected = "File h/s/f.txt does not exist."
self.assertEqual(expected, result)
def test_format_error_should_shorten_windows_relative_paths(self):
error = "File users\\secret_user_name\\file.txt does not exist."
result = analytics.format_error(error)
expected = "File u/s/f.txt does not exist."
self.assertEqual(expected, result)
def test_format_error_should_not_shorten_single_slashes(self):
error = "App maya\\2018 c4d/21"
result = analytics.format_error(error)
self.assertEqual(error, result)
def test_format_error_should_mask_emails(self):
error = "User [email protected] does not exist."
result = analytics.format_error(error)
expected = "User <email> does not exist."
self.assertEqual(expected, result)
def main():
unittest.main()
if __name__ == '__main__':
main()