diff --git a/Tst/json_to_csv.py b/Tst/json_to_csv.py index cb57d96c6cb02c87ffbd5de9dccc6d14a8a8331b..366d6d62996de380ef7fab7f023402b345c34a66 100755 --- a/Tst/json_to_csv.py +++ b/Tst/json_to_csv.py @@ -14,21 +14,23 @@ def run(jfile, outfile): data = json.loads(jfile) header = 'Item|Description|Verification|TestResult' - name = '{}|{}|Test spec. version: {}| IASW-{}'.format(data['_name'], data['_description'], data['_spec_version'], data['_iasw_version']) + name = '{}|{}|Test spec. version: {}| IASW-{}'.format(data['_name'], replace_newline(data['_description']), + data['_spec_version'], data['_iasw_version']) # Date from last time the json file was changed + current date date = 'Date||{}|'.format(datetime.datetime.now().strftime('%Y-%m-%d')) - testcomment = 'Comment|{}||'.format(data['_comment']) - precond = 'Precond.|{}||'.format(data['_precon_descr']) - postcond = 'Postcond.|{}||'.format(data['_postcon_descr']) + testcomment = 'Comment|{}||'.format(replace_newline(data['_comment'])) + precond = 'Precond.|{}||'.format(replace_newline(data['_precon_descr'])) + postcond = 'Postcond.|{}||'.format(replace_newline(data['_postcon_descr'])) steps = [] for step in data['sequences'][0]['steps']: - line = 'Step {}|{}|{}|'.format(step['_step_number'], step['_description'], step['_verification_description']) + line = 'Step {}|{}|{}|'.format(step['_step_number'], replace_newline(step['_description']), + replace_newline(step['_verification_description'])) steps.append(line) if step['_step_comment'] != '': - comment = 'Comment|{}||'.format(step['_step_comment']) + comment = 'Comment|{}||'.format(replace_newline(step['_step_comment'])) steps.append(comment) if outfile[-1] == '/': # If only path is given but no filename @@ -43,6 +45,10 @@ def run(jfile, outfile): fd.write(buf) +def replace_newline(txt): + return txt.replace('\n', '; ') + + if __name__ == '__main__': json_file_path = sys.argv[1] @@ -50,6 +56,5 @@ if __name__ == '__main__': outputfile = sys.argv[2] else: # If no filename is given take the working directory path, filename is used from the json file outputfile = os.getcwd() + '/' - # outputfile = '/'.join(json_file_path[:-len(json_file_path.split('/')[-1])-1]) + '/' # This would take the json File path run(json_file_path, outputfile)