|
1 | 1 | import re |
2 | | -from typing import Optional, Union |
| 2 | +from copy import deepcopy |
| 3 | +from typing import Dict, Optional, Union |
3 | 4 |
|
4 | 5 | import pytest |
5 | 6 | from dirty_equals import HasRepr, IsInstance |
@@ -1140,3 +1141,75 @@ def test_url_vulnerabilities(url_validator, url, expected): |
1140 | 1141 | else: |
1141 | 1142 | output_parts[key] = getattr(output_url, key) |
1142 | 1143 | assert output_parts == expected |
| 1144 | + |
| 1145 | + |
| 1146 | +def test_multi_host_url_comparison() -> None: |
| 1147 | + assert MultiHostUrl('http://example.com,www.example.com') == MultiHostUrl('http://example.com,www.example.com') |
| 1148 | + assert MultiHostUrl('http://example.com,www.example.com') == MultiHostUrl('http://example.com,www.example.com/') |
| 1149 | + assert MultiHostUrl('http://example.com,www.example.com') != MultiHostUrl('http://example.com,www.example.com/123') |
| 1150 | + assert MultiHostUrl('http://example.com,www.example.com/123') > MultiHostUrl('http://example.com,www.example.com') |
| 1151 | + assert MultiHostUrl('http://example.com,www.example.com/123') >= MultiHostUrl('http://example.com,www.example.com') |
| 1152 | + assert MultiHostUrl('http://example.com,www.example.com') >= MultiHostUrl('http://example.com,www.example.com') |
| 1153 | + assert MultiHostUrl('http://example.com,www.example.com') < MultiHostUrl('http://example.com,www.example.com/123') |
| 1154 | + assert MultiHostUrl('http://example.com,www.example.com') <= MultiHostUrl('http://example.com,www.example.com/123') |
| 1155 | + assert MultiHostUrl('http://example.com,www.example.com') <= MultiHostUrl('http://example.com') |
| 1156 | + |
| 1157 | + |
| 1158 | +def test_multi_host_url_bool() -> None: |
| 1159 | + assert bool(MultiHostUrl('http://example.com,www.example.com')) is True |
| 1160 | + |
| 1161 | + |
| 1162 | +def test_multi_host_url_hash() -> None: |
| 1163 | + data: Dict[MultiHostUrl, int] = {} |
| 1164 | + |
| 1165 | + data[MultiHostUrl('http://example.com,www.example.com')] = 1 |
| 1166 | + assert data == {MultiHostUrl('http://example.com,www.example.com/'): 1} |
| 1167 | + |
| 1168 | + data[MultiHostUrl('http://example.com,www.example.com/123')] = 2 |
| 1169 | + assert data == { |
| 1170 | + MultiHostUrl('http://example.com,www.example.com/'): 1, |
| 1171 | + MultiHostUrl('http://example.com,www.example.com/123'): 2, |
| 1172 | + } |
| 1173 | + |
| 1174 | + data[MultiHostUrl('http://example.com,www.example.com')] = 3 |
| 1175 | + assert data == { |
| 1176 | + MultiHostUrl('http://example.com,www.example.com/'): 3, |
| 1177 | + MultiHostUrl('http://example.com,www.example.com/123'): 2, |
| 1178 | + } |
| 1179 | + |
| 1180 | + |
| 1181 | +def test_multi_host_url_deepcopy() -> None: |
| 1182 | + assert deepcopy(MultiHostUrl('http://example.com')) == MultiHostUrl('http://example.com/') |
| 1183 | + |
| 1184 | + |
| 1185 | +def test_url_comparison() -> None: |
| 1186 | + assert Url('http://example.com') == Url('http://example.com') |
| 1187 | + assert Url('http://example.com') == Url('http://example.com/') |
| 1188 | + assert Url('http://example.com') != Url('http://example.com/123') |
| 1189 | + assert Url('http://example.com/123') > Url('http://example.com') |
| 1190 | + assert Url('http://example.com/123') >= Url('http://example.com') |
| 1191 | + assert Url('http://example.com') >= Url('http://example.com') |
| 1192 | + assert Url('http://example.com') < Url('http://example.com/123') |
| 1193 | + assert Url('http://example.com') <= Url('http://example.com/123') |
| 1194 | + assert Url('http://example.com') <= Url('http://example.com') |
| 1195 | + |
| 1196 | + |
| 1197 | +def test_url_bool() -> None: |
| 1198 | + assert bool(Url('http://example.com')) is True |
| 1199 | + |
| 1200 | + |
| 1201 | +def test_url_hash() -> None: |
| 1202 | + data: Dict[Url, int] = {} |
| 1203 | + |
| 1204 | + data[Url('http://example.com')] = 1 |
| 1205 | + assert data == {Url('http://example.com/'): 1} |
| 1206 | + |
| 1207 | + data[Url('http://example.com/123')] = 2 |
| 1208 | + assert data == {Url('http://example.com/'): 1, Url('http://example.com/123'): 2} |
| 1209 | + |
| 1210 | + data[Url('http://example.com')] = 3 |
| 1211 | + assert data == {Url('http://example.com/'): 3, Url('http://example.com/123'): 2} |
| 1212 | + |
| 1213 | + |
| 1214 | +def test_url_deepcopy() -> None: |
| 1215 | + assert deepcopy(Url('http://example.com')) == Url('http://example.com/') |
0 commit comments