|
23 | 23 | def sections():
|
24 | 24 | return copy.deepcopy(EXAMPLE_SECTIONS)
|
25 | 25 |
|
| 26 | +def check_ValueError(sections): |
| 27 | + "Check that a ValueError is raised when creating a `Builder` instance. Return the error message as a string." |
| 28 | + with pytest.raises(ValueError) as e: |
| 29 | + Builder(sections=sections, package='quartodoc') |
| 30 | + return str(e.value) |
| 31 | + |
26 | 32 | def test_valid_yaml(sections):
|
27 | 33 | "Test that valid YAML passes validation"
|
28 | 34 | Builder(sections=sections, package='quartodoc')
|
29 | 35 |
|
30 | 36 | def test_missing_title(sections):
|
31 | 37 | "Test that missing title raises an error"
|
32 | 38 | del sections[0]['title']
|
33 |
| - with pytest.raises(ValueError) as e: |
34 |
| - Builder(sections=sections, package='quartodoc') |
35 |
| - assert '- Missing field `title` for element 0 in the list for `sections`' in str(e.value) |
| 39 | + msg = check_ValueError(sections) |
| 40 | + assert '- Missing field `title` for element 0 in the list for `sections`' in msg |
36 | 41 |
|
37 | 42 | def test_missing_desc(sections):
|
38 | 43 | "Test that a missing description raises an error"
|
39 | 44 | sections = copy.deepcopy(EXAMPLE_SECTIONS)
|
40 | 45 | del sections[2]['desc']
|
41 |
| - with pytest.raises(ValueError) as e: |
42 |
| - Builder(sections=sections, package='quartodoc') |
43 |
| - assert '- Missing field `desc` for element 2 in the list for `sections`' in str(e.value) |
| 46 | + msg = check_ValueError(sections) |
| 47 | + assert '- Missing field `desc` for element 2 in the list for `sections`' in msg |
44 | 48 |
|
45 | 49 | def test_missing_name_contents_1(sections):
|
46 | 50 | "Test that a missing name in contents raises an error"
|
47 | 51 | del sections[2]['contents'][0]['name']
|
48 |
| - with pytest.raises(ValueError) as e: |
49 |
| - Builder(sections=sections, package='quartodoc') |
50 |
| - assert '- Missing field `name` for element 0 in the list for `contents` located in element 2 in the list for `sections`' in str(e.value) |
| 52 | + msg = check_ValueError(sections) |
| 53 | + assert '- Missing field `name` for element 0 in the list for `contents` located in element 2 in the list for `sections`' in msg |
51 | 54 |
|
52 | 55 | def test_missing_name_contents_2(sections):
|
53 | 56 | "Test that a missing name in contents raises an error in a different section."
|
54 | 57 | del sections[1]['contents'][0]['name']
|
55 |
| - with pytest.raises(ValueError) as e: |
56 |
| - Builder(sections=sections, package='quartodoc') |
57 |
| - assert '- Missing field `name` for element 0 in the list for `contents` located in element 1 in the list for `sections`' in str(e.value) |
| 58 | + msg = check_ValueError(sections) |
| 59 | + assert '- Missing field `name` for element 0 in the list for `contents` located in element 1 in the list for `sections`' in msg |
58 | 60 |
|
59 | 61 | def test_misplaced_kindpage(sections):
|
60 | 62 | "Test that a misplaced kind: page raises an error"
|
61 | 63 | sections[0]['kind'] = 'page'
|
62 |
| - with pytest.raises(ValueError) as e: |
63 |
| - Builder(sections=sections, package='quartodoc') |
64 |
| - assert ' - Missing field `path` for element 0 in the list for `sections`, which you need when setting `kind: page`.' in str(e.value) |
| 64 | + msg = check_ValueError(sections) |
| 65 | + assert ' - Missing field `path` for element 0 in the list for `sections`, which you need when setting `kind: page`.' in msg |
0 commit comments