def display_example(name, language, number_lines=False): r"""Display the yaml and source code for an example with syntax highlighting. Args: name (str): Name of the example. language (str): Language that example should be displayed in. number_lines (bool, optional): If True, line numbers will be added to the displayed examples. Defaults to False. """ ex_yml = get_example_yaml(name, language) ex_src = get_example_source(name, language) tools.display_source(ex_yml, number_lines=number_lines) tools.display_source(ex_src, number_lines=number_lines)
def test_display_source(): r"""Test display_source.""" fname = os.path.abspath(__file__) tools.display_source([fname], number_lines=True) tools.display_source([fname], return_lines=True) tools.display_source(test_display_source) fname_txt = os.path.join(tempfile.gettempdir(), 'unknown_example.invalid') with open(fname_txt, 'w') as fd: fd.write('hello') try: tools.display_source(fname_txt) finally: os.remove(fname_txt)
def test_display_source(): r"""Test display_source.""" fname = os.path.abspath(__file__) tools.display_source([fname], number_lines=True) tools.display_source([fname], return_lines=True)