| 1 | # -*- coding: utf-8 -*- |
|---|
| 2 | ## |
|---|
| 3 | ## $Id$ |
|---|
| 4 | ## |
|---|
| 5 | ## This file is part of CDS Indico. |
|---|
| 6 | ## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 CERN. |
|---|
| 7 | ## |
|---|
| 8 | ## CDS Indico is free software; you can redistribute it and/or |
|---|
| 9 | ## modify it under the terms of the GNU General Public License as |
|---|
| 10 | ## published by the Free Software Foundation; either version 2 of the |
|---|
| 11 | ## License, or (at your option) any later version. |
|---|
| 12 | ## |
|---|
| 13 | ## CDS Indico is distributed in the hope that it will be useful, but |
|---|
| 14 | ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 15 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|---|
| 16 | ## General Public License for more details. |
|---|
| 17 | ## |
|---|
| 18 | ## You should have received a copy of the GNU General Public License |
|---|
| 19 | ## along with CDS Indico; if not, write to the Free Software Foundation, Inc., |
|---|
| 20 | ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. |
|---|
| 21 | ''' |
|---|
| 22 | To add new tests simply create a new file inside tests/ or inside a subdir with a |
|---|
| 23 | unittest.TestCase child class and this script will automatically find it. |
|---|
| 24 | |
|---|
| 25 | WARNING WARNING WARNING |
|---|
| 26 | If you are launching tests inside Eclipse or any other IDE make sure that sys.path |
|---|
| 27 | is properly set. |
|---|
| 28 | ''' |
|---|
| 29 | import os |
|---|
| 30 | import unittest |
|---|
| 31 | import sys |
|---|
| 32 | import glob |
|---|
| 33 | import re |
|---|
| 34 | import nose |
|---|
| 35 | import figleaf |
|---|
| 36 | import figleaf.annotate_html |
|---|
| 37 | import subprocess |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | def main(testPath, coverage): |
|---|
| 41 | |
|---|
| 42 | print "Welcome in INDICOP" |
|---|
| 43 | sys.stdout.flush() |
|---|
| 44 | returnString="" |
|---|
| 45 | |
|---|
| 46 | if coverage: |
|---|
| 47 | figleaf.start() |
|---|
| 48 | |
|---|
| 49 | #Starting Selenium server |
|---|
| 50 | child = subprocess.Popen(["java", "-jar", "indicop/selenium_tests/selenium-server.jar"], stdout=subprocess.PIPE) |
|---|
| 51 | |
|---|
| 52 | #This is a cheap trick to make sure that selenium has fully |
|---|
| 53 | #started before launching the tests. |
|---|
| 54 | #Selenium (1.0.1) displays 5 lines in the shell before being ready |
|---|
| 55 | counter = 0 |
|---|
| 56 | while counter < 5: |
|---|
| 57 | child_output = child.stdout.readline() |
|---|
| 58 | #print "Selenium debug %s: %s" % (counter, child_output) |
|---|
| 59 | counter += 1 |
|---|
| 60 | |
|---|
| 61 | if testPath: |
|---|
| 62 | result = nose.run(argv=['nose','-v', 'indicop/MaKaC_tests/%s' % testPath]) |
|---|
| 63 | else: |
|---|
| 64 | #result = nose.run(argv=['nose','-v', 'indicop/MaKaC_tests/']) |
|---|
| 65 | result = nose.run(argv=['nose','-v', 'indicop/selenium_tests/create_delete_lecture_test.py:Selenium_test.test_create_delete_lecture']) |
|---|
| 66 | |
|---|
| 67 | #Stopping Selenium Server |
|---|
| 68 | child.kill() |
|---|
| 69 | |
|---|
| 70 | if coverage: |
|---|
| 71 | figleaf.stop() |
|---|
| 72 | coverageOutput = figleaf.get_data().gather_files() |
|---|
| 73 | try: |
|---|
| 74 | figleaf.annotate_html.report_as_html(coverageOutput, 'indicop/coverage/html_report', [], {}) |
|---|
| 75 | except Exception: |
|---|
| 76 | os.mkdir('indicop/coverage/html_report') |
|---|
| 77 | figleaf.annotate_html.report_as_html(coverageOutput, 'indicop/coverage/html_report', [], {}) |
|---|
| 78 | returnString += "Report generated in indicop/coverage/html_report\n" |
|---|
| 79 | |
|---|
| 80 | if result: |
|---|
| 81 | returnString += "All tests succeeded!" |
|---|
| 82 | else: |
|---|
| 83 | returnString += "TestSuite failed!" |
|---|
| 84 | |
|---|
| 85 | return returnString |
|---|
| 86 | |
|---|
| 87 | if __name__ == '__main__': |
|---|
| 88 | main() |
|---|