Skip to content

Commit

Permalink
Add test for markdown generation
Browse files Browse the repository at this point in the history
  • Loading branch information
christophfroehlich committed Dec 28, 2023
1 parent 682506f commit a8a7582
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,9 @@ def __str__(self):
data = {
'title': title,
'default_config': str(self.default_config),
'parameter_details': '\n'.join(str(val) for val in self.param_details).join(
str(val) for val in self.runtime_param_details
),
'parameter_details': '\n'.join(str(val) for val in self.param_details)
+ '\n'
+ '\n'.join(str(val) for val in self.runtime_param_details),
}

j2_template = Template(GenerateCode.templates['documentation'])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
{% endif %}
* Type: `{{type}}`
{%- if default_value|length %}
* Default Value: {{default_value}}
{% endif %}
* Default Value: {{default_value}}{% endif %}
{%- if constraints|length %}

*Constraints:*
{{constraints}}
{% endif %}
{{constraints}}{% endif %}
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,18 @@ class GenerateCode:
templates = None

def __init__(self, language: str):
if language == 'cpp':
self.comments = '// auto-generated DO NOT EDIT'
elif language == 'rst':
self.comments = '.. auto-generated DO NOT EDIT'
elif language == 'markdown':
self.comments = '<!--- auto-generated DO NOT EDIT -->'
elif language == 'python' or language == 'markdown':
self.comments = '# auto-generated DO NOT EDIT'
else:
raise compile_error(
'Invalid language, only cpp, markdown, rst, and python are currently supported.'
)
GenerateCode.templates = get_all_templates(language)
self.language = language
self.namespace = ''
Expand All @@ -702,16 +714,6 @@ def __init__(self, language: str):
self.remove_dynamic_parameter = []
self.declare_parameter_sets = []
self.set_stack_params = []
if language == 'cpp':
self.comments = '// auto-generated DO NOT EDIT'
elif language == 'rst':
self.comments = '.. auto-generated DO NOT EDIT'
elif language == 'python' or language == 'markdown':
self.comments = '# auto-generated DO NOT EDIT'
else:
raise compile_error(
'Invalid language, only c++ and python are currently supported.'
)
self.user_validation_file = ''

def parse(self, yaml_file, validate_header):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from ament_index_python.packages import get_package_share_path
from generate_parameter_library_py.generate_cpp_header import run as run_python
from generate_parameter_library_py.generate_python_module import run as run_cpp
from generate_parameter_library_py.generate_markdown import run as run_md
from generate_parameter_library_py.parse_yaml import YAMLSyntaxError
from generate_parameter_library_py.generate_cpp_header import parse_args

Expand All @@ -29,16 +30,42 @@ def set_up(yaml_test_file):
full_file_path = os.path.join(
get_package_share_path('generate_parameter_library_py'), 'test', yaml_test_file
)
testargs = [sys.argv[0], '/tmp/admittance_controller.h', full_file_path]
testargs = [sys.argv[0], '/tmp/' + yaml_test_file + '.h', full_file_path]

with patch.object(sys, 'argv', testargs):
args = parse_args()
output_file = args.output_cpp_header_file
yaml_file = args.input_yaml_file
validate_header = args.validate_header
run_cpp(output_file, yaml_file, validate_header)

testargs = [sys.argv[0], '/tmp/' + yaml_test_file + '.py', full_file_path]

with patch.object(sys, 'argv', testargs):
args = parse_args()
output_file = args.output_cpp_header_file
yaml_file = args.input_yaml_file
validate_header = args.validate_header
run_python(output_file, yaml_file, validate_header)

testargs = [sys.argv[0], '/tmp/' + yaml_test_file + '.md', full_file_path]

with patch.object(sys, 'argv', testargs):
args = parse_args()
output_file = args.output_cpp_header_file
yaml_file = args.input_yaml_file
validate_header = args.validate_header
run_md(yaml_file, output_file, 'markdown')

testargs = [sys.argv[0], '/tmp/' + yaml_test_file + '.rst', full_file_path]

with patch.object(sys, 'argv', testargs):
args = parse_args()
output_file = args.output_cpp_header_file
yaml_file = args.input_yaml_file
validate_header = args.validate_header
run_md(yaml_file, output_file, 'rst')


# class TestViewValidCodeGen(unittest.TestCase):
@pytest.mark.parametrize(
Expand Down

0 comments on commit a8a7582

Please sign in to comment.