def _write_doc(self): files_to_overwite = [] for file in self.template_files: doc_file=self.config.get_output_dir()+'/'+file[:-len(self.extension)-1] if os.path.isfile(doc_file): files_to_overwite.append(doc_file) if len(files_to_overwite) > 0 and self.config.template_overwrite is False: SingleLog.print('This files will be overwritten:',files_to_overwite) if not self.config.dry_run: resulst = FileUtils.query_yes_no('do you want to continue?') if resulst != 'yes': sys.exit() for file in self.template_files: doc_file = self.config.get_output_dir()+'/'+file[:-len(self.extension)-1] source_file = self.config.get_template_base_dir()+'/'+file self.log.trace('[GENERATOR] Writing doc output to: '+doc_file+' from: '+source_file) # make sure the directory exists self._create_dir(os.path.dirname(os.path.realpath(doc_file))) if os.path.exists(source_file) and os.path.isfile(source_file): with open(source_file, 'r') as template: data = template.read() if data is not None: try: data = Environment(loader=FileSystemLoader(self.config.get_template_base_dir()),lstrip_blocks=True, trim_blocks=True).from_string(data).render(self._parser.get_data(),r=self._parser) if not self.config.dry_run: with open(doc_file, 'w') as outfile: outfile.write(data) self.log.info('Writing to: '+doc_file) else: self.log.info('[GENERATOR][DRY] Writing to: '+doc_file) except jinja2.exceptions.UndefinedError as e: self.log.error('Jinja2 templating error: <'+str(e)+"> when loading file: \""+file+"\", run in debug mode to see full except") if self.log.log_level < 1: raise except UnicodeEncodeError as e: self.log.error("At the moment I'm unable to print special chars: <"+str(e)+'>, run in debug mode to see full except') if self.log.log_level < 1: raise sys.exit()
def test_print_list(self,capsys): SingleLog.print('msg',['item1']) captured = capsys.readouterr() assert captured.out == 'msg\n [0]: item1\n'