[Checkins] SVN: gocept.selenium/branches/gotcha-generator/ add first tests
Godefroid Chapelle
gotcha at bubblenet.be
Tue Jan 4 09:36:22 EST 2011
Log message for revision 119346:
add first tests
Changed:
U gocept.selenium/branches/gotcha-generator/plonetesting-plone3.cfg
U gocept.selenium/branches/gotcha-generator/setup.py
U gocept.selenium/branches/gotcha-generator/src/gocept/selenium/scripts/converthtmltests.py
A gocept.selenium/branches/gotcha-generator/src/gocept/selenium/scripts/tests/test_converthtmltests.py
-=-
Modified: gocept.selenium/branches/gotcha-generator/plonetesting-plone3.cfg
===================================================================
--- gocept.selenium/branches/gotcha-generator/plonetesting-plone3.cfg 2011-01-04 14:34:30 UTC (rev 119345)
+++ gocept.selenium/branches/gotcha-generator/plonetesting-plone3.cfg 2011-01-04 14:36:22 UTC (rev 119346)
@@ -19,7 +19,9 @@
[test]
defaults = ['-s', 'gocept.selenium.plonetesting.tests.plone3',
+ '-s', 'gocept.selenium.scripts.tests',
'--tests-pattern', 'test_']
+eggs += gocept.selenium [test_script]
extra-paths = ${zope2:location}/lib/python
[omelette]
Modified: gocept.selenium/branches/gotcha-generator/setup.py
===================================================================
--- gocept.selenium/branches/gotcha-generator/setup.py 2011-01-04 14:34:30 UTC (rev 119345)
+++ gocept.selenium/branches/gotcha-generator/setup.py 2011-01-04 14:36:22 UTC (rev 119346)
@@ -81,6 +81,9 @@
script=[
'elementtree',
],
+ test_script=[
+ 'mock',
+ ],
),
entry_points={
'console_scripts': [
Modified: gocept.selenium/branches/gotcha-generator/src/gocept/selenium/scripts/converthtmltests.py
===================================================================
--- gocept.selenium/branches/gotcha-generator/src/gocept/selenium/scripts/converthtmltests.py 2011-01-04 14:34:30 UTC (rev 119345)
+++ gocept.selenium/branches/gotcha-generator/src/gocept/selenium/scripts/converthtmltests.py 2011-01-04 14:36:22 UTC (rev 119346)
@@ -52,13 +52,13 @@
return ' selenium.%s(%s)' % (command, ', '.join(arguments))
-def parse_options():
+def make_parser():
parser = OptionParser(usage="generatetests -l LAYER [options] directory",
version="%prog 1.0")
parser.add_option("-f", "--file", dest="target",
- default="tests_all_selenium.py",
- help="write tests to OUTPUT", metavar="FILE")
- parser.add_option("-l", "--layer", dest="layer",
+ default=DEFAULT_TARGET,
+ help="write tests to FILE", metavar="FILE")
+ parser.add_option("-l", "--layer", dest="layer", default=None,
help="full python import path to layer instance",
metavar="LAYER")
parser.add_option("-v", "--verbose",
@@ -67,24 +67,37 @@
parser.add_option("-q", "--quiet",
action="store_false", dest="verbose", default=True,
help="do not print progress messages to stdout")
+ return parser
- options, args = parser.parse_args()
- if not args:
- parser.error('source directory is required')
+DEFAULT_TARGET = 'tests_all_selenium.py'
+LAYER_REQUIRED = 'Layer (-l) argument is required.'
+DIRECTORY_REQUIRED = 'Source directory is required.'
+LAYER_WITH_MODULE = 'Layer (-l) should include a module.'
+ONE_DIRECTORY = 'Only one source directory should be provided.'
+DIRECTORY_NOT_EXIST = 'Source directory does not exist.'
+
+
+def parse_options(parser, args=None):
+ directory = ''
+ options, args = parser.parse_args(args=args)
+ if not options.layer:
+ parser.error(LAYER_REQUIRED)
+ elif not args:
+ parser.error(DIRECTORY_REQUIRED)
+ elif len(options.layer.split('.')) <= 1:
+ parser.error(LAYER_WITH_MODULE)
elif len(args) > 1:
- parser.error('only one source directory should be provided')
- if not options.layer:
- parser.error('layer is required')
- if len(options.layer.split('.')) <= 1:
- parser.error('layer option should include the module')
- directory = os.path.abspath(args[0])
- if not os.path.exists(directory):
- parser.error('directory [%s] does not exist')
+ parser.error(ONE_DIRECTORY)
+ else:
+ directory = os.path.abspath(args[0])
+ if not os.path.exists(directory):
+ parser.error(DIRECTORY_NOT_EXIST)
return options, directory
def main():
- options, directory = parse_options()
+ parser = make_parser()
+ options, directory = parse_options(parser)
tests = []
pattern = os.path.join(directory, '*.html')
for filename in glob.glob(pattern):
Added: gocept.selenium/branches/gotcha-generator/src/gocept/selenium/scripts/tests/test_converthtmltests.py
===================================================================
--- gocept.selenium/branches/gotcha-generator/src/gocept/selenium/scripts/tests/test_converthtmltests.py (rev 0)
+++ gocept.selenium/branches/gotcha-generator/src/gocept/selenium/scripts/tests/test_converthtmltests.py 2011-01-04 14:36:22 UTC (rev 119346)
@@ -0,0 +1,95 @@
+import unittest
+import mock
+import tempfile
+
+
+class TestConversion(unittest.TestCase):
+
+ def test_parse_options_no_layer(self):
+ from gocept.selenium.scripts.converthtmltests import parse_options
+ from gocept.selenium.scripts.converthtmltests import make_parser
+ from gocept.selenium.scripts.converthtmltests import LAYER_REQUIRED
+ parser = make_parser()
+ parser.error = mock.Mock()
+ parse_options(parser, [])
+ self.failUnless(parser.error.called)
+ parser.error.assert_called_with(LAYER_REQUIRED)
+
+ def test_parse_options_no_directory(self):
+ from gocept.selenium.scripts.converthtmltests import parse_options
+ from gocept.selenium.scripts.converthtmltests import make_parser
+ from gocept.selenium.scripts.converthtmltests import DIRECTORY_REQUIRED
+ parser = make_parser()
+ parser.error = mock.Mock()
+ parse_options(parser, ['-l', 'module.layer'])
+ self.failUnless(parser.error.called)
+ parser.error.assert_called_with(DIRECTORY_REQUIRED)
+
+ def test_parse_options_no_module(self):
+ from gocept.selenium.scripts.converthtmltests import parse_options
+ from gocept.selenium.scripts.converthtmltests import make_parser
+ from gocept.selenium.scripts.converthtmltests import LAYER_WITH_MODULE
+ parser = make_parser()
+ parser.error = mock.Mock()
+ parse_options(parser, ['-l', 'layer', 'dummy'])
+ self.failUnless(parser.error.called)
+ parser.error.assert_called_with(LAYER_WITH_MODULE)
+
+ def test_parse_options_one_directory(self):
+ from gocept.selenium.scripts.converthtmltests import parse_options
+ from gocept.selenium.scripts.converthtmltests import make_parser
+ from gocept.selenium.scripts.converthtmltests import ONE_DIRECTORY
+ parser = make_parser()
+ parser.error = mock.Mock()
+ parse_options(parser, ['-l', 'module.layer', 'first', 'second'])
+ self.failUnless(parser.error.called)
+ parser.error.assert_called_with(ONE_DIRECTORY)
+
+ def test_parse_options_directory_not_exist(self):
+ from gocept.selenium.scripts.converthtmltests import parse_options
+ from gocept.selenium.scripts.converthtmltests import make_parser
+ from gocept.selenium.scripts.converthtmltests import (
+ DIRECTORY_NOT_EXIST)
+ parser = make_parser()
+ parser.error = mock.Mock()
+ parse_options(parser, ['-l', 'module.layer', 'first'])
+ self.failUnless(parser.error.called)
+ parser.error.assert_called_with(DIRECTORY_NOT_EXIST)
+
+ def test_parse_options_directory_exists(self):
+ from gocept.selenium.scripts.converthtmltests import parse_options
+ from gocept.selenium.scripts.converthtmltests import make_parser
+ from gocept.selenium.scripts.converthtmltests import DEFAULT_TARGET
+ parser = make_parser()
+ parser.error = mock.Mock()
+ source = tempfile.gettempdir()
+ layer = 'module.layer'
+ options, directory = parse_options(parser,
+ ['-l', layer, source])
+ self.assertEquals(source, directory)
+ self.assertEquals(options.layer, layer)
+ self.assertEquals(options.target, DEFAULT_TARGET)
+ self.failUnless(options.verbose)
+
+ def test_parse_options_quiet(self):
+ from gocept.selenium.scripts.converthtmltests import parse_options
+ from gocept.selenium.scripts.converthtmltests import make_parser
+ parser = make_parser()
+ parser.error = mock.Mock()
+ source = tempfile.mkdtemp()
+ layer = 'module.layer'
+ options, directory = parse_options(parser,
+ ['-q', '-l', layer, source])
+ self.failIf(options.verbose)
+
+ def test_parse_options_target(self):
+ from gocept.selenium.scripts.converthtmltests import parse_options
+ from gocept.selenium.scripts.converthtmltests import make_parser
+ parser = make_parser()
+ parser.error = mock.Mock()
+ source = tempfile.mkdtemp()
+ target = tempfile.mktemp()
+ layer = 'module.layer'
+ options, directory = parse_options(parser,
+ ['-f', target, '-l', layer, source])
+ self.assertEquals(options.target, target)
More information about the checkins
mailing list