From 7033faf18c2ed048d2b6b702e0bc9109055d22db Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Mon, 5 Nov 2012 10:58:25 -0500 Subject: [PATCH 01/16] Don't show stdout from collectstatic during tests. --- rakefile | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/rakefile b/rakefile index 30716ca365..73b0c0fd83 100644 --- a/rakefile +++ b/rakefile @@ -134,7 +134,11 @@ TEST_TASKS = [] desc "Run collectstatic in the specified environment" task "#{system}:collectstatic:#{env}" => :predjango do - sh("#{django_admin(system, env, 'collectstatic', '--noinput')}") + sh("#{django_admin(system, env, 'collectstatic', '--noinput')} > /tmp/collectstatic.out") do |ok, status| + if !ok + abort "collectstatic failed!" + end + end end end end @@ -270,4 +274,4 @@ task :doc => :builddocs do Dir.chdir('docs/build/html') do sh('open index.html') end -end \ No newline at end of file +end From 7eb196df38a566328b85c83e4bebffa2e510fe9e Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Tue, 6 Nov 2012 16:44:32 -0500 Subject: [PATCH 02/16] Run coverage directly instead of as a plugin. Also quiet the install and clean steps of tests. --- cms/envs/test.py | 3 --- lms/envs/test.py | 14 ++++---------- rakefile | 18 +++++++++++++----- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/cms/envs/test.py b/cms/envs/test.py index 7dcd32caab..08b25346be 100644 --- a/cms/envs/test.py +++ b/cms/envs/test.py @@ -14,9 +14,6 @@ from path import path # Nose Test Runner INSTALLED_APPS += ('django_nose',) -NOSE_ARGS = ['--cover-erase', '--with-xunit', '--with-xcoverage', '--cover-html', '--cover-inclusive'] -for app in os.listdir(PROJECT_ROOT / 'djangoapps'): - NOSE_ARGS += ['--cover-package', app] TEST_RUNNER = 'django_nose.NoseTestSuiteRunner' TEST_ROOT = path('test_root') diff --git a/lms/envs/test.py b/lms/envs/test.py index bad680077b..01abce9f5a 100644 --- a/lms/envs/test.py +++ b/lms/envs/test.py @@ -29,16 +29,10 @@ SOUTH_TESTS_MIGRATE = False # To disable migrations and use syncdb instead INSTALLED_APPS += ('django_nose',) NOSE_ARGS = [] -# Turning off coverage speeds up tests dramatically... until we have better config, -# leave it here for manual fiddling. -_coverage = True -if _coverage: - NOSE_ARGS = ['--cover-erase', '--with-xunit', '--with-xcoverage', '--cover-html', - # '-v', '--pdb', # When really stuck, uncomment to start debugger on error - '--cover-inclusive', '--cover-html-dir', - os.environ.get('NOSE_COVER_HTML_DIR', 'cover_html')] - for app in os.listdir(PROJECT_ROOT / 'djangoapps'): - NOSE_ARGS += ['--cover-package', app] +NOSE_ARGS = [ + '--with-xunit', + # '-v', '--pdb', # When really stuck, uncomment to start debugger on error +] TEST_RUNNER = 'django_nose.NoseTestSuiteRunner' # Local Directories diff --git a/rakefile b/rakefile index 73b0c0fd83..8ada145b18 100644 --- a/rakefile +++ b/rakefile @@ -49,12 +49,12 @@ default_options = { task :predjango do sh("find . -type f -name *.pyc -delete") - sh('pip install -e common/lib/xmodule -e common/lib/capa') - sh('git submodule update --init') + sh("pip install -q -e common/lib/xmodule -e common/lib/capa") + sh("git submodule update --init") end task :clean_test_files do - sh("git clean -fdx test_root") + sh("git clean -fqdx test_root") end [:lms, :cms, :common].each do |system| @@ -84,11 +84,18 @@ end $failed_tests = 0 +def run_under_coverage(cmd) + cmd0, cmd_rest = cmd.split(" ", 2) + cmd = "coverage run `which #{cmd0}` #{cmd_rest}" + return cmd +end + def run_tests(system, report_dir, stop_on_failure=true) ENV['NOSE_XUNIT_FILE'] = File.join(report_dir, "nosetests.xml") ENV['NOSE_COVER_HTML_DIR'] = File.join(report_dir, "cover") dirs = Dir["common/djangoapps/*"] + Dir["#{system}/djangoapps/*"] - sh(django_admin(system, :test, 'test', *dirs.each)) do |ok, res| + cmd = django_admin(system, :test, 'test', '--logging-clear-handlers', *dirs.each) + sh(run_under_coverage(cmd)) do |ok, res| if !ok and stop_on_failure abort "Test failed!" end @@ -152,7 +159,8 @@ Dir["common/lib/*"].each do |lib| desc "Run tests for common lib #{lib}" task task_name => report_dir do ENV['NOSE_XUNIT_FILE'] = File.join(report_dir, "nosetests.xml") - sh("nosetests #{lib} --cover-erase --with-xunit --with-xcoverage --cover-html --cover-inclusive --cover-package #{File.basename(lib)} --cover-html-dir #{File.join(report_dir, "cover")}") + cmd = "nosetests #{lib} --logging-clear-handlers --with-xunit" + sh(run_under_coverage(cmd)) end TEST_TASKS << task_name From 90e33867518b87e1e2ca340f68d34fceebd77680 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Wed, 7 Nov 2012 10:45:45 -0500 Subject: [PATCH 03/16] WIP for quieter tests with coverage. --- cms/.coveragerc | 9 +++++++++ cms/envs/test.py | 1 + common/lib/capa/.coveragerc | 9 +++++++++ common/lib/xmodule/.coveragerc | 9 +++++++++ lms/.coveragerc | 9 +++++++++ lms/envs/test.py | 1 - rakefile | 33 +++++++++++++++++++++------------ 7 files changed, 58 insertions(+), 13 deletions(-) create mode 100644 cms/.coveragerc create mode 100644 common/lib/capa/.coveragerc create mode 100644 common/lib/xmodule/.coveragerc create mode 100644 lms/.coveragerc diff --git a/cms/.coveragerc b/cms/.coveragerc new file mode 100644 index 0000000000..fe84c60bdc --- /dev/null +++ b/cms/.coveragerc @@ -0,0 +1,9 @@ +# .coveragerc for cms +[report] +ignore_errors = True + +[html] +directory = reports/cms/cover + +[xml] +output = reports/cms/coverage.xml diff --git a/cms/envs/test.py b/cms/envs/test.py index 08b25346be..d55c309827 100644 --- a/cms/envs/test.py +++ b/cms/envs/test.py @@ -14,6 +14,7 @@ from path import path # Nose Test Runner INSTALLED_APPS += ('django_nose',) +NOSE_ARGS = ['--with-xunit'] TEST_RUNNER = 'django_nose.NoseTestSuiteRunner' TEST_ROOT = path('test_root') diff --git a/common/lib/capa/.coveragerc b/common/lib/capa/.coveragerc new file mode 100644 index 0000000000..726675d448 --- /dev/null +++ b/common/lib/capa/.coveragerc @@ -0,0 +1,9 @@ +# .coveragerc for common/lib/capa +[report] +ignore_errors = True + +[html] +directory = reports/common/lib/capa/cover + +[xml] +output = reports/common/lib/capa/coverage.xml diff --git a/common/lib/xmodule/.coveragerc b/common/lib/xmodule/.coveragerc new file mode 100644 index 0000000000..4d5a3c286d --- /dev/null +++ b/common/lib/xmodule/.coveragerc @@ -0,0 +1,9 @@ +# .coveragerc for common/lib/xmodule +[report] +ignore_errors = True + +[html] +directory = reports/common/xmodule/capa/cover + +[xml] +output = reports/common/lib/xmodule/coverage.xml diff --git a/lms/.coveragerc b/lms/.coveragerc new file mode 100644 index 0000000000..84d6e74e4c --- /dev/null +++ b/lms/.coveragerc @@ -0,0 +1,9 @@ +# .coveragerc for cms +[report] +ignore_errors = True + +[html] +directory = reports/lms/cover + +[xml] +output = reports/lms/coverage.xml diff --git a/lms/envs/test.py b/lms/envs/test.py index 01abce9f5a..e11946a47a 100644 --- a/lms/envs/test.py +++ b/lms/envs/test.py @@ -27,7 +27,6 @@ SOUTH_TESTS_MIGRATE = False # To disable migrations and use syncdb instead # Nose Test Runner INSTALLED_APPS += ('django_nose',) -NOSE_ARGS = [] NOSE_ARGS = [ '--with-xunit', diff --git a/rakefile b/rakefile index 8ada145b18..97ed5435bd 100644 --- a/rakefile +++ b/rakefile @@ -84,26 +84,33 @@ end $failed_tests = 0 -def run_under_coverage(cmd) +def run_under_coverage(cmd, root) cmd0, cmd_rest = cmd.split(" ", 2) - cmd = "coverage run `which #{cmd0}` #{cmd_rest}" + # We use "python -m coverage" so that the proper python will run the importable coverage + # rather than the coverage that OS path finds. + cmd = "python -m coverage run --rcfile=#{root}/.coveragerc `which #{cmd0}` #{cmd_rest}" return cmd end +def coverage_reports(root) + sh("coverage xml --rcfile=#{root}/.coveragerc") + sh("coverage html --rcfile=#{root}/.coveragerc") +end + def run_tests(system, report_dir, stop_on_failure=true) ENV['NOSE_XUNIT_FILE'] = File.join(report_dir, "nosetests.xml") - ENV['NOSE_COVER_HTML_DIR'] = File.join(report_dir, "cover") dirs = Dir["common/djangoapps/*"] + Dir["#{system}/djangoapps/*"] cmd = django_admin(system, :test, 'test', '--logging-clear-handlers', *dirs.each) - sh(run_under_coverage(cmd)) do |ok, res| + sh(run_under_coverage(cmd, system)) do |ok, res| if !ok and stop_on_failure abort "Test failed!" end $failed_tests += 1 unless ok end + coverage_reports(system) end -TEST_TASKS = [] +TEST_TASK_SYMBOLS = [] [:lms, :cms].each do |system| report_dir = File.join(REPORT_DIR, system.to_s) @@ -120,7 +127,7 @@ TEST_TASKS = [] run_tests(system, report_dir, args.stop_on_failure) end - TEST_TASKS << "test_#{system}" + TEST_TASK_SYMBOLS << system desc <<-desc Start the #{system} locally with the specified environment (defaults to dev). @@ -150,7 +157,7 @@ TEST_TASKS = [] end end -Dir["common/lib/*"].each do |lib| +Dir["common/lib/*"].select{|lib| File.directory?(lib)}.each do |lib| task_name = "test_#{lib}" report_dir = File.join(REPORT_DIR, task_name.gsub('/', '_')) @@ -160,21 +167,23 @@ Dir["common/lib/*"].each do |lib| task task_name => report_dir do ENV['NOSE_XUNIT_FILE'] = File.join(report_dir, "nosetests.xml") cmd = "nosetests #{lib} --logging-clear-handlers --with-xunit" - sh(run_under_coverage(cmd)) + sh(run_under_coverage(cmd, lib)) do |ok, res| + $failed_tests += 1 unless ok + end + coverage_reports(lib) end - TEST_TASKS << task_name + TEST_TASK_SYMBOLS << lib desc "Run tests for common lib #{lib} (without coverage)" task "fasttest_#{lib}" do sh("nosetests #{lib}") end - end task :test do - TEST_TASKS.each do |task| - Rake::Task[task].invoke(false) + TEST_TASK_SYMBOLS.each do |sym| + Rake::Task["test_#{sym}"].invoke(false) end if $failed_tests > 0 From 6b28b70e51293637c006f8bd5dddeda5b57db621 Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Tue, 6 Nov 2012 16:12:19 -0500 Subject: [PATCH 04/16] Add jenkins files for builds --- jenkins/quality.sh | 11 +++++++++++ jenkins/test_edge.sh | 28 ++++++++++++++++++++++++++++ jenkins/test_lms.sh | 26 ++++++++++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100755 jenkins/quality.sh create mode 100755 jenkins/test_edge.sh create mode 100755 jenkins/test_lms.sh diff --git a/jenkins/quality.sh b/jenkins/quality.sh new file mode 100755 index 0000000000..2cfea7a760 --- /dev/null +++ b/jenkins/quality.sh @@ -0,0 +1,11 @@ +#! /bin/bash + +# Reset the submodule, in case it changed +git submodule foreach 'git reset --hard HEAD' + +# Set the IO encoding to UTF-8 so that askbot will start +export PYTHONIOENCODING=UTF-8 + +rake clobber +rake pep8 || echo "pep8 failed, continuing" +rake pylint || echo "pylint failed, continuing" \ No newline at end of file diff --git a/jenkins/test_edge.sh b/jenkins/test_edge.sh new file mode 100755 index 0000000000..1896e58c55 --- /dev/null +++ b/jenkins/test_edge.sh @@ -0,0 +1,28 @@ +#! /bin/bash + +# Reset the submodule, in case it changed +git submodule foreach 'git reset --hard HEAD' + +# Set the IO encoding to UTF-8 so that askbot will start +export PYTHONIOENCODING=UTF-8 + +GIT_BRANCH=${GIT_BRANCH/HEAD/master} + +pip install -r pre-requirements.txt +yes w | pip install -r requirements.txt +[ ! -d askbot ] || pip install -r askbot/askbot_requirements.txt + +# Install the latest entry points from xmodule +pip install --upgrade -e common/lib/xmodule + +rake clobber +TESTS_FAILED=0 +rake test_cms[false] || TESTS_FAILED=1 +rake test_lms[false] || TESTS_FAILED=1 +rake test_common/lib/capa || TESTS_FAILED=1 +rake test_common/lib/xmodule || TESTS_FAILED=1 +rake phantomjs_jasmine_lms || true +rake phantomjs_jasmine_cms || true + +[ $TESTS_FAILED == '0' ] +rake autodeploy_properties \ No newline at end of file diff --git a/jenkins/test_lms.sh b/jenkins/test_lms.sh new file mode 100755 index 0000000000..59a141831d --- /dev/null +++ b/jenkins/test_lms.sh @@ -0,0 +1,26 @@ +#! /bin/bash + +# Reset the submodule, in case it changed +git submodule foreach 'git reset --hard HEAD' + +# Set the IO encoding to UTF-8 so that askbot will start +export PYTHONIOENCODING=UTF-8 + +GIT_BRANCH=${GIT_BRANCH/HEAD/master} + +pip install -r pre-requirements.txt +yes w | pip install -r requirements.txt +[ ! -d askbot ] || pip install -r askbot/askbot_requirements.txt + +# Install the latest entry points from xmodule +pip install --upgrade -e common/lib/xmodule + +rake clobber +TESTS_FAILED=0 +rake test_lms[false] || TESTS_FAILED=1 +rake test_common/lib/capa || TESTS_FAILED=1 +rake test_common/lib/xmodule || TESTS_FAILED=1 +rake phantomjs_jasmine_cms || true + +[ $TESTS_FAILED == '0' ] +rake autodeploy_properties \ No newline at end of file From 2a457bdc0fb5d44c16cc597de15f10b0cbc740ff Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Wed, 7 Nov 2012 08:48:44 -0500 Subject: [PATCH 05/16] Set -e and -x on jenkins build scripts --- jenkins/quality.sh | 5 ++++- jenkins/test_edge.sh | 3 +++ jenkins/test_lms.sh | 3 +++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/jenkins/quality.sh b/jenkins/quality.sh index 2cfea7a760..4cf26d76bf 100755 --- a/jenkins/quality.sh +++ b/jenkins/quality.sh @@ -1,5 +1,8 @@ #! /bin/bash +set -e +set -x + # Reset the submodule, in case it changed git submodule foreach 'git reset --hard HEAD' @@ -8,4 +11,4 @@ export PYTHONIOENCODING=UTF-8 rake clobber rake pep8 || echo "pep8 failed, continuing" -rake pylint || echo "pylint failed, continuing" \ No newline at end of file +rake pylint || echo "pylint failed, continuing" diff --git a/jenkins/test_edge.sh b/jenkins/test_edge.sh index 1896e58c55..12a8bd2189 100755 --- a/jenkins/test_edge.sh +++ b/jenkins/test_edge.sh @@ -1,5 +1,8 @@ #! /bin/bash +set -e +set -x + # Reset the submodule, in case it changed git submodule foreach 'git reset --hard HEAD' diff --git a/jenkins/test_lms.sh b/jenkins/test_lms.sh index 59a141831d..c24d75991b 100755 --- a/jenkins/test_lms.sh +++ b/jenkins/test_lms.sh @@ -1,5 +1,8 @@ #! /bin/bash +set -e +set -x + # Reset the submodule, in case it changed git submodule foreach 'git reset --hard HEAD' From 79a08266addf3cf93b73064704a7b2569f2d6feb Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Wed, 7 Nov 2012 08:51:05 -0500 Subject: [PATCH 06/16] Make pip install during jenkins builds quieter --- jenkins/test_edge.sh | 8 ++++---- jenkins/test_lms.sh | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/jenkins/test_edge.sh b/jenkins/test_edge.sh index 12a8bd2189..66a1185989 100755 --- a/jenkins/test_edge.sh +++ b/jenkins/test_edge.sh @@ -11,12 +11,12 @@ export PYTHONIOENCODING=UTF-8 GIT_BRANCH=${GIT_BRANCH/HEAD/master} -pip install -r pre-requirements.txt -yes w | pip install -r requirements.txt -[ ! -d askbot ] || pip install -r askbot/askbot_requirements.txt +pip install -q -r pre-requirements.txt +yes w | pip install -q -r requirements.txt +[ ! -d askbot ] || pip install -q -r askbot/askbot_requirements.txt # Install the latest entry points from xmodule -pip install --upgrade -e common/lib/xmodule +pip install -q --upgrade -e common/lib/xmodule rake clobber TESTS_FAILED=0 diff --git a/jenkins/test_lms.sh b/jenkins/test_lms.sh index c24d75991b..d95ee689cb 100755 --- a/jenkins/test_lms.sh +++ b/jenkins/test_lms.sh @@ -11,12 +11,12 @@ export PYTHONIOENCODING=UTF-8 GIT_BRANCH=${GIT_BRANCH/HEAD/master} -pip install -r pre-requirements.txt -yes w | pip install -r requirements.txt -[ ! -d askbot ] || pip install -r askbot/askbot_requirements.txt +pip install -q -r pre-requirements.txt +yes w | pip install -q -r requirements.txt +[ ! -d askbot ] || pip install -q -r askbot/askbot_requirements.txt # Install the latest entry points from xmodule -pip install --upgrade -e common/lib/xmodule +pip install -q --upgrade -e common/lib/xmodule rake clobber TESTS_FAILED=0 From c3f0d31cc960c592cb67b6394c9838b0952ecf44 Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Wed, 7 Nov 2012 10:08:01 -0500 Subject: [PATCH 07/16] Split out requirements that come from the local mitx repo and those that come from github, and upgrade the local requirements before running tests --- github-requirements.txt | 5 +++++ jenkins/test_edge.sh | 3 --- jenkins/test_lms.sh | 3 --- local-requirements.txt | 3 +++ rakefile | 4 ++-- repo-requirements.txt | 8 ++------ 6 files changed, 12 insertions(+), 14 deletions(-) create mode 100644 github-requirements.txt create mode 100644 local-requirements.txt diff --git a/github-requirements.txt b/github-requirements.txt new file mode 100644 index 0000000000..468d55ce65 --- /dev/null +++ b/github-requirements.txt @@ -0,0 +1,5 @@ +# Python libraries to install directly from github +-e git://github.com/MITx/django-staticfiles.git@6d2504e5c8#egg=django-staticfiles +-e git://github.com/MITx/django-pipeline.git#egg=django-pipeline +-e git://github.com/MITx/django-wiki.git@e2e84558#egg=django-wiki +-e git://github.com/dementrock/pystache_custom.git@776973740bdaad83a3b029f96e415a7d1e8bec2f#egg=pystache_custom-dev diff --git a/jenkins/test_edge.sh b/jenkins/test_edge.sh index 66a1185989..f66178914b 100755 --- a/jenkins/test_edge.sh +++ b/jenkins/test_edge.sh @@ -15,9 +15,6 @@ pip install -q -r pre-requirements.txt yes w | pip install -q -r requirements.txt [ ! -d askbot ] || pip install -q -r askbot/askbot_requirements.txt -# Install the latest entry points from xmodule -pip install -q --upgrade -e common/lib/xmodule - rake clobber TESTS_FAILED=0 rake test_cms[false] || TESTS_FAILED=1 diff --git a/jenkins/test_lms.sh b/jenkins/test_lms.sh index d95ee689cb..90cc1dde13 100755 --- a/jenkins/test_lms.sh +++ b/jenkins/test_lms.sh @@ -15,9 +15,6 @@ pip install -q -r pre-requirements.txt yes w | pip install -q -r requirements.txt [ ! -d askbot ] || pip install -q -r askbot/askbot_requirements.txt -# Install the latest entry points from xmodule -pip install -q --upgrade -e common/lib/xmodule - rake clobber TESTS_FAILED=0 rake test_lms[false] || TESTS_FAILED=1 diff --git a/local-requirements.txt b/local-requirements.txt new file mode 100644 index 0000000000..a4d153dd36 --- /dev/null +++ b/local-requirements.txt @@ -0,0 +1,3 @@ +# Python libraries to install that are local to the mitx repo +-e common/lib/capa +-e common/lib/xmodule diff --git a/rakefile b/rakefile index 97ed5435bd..3bf4f342f2 100644 --- a/rakefile +++ b/rakefile @@ -49,8 +49,8 @@ default_options = { task :predjango do sh("find . -type f -name *.pyc -delete") - sh("pip install -q -e common/lib/xmodule -e common/lib/capa") - sh("git submodule update --init") + sh('pip install -q --upgrade -r local-requirements.txt') + sh('git submodule update --init') end task :clean_test_files do diff --git a/repo-requirements.txt b/repo-requirements.txt index f98d05ffc9..aa503e9779 100644 --- a/repo-requirements.txt +++ b/repo-requirements.txt @@ -1,6 +1,2 @@ --e git://github.com/MITx/django-staticfiles.git@6d2504e5c8#egg=django-staticfiles --e git://github.com/MITx/django-pipeline.git#egg=django-pipeline --e git://github.com/MITx/django-wiki.git@e2e84558#egg=django-wiki --e git://github.com/dementrock/pystache_custom.git@776973740bdaad83a3b029f96e415a7d1e8bec2f#egg=pystache_custom-dev --e common/lib/capa --e common/lib/xmodule +-r github-requirements.txt +-r local-requirements.txt \ No newline at end of file From 3dc23eb131c7c9592d980fa5935c6c5312bf334a Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Wed, 7 Nov 2012 17:01:29 -0500 Subject: [PATCH 08/16] Coverage xml and html reports are now a separate 'xml' and 'html' step from 'test'. --- cms/.coveragerc | 3 +++ common/lib/capa/.coveragerc | 3 +++ common/lib/xmodule/.coveragerc | 5 ++++- lms/.coveragerc | 5 ++++- rakefile | 30 ++++++++++++++++++------------ 5 files changed, 32 insertions(+), 14 deletions(-) diff --git a/cms/.coveragerc b/cms/.coveragerc index fe84c60bdc..268193f94a 100644 --- a/cms/.coveragerc +++ b/cms/.coveragerc @@ -1,4 +1,7 @@ # .coveragerc for cms +[run] +data_file = cms/.coverage + [report] ignore_errors = True diff --git a/common/lib/capa/.coveragerc b/common/lib/capa/.coveragerc index 726675d448..955a76294b 100644 --- a/common/lib/capa/.coveragerc +++ b/common/lib/capa/.coveragerc @@ -1,4 +1,7 @@ # .coveragerc for common/lib/capa +[run] +data_file = common/lib/capa/.coverage + [report] ignore_errors = True diff --git a/common/lib/xmodule/.coveragerc b/common/lib/xmodule/.coveragerc index 4d5a3c286d..c31a858749 100644 --- a/common/lib/xmodule/.coveragerc +++ b/common/lib/xmodule/.coveragerc @@ -1,9 +1,12 @@ # .coveragerc for common/lib/xmodule +[run] +data_file = common/lib/xmodule/.coverage + [report] ignore_errors = True [html] -directory = reports/common/xmodule/capa/cover +directory = reports/common/lib/xmodule/cover [xml] output = reports/common/lib/xmodule/coverage.xml diff --git a/lms/.coveragerc b/lms/.coveragerc index 84d6e74e4c..f41b79da68 100644 --- a/lms/.coveragerc +++ b/lms/.coveragerc @@ -1,4 +1,7 @@ -# .coveragerc for cms +# .coveragerc for lms +[run] +data_file = lms/.coverage + [report] ignore_errors = True diff --git a/rakefile b/rakefile index 3bf4f342f2..af22f5d7d4 100644 --- a/rakefile +++ b/rakefile @@ -92,11 +92,6 @@ def run_under_coverage(cmd, root) return cmd end -def coverage_reports(root) - sh("coverage xml --rcfile=#{root}/.coveragerc") - sh("coverage html --rcfile=#{root}/.coveragerc") -end - def run_tests(system, report_dir, stop_on_failure=true) ENV['NOSE_XUNIT_FILE'] = File.join(report_dir, "nosetests.xml") dirs = Dir["common/djangoapps/*"] + Dir["#{system}/djangoapps/*"] @@ -107,10 +102,9 @@ def run_tests(system, report_dir, stop_on_failure=true) end $failed_tests += 1 unless ok end - coverage_reports(system) end -TEST_TASK_SYMBOLS = [] +TEST_TASK_DIRS = [] [:lms, :cms].each do |system| report_dir = File.join(REPORT_DIR, system.to_s) @@ -127,7 +121,7 @@ TEST_TASK_SYMBOLS = [] run_tests(system, report_dir, args.stop_on_failure) end - TEST_TASK_SYMBOLS << system + TEST_TASK_DIRS << system desc <<-desc Start the #{system} locally with the specified environment (defaults to dev). @@ -170,9 +164,8 @@ Dir["common/lib/*"].select{|lib| File.directory?(lib)}.each do |lib| sh(run_under_coverage(cmd, lib)) do |ok, res| $failed_tests += 1 unless ok end - coverage_reports(lib) end - TEST_TASK_SYMBOLS << lib + TEST_TASK_DIRS << lib desc "Run tests for common lib #{lib} (without coverage)" task "fasttest_#{lib}" do @@ -182,8 +175,8 @@ Dir["common/lib/*"].select{|lib| File.directory?(lib)}.each do |lib| end task :test do - TEST_TASK_SYMBOLS.each do |sym| - Rake::Task["test_#{sym}"].invoke(false) + TEST_TASK_DIRS.each do |dir| + Rake::Task["test_#{dir}"].invoke(false) end if $failed_tests > 0 @@ -191,6 +184,19 @@ task :test do end end +task :html do + TEST_TASK_DIRS.each do |dir| + sh("coverage html --rcfile=#{dir}/.coveragerc") + end +end + +task :xml do + TEST_TASK_DIRS.each do |dir| + # Why doesn't the rcfile control the xml output file properly?? + sh("coverage xml -o reports/#{dir}/coverage.xml --rcfile=#{dir}/.coveragerc") + end +end + task :runserver => :lms desc "Run django-admin against the specified system and environment" From 899132a9bb21871db6952ba8527ec2cb53604c63 Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Wed, 7 Nov 2012 10:54:35 -0500 Subject: [PATCH 09/16] Force django to run using the python from the virtualenv --- rakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rakefile b/rakefile index af22f5d7d4..1a5d4d604e 100644 --- a/rakefile +++ b/rakefile @@ -35,7 +35,7 @@ end def django_admin(system, env, command, *args) django_admin = ENV['DJANGO_ADMIN_PATH'] || select_executable('django-admin.py', 'django-admin') - return "#{django_admin} #{command} --settings=#{system}.envs.#{env} --pythonpath=. #{args.join(' ')}" + return "python `which #{django_admin}` #{command} --settings=#{system}.envs.#{env} --pythonpath=. #{args.join(' ')}" end task :default => [:test, :pep8, :pylint] From 1968a1dde561298bd97d332477a8b1b519a357fd Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Thu, 8 Nov 2012 10:04:41 -0500 Subject: [PATCH 10/16] Remove attempt to use virtualenv python when running django-admin commands --- rakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rakefile b/rakefile index 1a5d4d604e..af22f5d7d4 100644 --- a/rakefile +++ b/rakefile @@ -35,7 +35,7 @@ end def django_admin(system, env, command, *args) django_admin = ENV['DJANGO_ADMIN_PATH'] || select_executable('django-admin.py', 'django-admin') - return "python `which #{django_admin}` #{command} --settings=#{system}.envs.#{env} --pythonpath=. #{args.join(' ')}" + return "#{django_admin} #{command} --settings=#{system}.envs.#{env} --pythonpath=. #{args.join(' ')}" end task :default => [:test, :pep8, :pylint] From 17570c4c067cb381b97cef56721e89b5687fd9a1 Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Thu, 8 Nov 2012 10:10:44 -0500 Subject: [PATCH 11/16] Create xml and html coverage reports --- jenkins/test_edge.sh | 1 + jenkins/test_lms.sh | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/jenkins/test_edge.sh b/jenkins/test_edge.sh index f66178914b..e33cef94fd 100755 --- a/jenkins/test_edge.sh +++ b/jenkins/test_edge.sh @@ -23,6 +23,7 @@ rake test_common/lib/capa || TESTS_FAILED=1 rake test_common/lib/xmodule || TESTS_FAILED=1 rake phantomjs_jasmine_lms || true rake phantomjs_jasmine_cms || true +rake xml html [ $TESTS_FAILED == '0' ] rake autodeploy_properties \ No newline at end of file diff --git a/jenkins/test_lms.sh b/jenkins/test_lms.sh index 90cc1dde13..b44e6b6f70 100755 --- a/jenkins/test_lms.sh +++ b/jenkins/test_lms.sh @@ -20,7 +20,8 @@ TESTS_FAILED=0 rake test_lms[false] || TESTS_FAILED=1 rake test_common/lib/capa || TESTS_FAILED=1 rake test_common/lib/xmodule || TESTS_FAILED=1 -rake phantomjs_jasmine_cms || true +rake phantomjs_jasmine_lms || true +rake xml html [ $TESTS_FAILED == '0' ] rake autodeploy_properties \ No newline at end of file From 0cf46f7636ce0d06386db82b53654a0540ae0ecd Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Thu, 8 Nov 2012 10:12:32 -0500 Subject: [PATCH 12/16] Namespace the coverage html and xml report generation tasks --- jenkins/test_edge.sh | 2 +- jenkins/test_lms.sh | 2 +- rakefile | 20 ++++++++++++-------- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/jenkins/test_edge.sh b/jenkins/test_edge.sh index e33cef94fd..7b58b481f6 100755 --- a/jenkins/test_edge.sh +++ b/jenkins/test_edge.sh @@ -23,7 +23,7 @@ rake test_common/lib/capa || TESTS_FAILED=1 rake test_common/lib/xmodule || TESTS_FAILED=1 rake phantomjs_jasmine_lms || true rake phantomjs_jasmine_cms || true -rake xml html +rake coverage:xml coverage:html [ $TESTS_FAILED == '0' ] rake autodeploy_properties \ No newline at end of file diff --git a/jenkins/test_lms.sh b/jenkins/test_lms.sh index b44e6b6f70..98640c2b5b 100755 --- a/jenkins/test_lms.sh +++ b/jenkins/test_lms.sh @@ -21,7 +21,7 @@ rake test_lms[false] || TESTS_FAILED=1 rake test_common/lib/capa || TESTS_FAILED=1 rake test_common/lib/xmodule || TESTS_FAILED=1 rake phantomjs_jasmine_lms || true -rake xml html +rake coverage:xml coverage:html [ $TESTS_FAILED == '0' ] rake autodeploy_properties \ No newline at end of file diff --git a/rakefile b/rakefile index af22f5d7d4..ad494d5ece 100644 --- a/rakefile +++ b/rakefile @@ -184,16 +184,20 @@ task :test do end end -task :html do - TEST_TASK_DIRS.each do |dir| - sh("coverage html --rcfile=#{dir}/.coveragerc") +namespace :coverage do + desc "Build the html coverage reports" + task :html do + TEST_TASK_DIRS.each do |dir| + sh("coverage html --rcfile=#{dir}/.coveragerc") + end end -end -task :xml do - TEST_TASK_DIRS.each do |dir| - # Why doesn't the rcfile control the xml output file properly?? - sh("coverage xml -o reports/#{dir}/coverage.xml --rcfile=#{dir}/.coveragerc") + desc "Build the xml coverage reports" + task :xml do + TEST_TASK_DIRS.each do |dir| + # Why doesn't the rcfile control the xml output file properly?? + sh("coverage xml -o reports/#{dir}/coverage.xml --rcfile=#{dir}/.coveragerc") + end end end From 83e2b362e4902186678ee25128847aa087d89ae5 Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Thu, 8 Nov 2012 10:32:32 -0500 Subject: [PATCH 13/16] Make reports directory build work correctly --- rakefile | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/rakefile b/rakefile index ad494d5ece..3836eb140e 100644 --- a/rakefile +++ b/rakefile @@ -38,6 +38,10 @@ def django_admin(system, env, command, *args) return "#{django_admin} #{command} --settings=#{system}.envs.#{env} --pythonpath=. #{args.join(' ')}" end +def report_dir_path(dir) + return File.join(REPORT_DIR, dir.to_s) +end + task :default => [:test, :pep8, :pylint] directory REPORT_DIR @@ -58,7 +62,7 @@ task :clean_test_files do end [:lms, :cms, :common].each do |system| - report_dir = File.join(REPORT_DIR, system.to_s) + report_dir = report_dir_path(system) directory report_dir desc "Run pep8 on all #{system} code" @@ -107,8 +111,7 @@ end TEST_TASK_DIRS = [] [:lms, :cms].each do |system| - report_dir = File.join(REPORT_DIR, system.to_s) - directory report_dir + report_dir = report_dir_path(system) # Per System tasks desc "Run all django tests on our djangoapps for the #{system}" @@ -154,8 +157,7 @@ end Dir["common/lib/*"].select{|lib| File.directory?(lib)}.each do |lib| task_name = "test_#{lib}" - report_dir = File.join(REPORT_DIR, task_name.gsub('/', '_')) - directory report_dir + report_dir = report_dir_path(lib) desc "Run tests for common lib #{lib}" task task_name => report_dir do @@ -174,6 +176,14 @@ Dir["common/lib/*"].select{|lib| File.directory?(lib)}.each do |lib| end +task :report_dirs + +TEST_TASK_DIRS.each do |dir| + report_dir = report_dir_path(dir) + directory report_dir + task :report_dirs => [REPORT_DIR, report_dir] +end + task :test do TEST_TASK_DIRS.each do |dir| Rake::Task["test_#{dir}"].invoke(false) @@ -186,14 +196,14 @@ end namespace :coverage do desc "Build the html coverage reports" - task :html do + task :html => :report_dirs do TEST_TASK_DIRS.each do |dir| sh("coverage html --rcfile=#{dir}/.coveragerc") end end desc "Build the xml coverage reports" - task :xml do + task :xml => :report_dirs do TEST_TASK_DIRS.each do |dir| # Why doesn't the rcfile control the xml output file properly?? sh("coverage xml -o reports/#{dir}/coverage.xml --rcfile=#{dir}/.coveragerc") From d3e2e739a7254c3f7ec462dd4263bf907cb971f4 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Thu, 8 Nov 2012 10:18:14 -0500 Subject: [PATCH 14/16] Add the .coverage files to the clobber task. --- rakefile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/rakefile b/rakefile index 3836eb140e..0239614e57 100644 --- a/rakefile +++ b/rakefile @@ -211,6 +211,10 @@ namespace :coverage do end end +TEST_TASK_DIRS.each do |dir| + CLOBBER.include("#{dir}/.coverage") +end + task :runserver => :lms desc "Run django-admin against the specified system and environment" From 28bb4724e7ba212979ac25c16d0132fbfb50a901 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Thu, 8 Nov 2012 11:09:57 -0500 Subject: [PATCH 15/16] Put the coverage data files in the reports dir, where they will be treated like the disposable things they are. --- cms/.coveragerc | 2 +- common/lib/capa/.coveragerc | 2 +- common/lib/xmodule/.coveragerc | 2 +- lms/.coveragerc | 2 +- rakefile | 6 +++--- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/cms/.coveragerc b/cms/.coveragerc index 268193f94a..5a2c6e0e93 100644 --- a/cms/.coveragerc +++ b/cms/.coveragerc @@ -1,6 +1,6 @@ # .coveragerc for cms [run] -data_file = cms/.coverage +data_file = reports/cms/.coverage [report] ignore_errors = True diff --git a/common/lib/capa/.coveragerc b/common/lib/capa/.coveragerc index 955a76294b..3818cb480a 100644 --- a/common/lib/capa/.coveragerc +++ b/common/lib/capa/.coveragerc @@ -1,6 +1,6 @@ # .coveragerc for common/lib/capa [run] -data_file = common/lib/capa/.coverage +data_file = reports/common/lib/capa/.coverage [report] ignore_errors = True diff --git a/common/lib/xmodule/.coveragerc b/common/lib/xmodule/.coveragerc index c31a858749..9f8c72ba37 100644 --- a/common/lib/xmodule/.coveragerc +++ b/common/lib/xmodule/.coveragerc @@ -1,6 +1,6 @@ # .coveragerc for common/lib/xmodule [run] -data_file = common/lib/xmodule/.coverage +data_file = reports/common/lib/xmodule/.coverage [report] ignore_errors = True diff --git a/lms/.coveragerc b/lms/.coveragerc index f41b79da68..13c5f9801e 100644 --- a/lms/.coveragerc +++ b/lms/.coveragerc @@ -1,6 +1,6 @@ # .coveragerc for lms [run] -data_file = lms/.coverage +data_file = reports/lms/.coverage [report] ignore_errors = True diff --git a/rakefile b/rakefile index 0239614e57..a1e98e9b6b 100644 --- a/rakefile +++ b/rakefile @@ -209,10 +209,10 @@ namespace :coverage do sh("coverage xml -o reports/#{dir}/coverage.xml --rcfile=#{dir}/.coveragerc") end end -end -TEST_TASK_DIRS.each do |dir| - CLOBBER.include("#{dir}/.coverage") + TEST_TASK_DIRS.each do |dir| + CLOBBER.include("#{dir}/.coverage") + end end task :runserver => :lms From 686cab4545199faac80b1f48bec6414c39b67b5f Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Thu, 8 Nov 2012 11:32:27 -0500 Subject: [PATCH 16/16] Build all available coverage xml and html, even if some is missing --- rakefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rakefile b/rakefile index a1e98e9b6b..8bdc859a2e 100644 --- a/rakefile +++ b/rakefile @@ -198,7 +198,7 @@ namespace :coverage do desc "Build the html coverage reports" task :html => :report_dirs do TEST_TASK_DIRS.each do |dir| - sh("coverage html --rcfile=#{dir}/.coveragerc") + sh("coverage html --rcfile=#{dir}/.coveragerc || echo 'Unable to build coverage html for #{dir}'") end end @@ -206,7 +206,7 @@ namespace :coverage do task :xml => :report_dirs do TEST_TASK_DIRS.each do |dir| # Why doesn't the rcfile control the xml output file properly?? - sh("coverage xml -o reports/#{dir}/coverage.xml --rcfile=#{dir}/.coveragerc") + sh("coverage xml -o reports/#{dir}/coverage.xml --rcfile=#{dir}/.coveragerc || echo 'Unable to build coverage xml for #{dir}'") end end