Add Activity Testing API and check command to setup.py
./setup.py check now invokes tests in tests/ directory. tests directory should have integration(UI tests) and unit(unit tests) sub directories, but it isn't necessary to have any dir. of the above.
This commit is contained in:
parent
d4b4405c6c
commit
29738c9087
@ -24,6 +24,7 @@ import os
|
||||
import sys
|
||||
import zipfile
|
||||
import tarfile
|
||||
import unittest
|
||||
import shutil
|
||||
import subprocess
|
||||
import re
|
||||
@ -263,6 +264,56 @@ class Installer(Packager):
|
||||
self.config.bundle.install_mime_type(self.config.source_dir)
|
||||
|
||||
|
||||
def cmd_check(config, args):
|
||||
"""Run tests for the activity"""
|
||||
|
||||
if len(args) > 1:
|
||||
print "Usage: %prog check {integration.unit}"
|
||||
return
|
||||
|
||||
run_unit_test = True
|
||||
run_integration_test = True
|
||||
|
||||
if len(args) == 1:
|
||||
if args[0] == "unit":
|
||||
run_integration_test = False
|
||||
elif args[0] == "integration":
|
||||
run_unit_test = False
|
||||
else:
|
||||
print "Invalid argument: should be either integration or unit"
|
||||
|
||||
print "Running Tests"
|
||||
|
||||
test_path = os.path.join(config.source_dir, "tests")
|
||||
|
||||
if os.path.isdir(test_path):
|
||||
unit_test_path = os.path.join(test_path, "unit")
|
||||
integration_test_path = os.path.join(test_path, "integration")
|
||||
sys.path.append(config.source_dir)
|
||||
|
||||
# Run Tests
|
||||
if os.path.isdir(unit_test_path) and run_unit_test:
|
||||
all_tests = unittest.defaultTestLoader.discover(unit_test_path)
|
||||
unittest.TextTestRunner().run(all_tests)
|
||||
elif not run_unit_test:
|
||||
print "Not running unit tests"
|
||||
else:
|
||||
print 'No "unit" directory found.'
|
||||
|
||||
if os.path.isdir(integration_test_path) and run_integration_test:
|
||||
all_tests = unittest.defaultTestLoader.discover(
|
||||
integration_test_path)
|
||||
unittest.TextTestRunner().run(all_tests)
|
||||
elif not run_integration_test:
|
||||
print "Not running integration tests"
|
||||
else:
|
||||
print 'No "integration" directory found.'
|
||||
|
||||
print "Finished testing"
|
||||
else:
|
||||
print "Error: No tests/ directory"
|
||||
|
||||
|
||||
def cmd_dev(config, args):
|
||||
"""Setup for development"""
|
||||
|
||||
|
@ -22,14 +22,26 @@ from __future__ import absolute_import
|
||||
|
||||
import logging
|
||||
import os
|
||||
import time
|
||||
import unittest
|
||||
import subprocess
|
||||
from contextlib import contextmanager
|
||||
|
||||
from sugar3.test import uitree
|
||||
|
||||
import dbus
|
||||
from dbus.mainloop.glib import DBusGMainLoop
|
||||
DBusGMainLoop(set_as_default=True)
|
||||
bus = dbus.SessionBus()
|
||||
|
||||
|
||||
class UITestCase(unittest.TestCase):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
unittest.TestCase(*args, **kwargs)
|
||||
|
||||
self.bundle_id = None
|
||||
|
||||
def setUp(self):
|
||||
logger = logging.getLogger()
|
||||
self._orig_level = logger.getEffectiveLevel()
|
||||
@ -51,3 +63,19 @@ class UITestCase(unittest.TestCase):
|
||||
raise
|
||||
finally:
|
||||
process.terminate()
|
||||
|
||||
@contextmanager
|
||||
def run_activity(self):
|
||||
if bundle_id is not None:
|
||||
process = subprocess.Popen(["sugar-launch", self.bundle_id])
|
||||
else:
|
||||
print "No bundle_id specified."
|
||||
return
|
||||
|
||||
try:
|
||||
yield
|
||||
except:
|
||||
logging.debug(uitree.get_root().dump())
|
||||
raise
|
||||
finally:
|
||||
process.terminate()
|
||||
|
Loading…
Reference in New Issue
Block a user