Add a tool to make an empty unittest script

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxPython/Phoenix/trunk@72063 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2012-07-13 03:17:42 +00:00
parent 0e245c6617
commit c93c093b88
2 changed files with 67 additions and 2 deletions

View File

@@ -1,7 +1,6 @@
#!/usr/bin/env python
#---------------------------------------------------------------------------
# Name: etgtools/make-new-etg-file.py
# Name: bin/make-new-etg-file.py
# Author: Kevin Ollivier
#
# Created: 24-Sept-2011
@@ -73,6 +72,8 @@ if __name__ == '__main__':
"""
# TODO: refactor to just use make-new-unittest-file instead of duplicating it here...
unitteststub = """\
import imp_unittest, unittest
import wtc

64
bin/make-new-unittest-file.py Executable file
View File

@@ -0,0 +1,64 @@
#!/usr/bin/env python
#---------------------------------------------------------------------------
# Name: bin/make-new-unittest-file.py
# Author: Robin Dunn
#
# Created: 12-July-2012
# Copyright: (c) 2012 by Robin Dunn
# License: wxWindows License
#---------------------------------------------------------------------------
import os
import sys
script_dir = os.path.dirname(__file__)
root_dir = os.path.abspath(os.path.join(script_dir, ".."))
usage = "usage: %prog [options] name module"
unitteststub = """\
import imp_unittest, unittest
import wtc
import wx
#---------------------------------------------------------------------------
class %(name)s_Tests(wtc.WidgetTestCase):
# TODO: Remove this test and add real ones.
def test_%(name)s1(self):
self.fail("Unit tests for %(name)s not implemented yet.")
#---------------------------------------------------------------------------
if __name__ == '__main__':
unittest.main()
"""
def main(args):
if not args:
print("usage: %s names" % __file__)
return
for name in args:
writeFile(
os.path.join(root_dir, "unittests", "test_%s.py" % name),
unitteststub, dict(name=name))
def writeFile(filename, stub, values):
if os.path.exists(filename):
print("'%s' already exists. Exiting." % filename)
sys.exit(1)
output = open(filename, 'w')
output.write(stub % values)
output.close()
print("Wrote %s" % filename)
if __name__ == '__main__':
main(sys.argv[1:])