Commit 3fafc65c by Ben Patterson

Merge pull request #5278 from edx/benp/improve-paver-bokchoy-modulestore

Refactor default_store logic in paver test_bokchoy
parents a129c4d2 f6b2b52c
...@@ -52,7 +52,7 @@ def test_bokchoy(options): ...@@ -52,7 +52,7 @@ def test_bokchoy(options):
opts = { opts = {
'test_spec': getattr(options, 'test_spec', None), 'test_spec': getattr(options, 'test_spec', None),
'fasttest': getattr(options, 'fasttest', False), 'fasttest': getattr(options, 'fasttest', False),
'default_store': getattr(options, 'default_store', None), 'default_store': getattr(options, 'default_store', 'split'),
'verbosity': getattr(options, 'verbosity', 2), 'verbosity': getattr(options, 'verbosity', 2),
'extra_args': getattr(options, 'extra_args', ''), 'extra_args': getattr(options, 'extra_args', ''),
'test_dir': 'tests', 'test_dir': 'tests',
...@@ -78,8 +78,8 @@ def perf_report_bokchoy(options): ...@@ -78,8 +78,8 @@ def perf_report_bokchoy(options):
opts = { opts = {
'test_spec': getattr(options, 'test_spec', None), 'test_spec': getattr(options, 'test_spec', None),
'fasttest': getattr(options, 'fasttest', False), 'fasttest': getattr(options, 'fasttest', False),
'default_store': getattr(options, 'default_store', 'split'),
'imports_dir': getattr(options, 'imports_dir', None), 'imports_dir': getattr(options, 'imports_dir', None),
'default_store': getattr(options, 'default_store', None),
'verbosity': getattr(options, 'verbosity', 2), 'verbosity': getattr(options, 'verbosity', 2),
'test_dir': 'performance', 'test_dir': 'performance',
'ptests': True, 'ptests': True,
...@@ -90,22 +90,15 @@ def perf_report_bokchoy(options): ...@@ -90,22 +90,15 @@ def perf_report_bokchoy(options):
def run_bokchoy(**opts): def run_bokchoy(**opts):
""" """
Runs BokChoyTestSuite with the given options. Runs BokChoyTestSuite with the given options.
If a default store is not specified, runs the test suite for 'split' as the default store.
""" """
if opts['default_store'] not in ['draft', 'split']: test_suite = BokChoyTestSuite('bok-choy', **opts)
msg = colorize( msg = colorize(
'red', 'green',
'No modulestore specified, running tests for split.' 'Running tests using {default_store} modulestore.'.format(
default_store=test_suite.default_store)
) )
print(msg) print(msg)
stores = ['split'] test_suite.run()
else:
stores = [opts['default_store']]
for store in stores:
opts['default_store'] = store
test_suite = BokChoyTestSuite('bok-choy', **opts)
test_suite.run()
@task @task
......
...@@ -6,26 +6,23 @@ from pavelib.utils.test.suites.bokchoy_suite import BokChoyTestSuite ...@@ -6,26 +6,23 @@ from pavelib.utils.test.suites.bokchoy_suite import BokChoyTestSuite
REPO_DIR = os.getcwd() REPO_DIR = os.getcwd()
class TestPaverBokChoy(unittest.TestCase): class TestPaverBokChoyCmd(unittest.TestCase):
def setUp(self): def setUp(self):
self.request = BokChoyTestSuite('') self.request = BokChoyTestSuite('')
def _expected_command(self, expected_text_append): def _expected_command(self, expected_text_append, expected_default_store=None):
if expected_text_append: if expected_text_append:
expected_text_append = "/" + expected_text_append expected_text_append = "/" + expected_text_append
expected_statement = ( expected_statement = ("DEFAULT_STORE={default_store} SCREENSHOT_DIR='{repo_dir}/test_root/log' "
"DEFAULT_STORE=None SCREENSHOT_DIR='{repo_dir}/test_root/log' " "BOK_CHOY_HAR_DIR='{repo_dir}/test_root/log/hars' "
"BOK_CHOY_HAR_DIR='{repo_dir}/test_root/log/hars' " "SELENIUM_DRIVER_LOG_DIR='{repo_dir}/test_root/log' "
"SELENIUM_DRIVER_LOG_DIR='{repo_dir}/test_root/log' " "nosetests {repo_dir}/common/test/acceptance/tests{exp_text} "
"nosetests {repo_dir}/common/test/acceptance/tests{exp_text} " "--with-xunit "
"--with-xunit " "--xunit-file={repo_dir}/reports/bok_choy/xunit.xml "
"--xunit-file={repo_dir}/reports/bok_choy/xunit.xml " "--verbosity=2 ".format(default_store=expected_default_store,
"--verbosity=2 ".format( repo_dir=REPO_DIR,
repo_dir=REPO_DIR, exp_text=expected_text_append))
exp_text=expected_text_append,
)
)
return expected_statement return expected_statement
def test_default_bokchoy(self): def test_default_bokchoy(self):
...@@ -43,5 +40,13 @@ class TestPaverBokChoy(unittest.TestCase): ...@@ -43,5 +40,13 @@ class TestPaverBokChoy(unittest.TestCase):
self.request.test_spec = "test_foo.py:FooTest.test_bar" self.request.test_spec = "test_foo.py:FooTest.test_bar"
self.assertEqual(self.request.cmd, self._expected_command(self.request.test_spec)) self.assertEqual(self.request.cmd, self._expected_command(self.request.test_spec))
def test_default_bokchoy_with_draft_default_store(self):
self.request.test_spec = "test_foo.py"
self.request.default_store = "draft"
self.assertEqual(self.request.cmd, self._expected_command(self.request.test_spec, "draft"))
# TODO: Test when bok_choy test file is in a subdir def test_default_bokchoy_with_invalid_default_store(self):
# the cmd will dumbly compose whatever we pass in for the default_store
self.request.test_spec = "test_foo.py"
self.request.default_store = "invalid"
self.assertEqual(self.request.cmd, self._expected_command(self.request.test_spec, "invalid"))
...@@ -18,6 +18,14 @@ __test__ = False # do not collect ...@@ -18,6 +18,14 @@ __test__ = False # do not collect
class BokChoyTestSuite(TestSuite): class BokChoyTestSuite(TestSuite):
""" """
TestSuite for running Bok Choy tests TestSuite for running Bok Choy tests
Properties (below is a subset):
test_dir - parent directory for tests
log_dir - directory for test output
report_dir - directory for reports (e.g., coverage) related to test execution
xunit_report - directory for xunit-style output (xml)
fasttest - when set, skip various set-up tasks (e.g., DB migrations)
test_spec - when set, specifies test files, classes, cases, etc. See platform doc.
default_store - modulestore to use when running tests (split or draft)
""" """
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(BokChoyTestSuite, self).__init__(*args, **kwargs) super(BokChoyTestSuite, self).__init__(*args, **kwargs)
...@@ -28,7 +36,7 @@ class BokChoyTestSuite(TestSuite): ...@@ -28,7 +36,7 @@ class BokChoyTestSuite(TestSuite):
self.cache = Env.BOK_CHOY_CACHE self.cache = Env.BOK_CHOY_CACHE
self.fasttest = kwargs.get('fasttest', False) self.fasttest = kwargs.get('fasttest', False)
self.test_spec = kwargs.get('test_spec', None) self.test_spec = kwargs.get('test_spec', None)
self.default_store = kwargs.get('default_store') self.default_store = kwargs.get('default_store', None)
self.verbosity = kwargs.get('verbosity', 2) self.verbosity = kwargs.get('verbosity', 2)
self.extra_args = kwargs.get('extra_args', '') self.extra_args = kwargs.get('extra_args', '')
self.ptests = kwargs.get('ptests', False) self.ptests = kwargs.get('ptests', False)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment