|
1 | 1 | import pytest
|
2 |
| -from pyfakefs.fake_filesystem import FakeFilesystem |
3 | 2 |
|
4 | 3 | from blurb import blurb
|
5 | 4 |
|
@@ -188,3 +187,68 @@ def test_version(capfd):
|
188 | 187 | # Assert
|
189 | 188 | captured = capfd.readouterr()
|
190 | 189 | assert captured.out.startswith("blurb version ")
|
| 190 | + |
| 191 | + |
| 192 | +def test_parse(): |
| 193 | + # Arrange |
| 194 | + contents = ".. gh-issue: 123456\n.. section: IDLE\nHello world!" |
| 195 | + blurbs = blurb.Blurbs() |
| 196 | + |
| 197 | + # Act |
| 198 | + blurbs.parse(contents) |
| 199 | + |
| 200 | + # Assert |
| 201 | + metadata, body = blurbs[0] |
| 202 | + assert metadata["gh-issue"] == "123456" |
| 203 | + assert metadata["section"] == "IDLE" |
| 204 | + assert body == "Hello world!\n" |
| 205 | + |
| 206 | + |
| 207 | +@pytest.mark.parametrize( |
| 208 | + "contents, expected_error", |
| 209 | + ( |
| 210 | + ( |
| 211 | + "", |
| 212 | + r"Blurb 'body' text must not be empty!", |
| 213 | + ), |
| 214 | + ( |
| 215 | + "gh-issue: Hello world!", |
| 216 | + r"Blurb 'body' can't start with 'gh-'!", |
| 217 | + ), |
| 218 | + ( |
| 219 | + ".. gh-issue: 1\n.. section: IDLE\nHello world!", |
| 220 | + r"Invalid gh-issue number: '1' \(must be >= 32426\)", |
| 221 | + ), |
| 222 | + ( |
| 223 | + ".. bpo: one-two\n.. section: IDLE\nHello world!", |
| 224 | + r"Invalid bpo number: 'one-two'", |
| 225 | + ), |
| 226 | + ( |
| 227 | + ".. gh-issue: one-two\n.. section: IDLE\nHello world!", |
| 228 | + r"Invalid GitHub number: 'one-two'", |
| 229 | + ), |
| 230 | + ( |
| 231 | + ".. gh-issue: 123456\n.. section: Funky Kong\nHello world!", |
| 232 | + r"Invalid section 'Funky Kong'! You must use one of the predefined sections", |
| 233 | + ), |
| 234 | + ( |
| 235 | + ".. gh-issue: 123456\nHello world!", |
| 236 | + r"No 'section' specified. You must provide one!", |
| 237 | + ), |
| 238 | + ( |
| 239 | + ".. gh-issue: 123456\n.. section: IDLE\n.. section: IDLE\nHello world!", |
| 240 | + r"Blurb metadata sets 'section' twice!", |
| 241 | + ), |
| 242 | + ( |
| 243 | + ".. section: IDLE\nHello world!", |
| 244 | + r"'gh-issue:' or 'bpo:' must be specified in the metadata!", |
| 245 | + ), |
| 246 | + ), |
| 247 | +) |
| 248 | +def test_parse_no_body(contents, expected_error): |
| 249 | + # Arrange |
| 250 | + blurbs = blurb.Blurbs() |
| 251 | + |
| 252 | + # Act / Assert |
| 253 | + with pytest.raises(blurb.BlurbError, match=expected_error): |
| 254 | + blurbs.parse(contents) |
0 commit comments