Debian Codegraph @

os_api_ref/tests/test_warnings.py

raw symbols SCIP
1 # Licensed under the Apache License, Version 2.0 (the "License"); you may
2 # not use this file except in compliance with the License. You may obtain
3 # a copy of the License at
4 #
5 # http://www.apache.org/licenses/LICENSE-2.0
6 #
7 # Unless required by applicable law or agreed to in writing, software
8 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10 # License for the specific language governing permissions and limitations
11 # under the License.
12
13 """
14 test_os_api_ref
15 ----------------------------------
16
17 Tests for `os_api_ref` module.
18 """
19
20 from collections import OrderedDict
21
22 from bs4 import BeautifulSoup
23
24 from os_api_ref.tests import base
25
26
27 class TestWarnings(base.TestCase):
28 """Test basic rendering.
29
30 This can be used to test that basic rendering works for these
31 examples, so if someone breaks something we know.
32 """
33
34 @base.with_app(buildername='html', srcdir=base.example_dir('warnings'))
35 def setUp(self, app, status, warning):
36 super().setUp()
37 self.app = app
38 self.app.build()
39 self.status = status.getvalue()
40 self.warning = warning.getvalue()
41 self.html = (app.outdir / 'index.html').read_text(encoding='utf-8')
42 self.soup = BeautifulSoup(self.html, 'html.parser')
43 self.content = str(self.soup)
44
45 def test_out_of_order(self):
46 """Do we get an out of order naming warning."""
47 self.assertIn(
48 ("WARNING: Parameters out of order ``name2`` "
49 "should be after ``name``"),
50 self.warning)
51
52 def test_missing_lookup_name(self):
53 """Warning when missing a lookup key in parameter file."""
54 self.assertIn(
55 ("WARNING: No field definition for ``lookup_key_name`` found in "),
56 self.warning)
57
58 def test_missing_field(self):
59 """Warning when missing type field in parameter file."""
60 # py312 changes string interpretation of OrderedDict.
61 # Prevent such failures by using OrderedDict directly
62 cmp_data = OrderedDict({
63 "description": "name_1 is missing type field.\n",
64 "in": "body",
65 "required": True
66 })
67 self.assertIn(
68 ("WARNING: Failure on key: name, values: " +
69 f"{cmp_data}. " +
70 "'NoneType' object has no attribute 'split'"),
71 self.warning)
72
73 def test_invalid_parameter_definition(self):
74 """Warning when parameter definition is invalid."""
75 self.assertIn(
76 ("WARNING: Invalid parameter definition ``invalid_name``. " +
77 "Expected format: ``name: reference``. "),
78 self.warning)
79
80 def test_empty_parameter_file(self):
81 """Warning when parameter file exists but is empty."""
82 self.assertIn(
83 ("WARNING: Parameters file is empty"),
84 self.warning)
85
86 def test_no_parameters_set(self):
87 """Error when parameters are not set in rest_parameters stanza."""
88 self.assertIn(
89 ("No parameters defined\n\n.." +
90 " rest_parameters:: parameters.yaml"),
91 self.warning)
92
93 def test_parameter_file_not_exist(self):
94 """Error when parameter file does not exist"""
95 self.assertIn(
96 ("No parameters defined\n\n.." +
97 " rest_parameters:: no_parameters.yaml"),
98 self.warning)
99
100 def test_missing_path_parameter_in_stanza(self):
101 """Warning when path param not found in rest_parameter stanza."""
102
103 self.assertIn(
104 ("WARNING: No path parameter ``b_id`` found in" +
105 " rest_parameter stanza.\n"),
106 self.warning)