From 780768ec1e8bbd3aa68de385b1abe8bb998690c2 Mon Sep 17 00:00:00 2001 From: Maurits van Rees Date: Wed, 16 Sep 2015 21:09:22 +0200 Subject: [PATCH 1/3] Create coverage report in Travis. Generate nosetests script also under the 'test' name. Then bin/createcoverage works. In Travis call the new correct script names: - The new bin/test is the old bin/nosetests. - The new bin/test-plone_addon is the old bin/test. Created bin/alltests script. This runs bin/test, and the two test-plone_addon scripts. We could call that in Travis too. Added initial simple test to show coverage in hooks.py. --- .coveragerc | 3 +++ .gitignore | 2 ++ .travis.yml | 3 ++- bobtemplates/plone_addon/.travis.yml.bob | 2 +- buildout.cfg | 22 +++++++++++++++++++++- tests.py | 8 ++++++++ travis.cfg | 5 +++++ 7 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 .coveragerc diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 00000000..35c83b8b --- /dev/null +++ b/.coveragerc @@ -0,0 +1,3 @@ +[report] +include = + bobtemplates/* diff --git a/.gitignore b/.gitignore index ab1d0a31..78759fff 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ *.egg-info *.mo *.pyc +.coverage .installed.cfg .mr.developer.cfg .project @@ -11,6 +12,7 @@ bin/ buildout-cache/ develop-eggs/ eggs/ +htmlcov/ include/ lib/ local/ diff --git a/.travis.yml b/.travis.yml index b5719478..58a3af5d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -39,10 +39,11 @@ before_script: script: - bin/check-readme - bin/code-analysis - - bin/nosetests - bin/test + - bin/test-plone_addon after_success: + - bin/createcoverage - pip install -q coveralls - coveralls diff --git a/bobtemplates/plone_addon/.travis.yml.bob b/bobtemplates/plone_addon/.travis.yml.bob index ebefdf35..40cf010f 100644 --- a/bobtemplates/plone_addon/.travis.yml.bob +++ b/bobtemplates/plone_addon/.travis.yml.bob @@ -18,8 +18,8 @@ install: script: - bin/code-analysis - bin/test - - bin/createcoverage after_success: + - bin/createcoverage - pip install coveralls - coveralls diff --git a/buildout.cfg b/buildout.cfg index 27b2ff82..db03bc14 100644 --- a/buildout.cfg +++ b/buildout.cfg @@ -2,7 +2,9 @@ parts = scripts test + test-plone_addon test-plone_addon-nested + alltests code-analysis releaser check-readme @@ -20,10 +22,17 @@ eggs = [test] +# This section is only here to generate the nosetests script a second +# time under a different name: 'test'. +<= scripts +scripts = nosetests=test + + +[test-plone_addon] recipe = collective.recipe.template addon_name = test.plone_addon input = addon_test.template.sh -output = ${buildout:directory}/bin/test +output = ${buildout:directory}/bin/test-plone_addon mode = 755 @@ -35,6 +44,17 @@ output = ${buildout:directory}/bin/test-plone_addon-nested mode = 755 +[alltests] +recipe = collective.recipe.template +input = inline: + #!/bin/sh + bin/test + bin/test-plone_addon + bin/test-plone_addon-nested +output = ${buildout:directory}/bin/alltests +mode = 755 + + [code-analysis] recipe = plone.recipe.codeanalysis directory = ${buildout:directory} diff --git a/tests.py b/tests.py index 05f98656..cc60daa9 100644 --- a/tests.py +++ b/tests.py @@ -4,6 +4,7 @@ import tempfile import shutil +from bobtemplates import hooks from scripttest import TestFileEnvironment @@ -170,3 +171,10 @@ def test_plone_addon_nested_template(self): self.project + '/.gitattributes', ] ) + + +class HooksTest(unittest.TestCase): + + def test_to_boolean(self): + # Initial simple test to show coverage in hooks.py. + self.assertEqual(hooks.to_boolean(None, None, 'y'), True) diff --git a/travis.cfg b/travis.cfg index f343b2a8..a1ab97b9 100644 --- a/travis.cfg +++ b/travis.cfg @@ -1,7 +1,12 @@ [buildout] extends = buildout.cfg +parts += createcoverage [code-analysis] recipe = plone.recipe.codeanalysis pre-commit-hook = False return-status-codes = True + +[createcoverage] +recipe = zc.recipe.egg +eggs = createcoverage From f1a21789fc5ea00ed87dcfc45d7cb38fa63909bd Mon Sep 17 00:00:00 2001 From: Maurits van Rees Date: Thu, 17 Sep 2015 13:08:16 +0200 Subject: [PATCH 2/3] Save the exit code of the test command and return it. --- addon_test.template.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/addon_test.template.sh b/addon_test.template.sh index f50c44eb..10340a04 100644 --- a/addon_test.template.sh +++ b/addon_test.template.sh @@ -14,7 +14,14 @@ ${buildout:directory}/${:addon_name}/bin/buildout # run tests on addon ${buildout:directory}/${:addon_name}/bin/test --all +# save the exit code of the test command +testresult=$? + +# run code analysis ${buildout:directory}/${:addon_name}/bin/code-analysis # remove addon rm -rf ${buildout:directory}/${:addon_name}/ + +# return the exit code of the test command +exit $testresult From 88cefb593c72104b086870367dae453052b39bdc Mon Sep 17 00:00:00 2001 From: Maurits van Rees Date: Thu, 17 Sep 2015 13:10:01 +0200 Subject: [PATCH 3/3] Fixed typo: Dextrity -> Dexterity --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 58a3af5d..b3dc55df 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,7 +29,7 @@ install: - pip install docutils - sed -ie "s/^plone.version.*/plone.version = $PLONE_VERSION/g" test_answers.ini - sed -ie "s/^package.type.*/package.type = $PACKAGE_TYPE/g" test_answers.ini - - if [ "$PACKAGE_TYPE" == "Dexterity" ]; then echo "package.dexterity_type_name = MyDextrityTestType" >> test_answers.ini; fi + - if [ "$PACKAGE_TYPE" == "Dexterity" ]; then echo "package.dexterity_type_name = MyDexterityTestType" >> test_answers.ini; fi - bin/buildout -c travis.cfg before_script: