Guest User

Untitled

a guest
Jan 18th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. from __future__ import print_function
  5.  
  6. import os
  7. import sys
  8. import fnmatch
  9.  
  10. from subprocess import Popen
  11.  
  12.  
  13. def norm_join(base, *parts):
  14. return os.path.join(
  15. os.path.normpath(os.path.expanduser(base)),
  16. *map(os.path.normpath, parts)
  17. )
  18.  
  19.  
  20. # Definir Comandos
  21.  
  22. _OPENCOVER_CMD = norm_join('~/OpenCover', 'OpenCover.Console.exe')
  23. _REP_GEN_CMD = norm_join('~/ReportGenerator', 'ReportGenerator.exe')
  24. _NUNIT_CMD = norm_join('~/nunit', 'nunit3-console.exe')
  25. _NUNIT_ARGS = '--inprocess --noresult -where "cat != LongRunning"'
  26.  
  27.  
  28. def find_test_assemblies(tst_path):
  29. for (root, dirnames, filenames) in os.walk(tst_path):
  30. for filename in fnmatch.filter(filenames, '*[Tt]est*.[Dd][Ll][Ll]'):
  31. yield os.path.join(root, filename)
  32.  
  33.  
  34. def basename_noext(filepath):
  35. return os.path.basename(os.path.splitext(filepath)[0])
  36.  
  37.  
  38. def to_exclude_filter(assembly_path):
  39. return '-[{}]*'.format(os.path.basename(os.path.splitext(assembly_path)[0]))
  40.  
  41.  
  42. def exec_cmd(command_list):
  43. try:
  44. pipe = Popen(command_list)
  45. pipe.wait()
  46. return pipe.returncode
  47. except Exception, ex:
  48. print(ex, file=sys.stderr)
  49. sys.exit(3)
  50.  
  51.  
  52. def main(src_path):
  53.  
  54. # Define paths
  55. tst_path = norm_join(src_path, 'output')
  56. rpt_path = norm_join(src_path, '_coverage')
  57.  
  58. if not os.path.isdir(rpt_path):
  59. os.makedirs(rpt_path)
  60.  
  61. out_file = norm_join(rpt_path, 'result.xml')
  62.  
  63. # Define default filters
  64. include_filter = '+[*]*'
  65. exclude_filters = ['nunit', 'Moq']
  66.  
  67. # Discover assemblies to analyze
  68. test_assemblies = list(find_test_assemblies(tst_path))
  69. exclude_filters.extend(test_assemblies)
  70.  
  71. if not test_assemblies:
  72. print('No se encontraron assemblies a incluir.', file=sys.stderr)
  73. sys.exit(2)
  74.  
  75. # Execute tests
  76. print('\nEjecutando pruebas y analizando...')
  77. exec_cmd([
  78. _OPENCOVER_CMD,
  79. '-returntargetcode',
  80. '-register:user',
  81. '-target:{}'.format(_NUNIT_CMD),
  82. '-targetargs:{} {}'.format(_NUNIT_ARGS, ' '.join(test_assemblies)),
  83. '-filter:{} {}'.format(include_filter, ' '.join(to_exclude_filter(f) for f in
  84. exclude_filters)),
  85. '-output:{}'.format(out_file),
  86. ])
  87.  
  88. print('\nGenerando reporte...')
  89. exec_cmd([_REP_GEN_CMD, '-reports:{}'.format(out_file), '-targetdir:{}'.format(rpt_path),
  90. '-verbosity:Info'])
  91.  
  92. # All done!
  93. print('listo.')
  94.  
  95.  
  96. if __name__ == '__main__':
  97. if len(sys.argv) < 2:
  98. print('{} <src_path>'.format(sys.argv[0]), file=sys.stderr)
  99. sys.exit(1)
  100. else:
  101. main(sys.argv[1])
Add Comment
Please, Sign In to add comment