A bin folder, holding helpfull scripts and commands
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mkunittest 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. #!/usr/bin/env python3
  2. # -*- coding: UTF-8 -*-
  3. import os
  4. import stat
  5. name = os.path.basename(os.path.abspath('.'))
  6. gitignore = """# general stuff
  7. *~
  8. unittest/testresults/*
  9. unittest/output_data/*
  10. # eclipse stuff
  11. .settings/
  12. # Byte-compiled / optimized / DLL files
  13. __pycache__/
  14. *.py[cod]
  15. # C extensions
  16. *.so
  17. # Distribution / packaging
  18. .Python
  19. env/
  20. build/
  21. develop-eggs/
  22. dist/
  23. downloads/
  24. eggs/
  25. .eggs/
  26. lib/
  27. lib64/
  28. parts/
  29. sdist/
  30. var/
  31. *.egg-info/
  32. .installed.cfg
  33. *.egg
  34. # PyInstaller
  35. # Usually these files are written by a python script from a template
  36. # before PyInstaller builds the exe, so as to inject date/other infos into it.
  37. *.manifest
  38. *.spec
  39. # Installer logs
  40. pip-log.txt
  41. pip-delete-this-directory.txt
  42. # Unit test / coverage reports
  43. htmlcov/
  44. .tox/
  45. .coverage
  46. .coverage.*
  47. .cache
  48. nosetests.xml
  49. coverage.xml
  50. *,cover
  51. # Translations
  52. *.mo
  53. *.pot
  54. # Django stuff:
  55. *.log
  56. # Sphinx documentation
  57. docs/_build/
  58. # PyBuilder
  59. target/
  60. """
  61. unittest_py = """#!/usr/bin/env python
  62. # -*- coding: utf-8 -*-
  63. #
  64. import optparse
  65. import os
  66. import report
  67. import unittest
  68. import tests
  69. parser = optparse.OptionParser("usage: %prog [clean|run|coverage|pdf|copy|release]")
  70. parser.add_option("-e", "--execution-level", dest="execution_level", default="full", help="sets the execution level [full | short | smoke | single]")
  71. (options, args) = parser.parse_args()
  72. if report.TCEL_REVERSE_NAMED.get(tests.execution_level, report.TCEL_FULL) < report.TCEL_REVERSE_NAMED.get(options.execution_level, report.TCEL_FULL):
  73. options.execution_level = tests.execution_level
  74. unittest.run.unittest(options, args, os.path.dirname(os.path.abspath(os.path.dirname(__file__))))
  75. """
  76. config_py = """#!/usr/bin/env python
  77. # -*- coding: UTF-8 -*-
  78. import optparse
  79. import os
  80. import %s as lib
  81. release_unittest_version = 'xxx'
  82. lib_path = os.path.realpath(lib.__path__[0])
  83. additional_loggers_to_catch = []
  84. if __name__ == "__main__":
  85. parser = optparse.OptionParser("usage: %%prog [options] folder_for_document")
  86. parser.add_option("-p", "--path", dest="libpath", action="store_true", default=False, help="prints the library path")
  87. (options, args) = parser.parse_args()
  88. if options.libpath:
  89. print(lib_path)
  90. """ % name
  91. test_init_py = """#!/usr/bin/env python
  92. # -*- coding: UTF-8 -*-
  93. import %s
  94. from report import TCEL_FULL
  95. from report import TCEL_SHORT
  96. from report import TCEL_SINGLE
  97. from report import TCEL_SMOKE
  98. #from tests import test_
  99. execution_level = 'full'
  100. def testrun(tcl):
  101. #
  102. # caching.property_cache_json
  103. #
  104. tcl.testCase('description', TCEL_FULL, test_.func, *args, **kwargs)
  105. """ % name
  106. main_makefile = """MODULE_NAME := $(shell basename `pwd`)
  107. view_unittest:
  108. xdg-open pylibs/$(MODULE_NAME)/_testresults_/unittest.pdf
  109. view_requirements:
  110. xdg-open pylibs/$(MODULE_NAME)/_requirements_/specification.pdf
  111. view_docs:
  112. xdg-open pylibs/$(MODULE_NAME)/_docs_/index.html
  113. clean:
  114. make -kC docs clean; make -kC requirements cleanall; make -kC unittest clean
  115. """
  116. docs_makefile = """# Minimal makefile for Sphinx documentation
  117. #
  118. # You can set these variables from the command line.
  119. SPHINXOPTS =
  120. SPHINXBUILD = sphinx-build
  121. SPHINXPRJ = state_machine
  122. SOURCEDIR = .
  123. BUILDDIR = _build
  124. # Put it first so that "make" without argument is like "make help".
  125. help:
  126. @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
  127. .PHONY: help Makefile
  128. # Catch-all target: route all unknown targets to Sphinx using the new
  129. # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
  130. %: $(SPHINXPRJ)
  131. @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
  132. $(SPHINXPRJ): Makefile
  133. make -C $@/_examples_ all
  134. release: html
  135. rm -rf $(SPHINXPRJ)/_docs_
  136. mv $(BUILDDIR)/html $(SPHINXPRJ)/_docs_
  137. view_html: html
  138. xdg-open $(BUILDDIR)/html/index.html
  139. """
  140. with open('.gitignore', 'w') as fh:
  141. fh.write(gitignore)
  142. with open('Makefile', 'w') as fh:
  143. fh.write(main_makefile)
  144. os.mkdir('docs')
  145. with open('docs/Makefile', 'w') as fh:
  146. fh.write(docs_makefile)
  147. os.symlink('../pylibs/%s' % name, 'docs/%s' % name)
  148. os.mkdir('pylibs')
  149. os.mkdir('requirements')
  150. os.symlink('../pylibs/reqif/scripts/Makefile', 'requirements/Makefile')
  151. os.symlink('../pylibs/reqif', 'requirements/reqif')
  152. os.mkdir('unittest')
  153. os.symlink('../pylibs/unittest/scripts/Makefile', 'unittest/Makefile')
  154. os.mkdir('unittest/input_data')
  155. os.mkdir('unittest/output_data')
  156. os.mkdir('unittest/src')
  157. with open('unittest/src/config.py', 'w') as fh:
  158. fh.write(config_py)
  159. with open('unittest/src/unittest.py', 'w') as fh:
  160. fh.write(unittest_py)
  161. for lib_name in [name, 'report', 'unittest', 'fstools', 'reqif']:
  162. os.symlink('../../pylibs/%s' % lib_name, 'unittest/src/%s' % lib_name)
  163. os.mkdir('unittest/src/tests')
  164. with open('unittest/src/tests/__init__.py', 'w') as fh:
  165. fh.write(test_init_py)