Skip to content

Commit

Permalink
fix examples tests
Browse files Browse the repository at this point in the history
  • Loading branch information
holmanb committed Nov 23, 2021
1 parent e455a77 commit b4443e7
Showing 1 changed file with 42 additions and 14 deletions.
56 changes: 42 additions & 14 deletions tests/unittests/test_handler/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ def setUp(self):
super(ValidateCloudConfigFileTest, self).setUp()
self.config_file = self.tmp_path('cloudcfg.yaml')


def test_validateconfig_file_error_on_absent_file(self):
"""On absent config_path, validate_cloudconfig_file errors."""
with self.assertRaises(RuntimeError) as context_mgr:
Expand Down Expand Up @@ -244,6 +245,10 @@ class GetSchemaDocTest(CiTestCase):

def setUp(self):
super(GetSchemaDocTest, self).setUp()
self.required_schema = {
'title': 'title', 'description': 'description', 'id': 'id',
'name': 'name', 'frequency': 'frequency',
'distros': ['debian', 'rhel']}
self.meta = MetaSchema({
'title': 'title',
'description': 'description',
Expand All @@ -257,10 +262,13 @@ def setUp(self):

def test_get_meta_doc_returns_restructured_text(self):
"""get_meta_doc returns restructured text for a cloudinit schema."""
schema = {'properties': {
'prop1': {'type': 'array',
'items': {'type': 'integer'}}}}
doc = get_meta_doc(self.meta, schema)
full_schema = copy(self.required_schema)
full_schema.update(
{'properties': {
'prop1': {'type': 'array', 'description': 'prop-description',
'items': {'type': 'integer'}}}})

doc = get_meta_doc(self.meta, full_schema)
self.assertEqual(
dedent("""
name
Expand All @@ -276,7 +284,7 @@ def test_get_meta_doc_returns_restructured_text(self):
**Supported distros:** debian, rhel
**Config schema**:
**prop1:** (array of integer)
**prop1:** (array of integer) prop-description\n\n
**Examples**::
Expand Down Expand Up @@ -313,16 +321,18 @@ def test_get_meta_doc_handles_nested_oneof_property_types(self):
'**prop1:** (array of (string)/(integer))',
get_meta_doc(self.meta, schema))

def test_get_meta_doc_handles_string_examples(self):
"""get_meta_doc properly indented examples as a list of strings."""
schema = {'properties': {
'prop1': {'type': 'array',
'items': {'type': 'integer'}}}}
meta_doc = get_meta_doc(self.meta, schema)
def test_get_schema_doc_handles_string_examples(self):
"""get_schema_doc properly indented examples as a list of strings."""
full_schema = copy(self.required_schema)
full_schema.update(
{'examples': ['ex1:\n [don\'t, expand, "this"]', 'ex2: true'],
'properties': {
'prop1': {'type': 'array', 'description': 'prop-description',
'items': {'type': 'integer'}}}})
self.assertIn(
dedent("""
**Config schema**:
**prop1:** (array of integer)
**prop1:** (array of integer) prop-description
**Examples**::
Expand All @@ -331,22 +341,40 @@ def test_get_meta_doc_handles_string_examples(self):
# --- Example2 ---
ex2: true
"""),
meta_doc)
get_meta_doc(self.meta, full_schema))

def test_get_meta_doc_properly_parse_description(self):
"""get_meta_doc description properly formatted"""
schema = {
'properties': {
'p1': {
'type': 'string',
'description': dedent("""\
This item
has the
following options:
- option1
- option2
- option3
The default value is
option1""")
}
}
}

self.assertIn(
dedent("""
**Config schema**:
**p1:** (string)
**p1:** (string) This item has the following options:
- option1
- option2
- option3
The default value is option1
"""),
get_meta_doc(self.meta, schema))

Expand Down

0 comments on commit b4443e7

Please sign in to comment.