/docs/rule/python_test.soy

https://gitlab.com/smartether/buck · Closure Template · 176 lines · 100 code · 22 blank · 54 comment · 1 complexity · b28c9943f91a3e608e1e2a004f5d18f4 MD5 · raw file

  1. {namespace python_test}
  2. /***/
  3. {template .soyweb}
  4. {call buck.page}
  5. {param title: 'python_test()' /}
  6. {param navid: 'rule_python_test' /}
  7. {param prettify: true /}
  8. {param description}
  9. A rule that is used to define a set of python files that contian tests
  10. to run via the python unit testing framework.
  11. {/param}
  12. {param content}
  13. {call buck.rule}
  14. {param status: 'UNFROZEN' /}
  15. {param overview}
  16. A <code>python_test()</code> rule is used to define a set of <code>.py</code>{sp}
  17. files that contain tests to run via the <a href="https://docs.python.org/2/library/unittest.html">Python unit testing framework</a>.
  18. {/param}
  19. {param args}
  20. {call buck.arg}
  21. {param name: 'name' /}
  22. {param desc}
  23. The name of the rule.
  24. {/param}
  25. {/call}
  26. {call python_common.srcs_arg /}
  27. {call python_common.platform_srcs_arg /}
  28. {call python_common.resources_arg /}
  29. {call python_common.platform_resources_arg /}
  30. {call python_common.base_module_arg /}
  31. {call buck.arg}
  32. {param name: 'main_module' /}
  33. {param default : 'None' /}
  34. {param desc}
  35. The main module used to run the tests.
  36. This parameter is normally not needed, as Buck will provide a default main
  37. module that runs all tests. However, you can override this with your own
  38. module to perform custom initialization or command line processing. Your
  39. custom module can import the standard Buck test main
  40. as <code>__test_main__</code>, and can invoke it's normal main function
  41. as <code>__test_main__.main(sys.argv)</code>.
  42. {/param}
  43. {/call}
  44. {call python_common.platform_arg /}
  45. {call buck.arg}
  46. {param name: 'env' /}
  47. {{param default : '{}' /}}
  48. {param desc}
  49. A map of environment names and values to set when running the test.
  50. <br><br>
  51. It is also possible to expand references to other rules within the <b>values</b> of
  52. these environment variables, using builtin {call buck.string_parameter_macros /}:
  53. <dl>
  54. <dt><code>$(location /&#x2F;path/to:target)</code></dt>
  55. <dd>Expands to the location of the output of the build rule. This
  56. means that you can refer to these without needing to be aware of how
  57. Buck is storing data on the disk mid-build.</dd>
  58. </dl>
  59. {/param}
  60. {/call}
  61. {call buck.arg}
  62. {param name: 'deps' /}
  63. {param default : '[]' /}
  64. {param desc}
  65. {call buck.python_library /} rules used by the tests in this rules sources.
  66. {/param}
  67. {/call}
  68. {call buck.arg}
  69. {param name: 'labels' /}
  70. {param default: '[]' /}
  71. {param desc}
  72. A list of labels to be applied to these tests. These labels are
  73. arbitrary text strings and have no meaning within buck itself. They
  74. can, however, have meaning for you as a test author
  75. (e.g., <code>smoke</code> or <code>fast</code>). A label can be
  76. used to filter or include a specific <code>python_test()</code> rule
  77. when executing <a href="{ROOT}command/test.html"><code>buck
  78. test</code></a>.
  79. {/param}
  80. {/call}
  81. {call buck.test_rule_timeout_ms /}
  82. {call python_common.package_style_arg /}
  83. {call python_common.preload_deps_arg /}
  84. {call python_common.linker_flags_arg /}
  85. {/param} // close args
  86. {param examples}
  87. {literal}<pre class="prettyprint lang-py">
  88. # A rule that includes a single .py file containing tests.
  89. python_test(
  90. name = 'fileutil_test',
  91. srcs = ['fileutil_tests.py'],
  92. deps = [
  93. ':fileutil',
  94. ],
  95. )
  96. # A rule that uses glob() to include all sources in the directory which the
  97. # rule is defined. It also lists a resource file that gets packaged with
  98. # the sources in this rule.
  99. python_library(
  100. name = 'fileutil',
  101. srcs = glob(['fileutil/**/*.py'],
  102. resources = [
  103. 'testdata.dat',
  104. ],
  105. )
  106. </pre>{/literal}
  107. <p>
  108. Here is an example of using the `platform_srcs` and `platform_resources`
  109. parameters to pull in sources/resources only when building for a specific
  110. Python platform:
  111. </p>
  112. {literal}<pre class="prettyprint lang-ini">
  113. ; .buckconfig
  114. [python#py2]
  115. interpreter = /usr/bin/python2.7
  116. [python#py3]
  117. interpreter = /usr/bin/python3.4
  118. </pre>{/literal}
  119. {literal}<pre class="prettyprint lang-py">
  120. # BUCK
  121. python_test(
  122. name = 'test',
  123. platform_srcs = [
  124. ('py2', ['foo.py']),
  125. ('py3', ['bar.py']),
  126. ],
  127. platform_resources = [
  128. ('py2', ['foo.dat']),
  129. ('py3', ['bar.dat']),
  130. ],
  131. )
  132. </pre>{/literal}
  133. <p>
  134. Here is an example of using the `platform` parameter to select the "py2"
  135. Python platform as defined in `.buckconfig` above:
  136. </p>
  137. {literal}<pre class="prettyprint lang-py">
  138. # BUCK
  139. python_test(
  140. name = 'bin',
  141. platform = 'py2',
  142. srcs = [
  143. 'foo.py',
  144. ],
  145. )
  146. </pre>{/literal}
  147. {/param}
  148. {/call} // close buck.rule
  149. {/param}
  150. {/call}
  151. {/template}