| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 1 # This file is part of Adblock Plus <https://adblockplus.org/>, | 1 # This file is part of Adblock Plus <https://adblockplus.org/>, |
| 2 # Copyright (C) 2006-2017 eyeo GmbH | 2 # Copyright (C) 2006-present eyeo GmbH |
| 3 # | 3 # |
| 4 # Adblock Plus is free software: you can redistribute it and/or modify | 4 # Adblock Plus is free software: you can redistribute it and/or modify |
| 5 # it under the terms of the GNU General Public License version 3 as | 5 # it under the terms of the GNU General Public License version 3 as |
| 6 # published by the Free Software Foundation. | 6 # published by the Free Software Foundation. |
| 7 # | 7 # |
| 8 # Adblock Plus is distributed in the hope that it will be useful, | 8 # Adblock Plus is distributed in the hope that it will be useful, |
| 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of | 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 # GNU General Public License for more details. | 11 # GNU General Public License for more details. |
| 12 # | 12 # |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 103 }.items()) | 103 }.items()) |
| 104 def test_parse_filters(filter_text, expected): | 104 def test_parse_filters(filter_text, expected): |
| 105 """Parametric test for filter parsing""" | 105 """Parametric test for filter parsing""" |
| 106 parsed = parse_line(filter_text) | 106 parsed = parse_line(filter_text) |
| 107 assert parsed.type == 'filter' | 107 assert parsed.type == 'filter' |
| 108 assert parsed.text == filter_text | 108 assert parsed.text == filter_text |
| 109 for attribute, expected_value in expected.items(): | 109 for attribute, expected_value in expected.items(): |
| 110 assert getattr(parsed, attribute) == expected_value | 110 assert getattr(parsed, attribute) == expected_value |
| 111 | 111 |
| 112 | 112 |
| 113 def test_parse_bad_option(): | |
|
Vasily Kuznetsov
2017/07/28 18:57:49
Now we can also detect unknown options. Yaaay!
Vasily Kuznetsov
2017/08/02 16:21:17
I remove this test since we've agreed to remove th
| |
| 114 with pytest.raises(ParseError): | |
| 115 parse_line('foo.com$script,foo') | |
| 116 with pytest.raises(ParseError): | |
| 117 parse_line('foo.com$~foo') | |
| 118 | |
| 119 | |
| 120 def test_parse_comment(): | 113 def test_parse_comment(): |
| 121 line = parse_line('! Block foo') | 114 line = parse_line('! Block foo') |
| 122 assert line.type == 'comment' | 115 assert line.type == 'comment' |
| 123 assert line.text == 'Block foo' | 116 assert line.text == 'Block foo' |
| 124 | 117 |
| 125 | 118 |
| 126 def test_parse_meta(): | 119 def test_parse_meta(): |
| 127 line = parse_line('! Homepage : http://aaa.com/b') | 120 line = parse_line('! Homepage : http://aaa.com/b') |
| 128 assert line.type == 'metadata' | 121 assert line.type == 'metadata' |
| 129 assert line.key == 'Homepage' | 122 assert line.key == 'Homepage' |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 160 def test_parse_filterlist(): | 153 def test_parse_filterlist(): |
| 161 result = parse_filterlist(['! foo', '! Title: bar']) | 154 result = parse_filterlist(['! foo', '! Title: bar']) |
| 162 assert list(result) == [Comment('foo'), Metadata('Title', 'bar')] | 155 assert list(result) == [Comment('foo'), Metadata('Title', 'bar')] |
| 163 | 156 |
| 164 | 157 |
| 165 def test_exception_timing(): | 158 def test_exception_timing(): |
| 166 result = parse_filterlist(['! good line', '%bad line%']) | 159 result = parse_filterlist(['! good line', '%bad line%']) |
| 167 assert next(result) == Comment('good line') | 160 assert next(result) == Comment('good line') |
| 168 with pytest.raises(ParseError): | 161 with pytest.raises(ParseError): |
| 169 next(result) | 162 next(result) |
| LEFT | RIGHT |