|
1 | | -import platform |
2 | 1 | import time |
3 | 2 | from unittest import TestCase |
4 | 3 |
|
5 | 4 | from mistune import create_markdown |
6 | 5 |
|
7 | | -IS_PYPY = platform.python_implementation() == "PyPy" |
8 | | -DEADLINE = 1.0 if IS_PYPY else 0.5 |
| 6 | +DEADLINE = 1.0 |
9 | 7 |
|
10 | 8 |
|
11 | 9 | class TestInlineParserSecurity(TestCase): |
@@ -119,32 +117,30 @@ def test_repeated_link_suffixes_are_near_linear(self): |
119 | 117 |
|
120 | 118 | def render(size): |
121 | 119 | text = "[" * size + "a" + "](/u)" * size + "\n" |
122 | | - start = time.process_time() |
| 120 | + start = time.perf_counter() |
123 | 121 | md(text) |
124 | | - return time.process_time() - start |
| 122 | + return time.perf_counter() - start |
125 | 123 |
|
126 | 124 | render(200) |
127 | 125 | small = render(1000) |
128 | 126 | large = render(2000) |
129 | 127 |
|
130 | | - self.assertLess(large, DEADLINE) |
131 | | - self.assertLess(large, small * 3) |
| 128 | + self.assertLess(large, small * 3.5 + 0.02) |
132 | 129 |
|
133 | 130 | def test_repeated_unclosed_inline_spoilers_are_near_linear(self): |
134 | 131 | md = create_markdown(plugins=["spoiler"]) |
135 | 132 |
|
136 | 133 | def render(size): |
137 | 134 | text = ">! a " * size + "\n" |
138 | | - start = time.process_time() |
| 135 | + start = time.perf_counter() |
139 | 136 | md(text) |
140 | | - return time.process_time() - start |
| 137 | + return time.perf_counter() - start |
141 | 138 |
|
142 | 139 | render(200) |
143 | 140 | small = render(1000) |
144 | 141 | large = render(2000) |
145 | 142 |
|
146 | | - self.assertLess(large, DEADLINE) |
147 | | - self.assertLess(large, small * 3) |
| 143 | + self.assertLess(large, small * 3.5 + 0.02) |
148 | 144 |
|
149 | 145 | def test_adjacent_ruby_tokens_do_not_recurse_forever(self): |
150 | 146 | text = "[a(b)]" * 3000 + "\n" |
|
0 commit comments