/ruffus/test/test_inputs_with_multiple_args_raising_exception.py

https://code.google.com/p/ruffus/ · Python · 193 lines · 116 code · 49 blank · 28 comment · 13 complexity · 9a116a65d8a02851d7d82a5e801dde68 MD5 · raw file

  1. #!/usr/bin/env python
  2. """
  3. test_inputs_with_multiple_args_raising_exception.py
  4. inputs with multiple arguments should raise an exception
  5. """
  6. #88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888
  7. # options
  8. #88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888
  9. from optparse import OptionParser
  10. import sys, os
  11. import os.path
  12. import StringIO
  13. import re,time
  14. # add self to search path for testing
  15. exe_path = os.path.split(os.path.abspath(sys.argv[0]))[0]
  16. sys.path.insert(0,os.path.abspath(os.path.join(exe_path,"..", "..")))
  17. if __name__ == '__main__':
  18. module_name = os.path.split(sys.argv[0])[1]
  19. module_name = os.path.splitext(module_name)[0];
  20. else:
  21. module_name = __name__
  22. import ruffus
  23. print "\tRuffus Version = ", ruffus.__version__
  24. parser = OptionParser(version="%%prog v1.0, ruffus v%s" % ruffus.ruffus_version.__version)
  25. parser.add_option("-t", "--target_tasks", dest="target_tasks",
  26. action="append",
  27. default = list(),
  28. metavar="JOBNAME",
  29. type="string",
  30. help="Target task(s) of pipeline.")
  31. parser.add_option("-f", "--forced_tasks", dest="forced_tasks",
  32. action="append",
  33. default = list(),
  34. metavar="JOBNAME",
  35. type="string",
  36. help="Pipeline task(s) which will be included even if they are up to date.")
  37. parser.add_option("-j", "--jobs", dest="jobs",
  38. default=1,
  39. metavar="jobs",
  40. type="int",
  41. help="Specifies the number of jobs (commands) to run simultaneously.")
  42. parser.add_option("-v", "--verbose", dest = "verbose",
  43. action="count", default=0,
  44. help="Print more verbose messages for each additional verbose level.")
  45. parser.add_option("-d", "--dependency", dest="dependency_file",
  46. #default="simple.svg",
  47. metavar="FILE",
  48. type="string",
  49. help="Print a dependency graph of the pipeline that would be executed "
  50. "to FILE, but do not execute it.")
  51. parser.add_option("-F", "--dependency_graph_format", dest="dependency_graph_format",
  52. metavar="FORMAT",
  53. type="string",
  54. default = 'svg',
  55. help="format of dependency graph file. Can be 'ps' (PostScript), "+
  56. "'svg' 'svgz' (Structured Vector Graphics), " +
  57. "'png' 'gif' (bitmap graphics) etc ")
  58. parser.add_option("-n", "--just_print", dest="just_print",
  59. action="store_true", default=False,
  60. help="Print a description of the jobs that would be executed, "
  61. "but do not execute them.")
  62. parser.add_option("-M", "--minimal_rebuild_mode", dest="minimal_rebuild_mode",
  63. action="store_true", default=False,
  64. help="Rebuild a minimum of tasks necessary for the target. "
  65. "Ignore upstream out of date tasks if intervening tasks are fine.")
  66. parser.add_option("-K", "--no_key_legend_in_graph", dest="no_key_legend_in_graph",
  67. action="store_true", default=False,
  68. help="Do not print out legend and key for dependency graph.")
  69. parser.add_option("-H", "--draw_graph_horizontally", dest="draw_horizontally",
  70. action="store_true", default=False,
  71. help="Draw horizontal dependency graph.")
  72. parameters = [
  73. ]
  74. #88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888
  75. # imports
  76. #88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888
  77. import StringIO
  78. import re
  79. import operator
  80. import sys,os
  81. from collections import defaultdict
  82. import random
  83. sys.path.append(os.path.abspath(os.path.join(exe_path,"..", "..")))
  84. from ruffus import *
  85. # use simplejson in place of json for python < 2.6
  86. try:
  87. import json
  88. except ImportError:
  89. import simplejson
  90. json = simplejson
  91. #88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888
  92. # Main logic
  93. #88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888
  94. # get help string
  95. f =StringIO.StringIO()
  96. parser.print_help(f)
  97. helpstr = f.getvalue()
  98. (options, remaining_args) = parser.parse_args()
  99. #88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888
  100. # Tasks
  101. #88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888
  102. try:
  103. @transform(None, regex("b"), inputs("a", "b"), "task_1.output")
  104. def task_1 (i, o):
  105. for f in o:
  106. open(f, 'w')
  107. except ruffus.ruffus_exceptions.error_task_transform_inputs_multiple_args:
  108. print "\tExpected exception thrown"
  109. sys.exit(0)
  110. raise Exception("Inputs(...) with multiple arguments should have thrown an exception")
  111. import unittest
  112. class Test_task_mkdir(unittest.TestCase):
  113. def setUp (self):
  114. """
  115. """
  116. pass
  117. def tearDown (self):
  118. """
  119. """
  120. pass
  121. def test_no_re_match (self):
  122. pipeline_run([task_1], options.forced_tasks, multiprocess = options.jobs,
  123. logger = stderr_logger if options.verbose else black_hole_logger,
  124. gnu_make_maximal_rebuild_mode = not options.minimal_rebuild_mode,
  125. verbose = options.verbose)
  126. if __name__ == '__main__':
  127. if options.just_print:
  128. pipeline_printout(sys.stdout, options.target_tasks, options.forced_tasks,
  129. verbose = options.verbose,
  130. gnu_make_maximal_rebuild_mode = not options.minimal_rebuild_mode)
  131. elif options.dependency_file:
  132. pipeline_printout_graph ( open(options.dependency_file, "w"),
  133. options.dependency_graph_format,
  134. options.target_tasks,
  135. options.forced_tasks,
  136. draw_vertically = not options.draw_horizontally,
  137. gnu_make_maximal_rebuild_mode = not options.minimal_rebuild_mode,
  138. no_key_legend = options.no_key_legend_in_graph)
  139. else:
  140. sys.argv= sys.argv[0:1]
  141. unittest.main()