def convert_command_output(*command): """ Command line interface for ``coloredlogs --to-html``. Takes a command (and its arguments) and runs the program under ``script`` (emulating an interactive terminal), intercepts the output of the command and converts ANSI escape sequences in the output to HTML. """ html_output = convert(capture(command)) if connected_to_terminal(): fd, temporary_file = tempfile.mkstemp(suffix='.html') with open(temporary_file, 'w') as handle: handle.write(html_output) webbrowser.open(temporary_file) else: print(html_output)
def test_output_interception(self): """Test capturing of output from external commands.""" expected_output = 'testing, 1, 2, 3 ..' actual_output = capture(['echo', expected_output]) assert actual_output.strip() == expected_output.strip()
def test_output_interception(self): """Test capturing of output from external commands.""" expected_output = 'testing, 1, 2, 3 ..' assert capture(['sh', '-c', 'echo -n %s' % expected_output]) == expected_output