From 65e430c4c154b66a42e44c4cfe7da92c4830dd0f Mon Sep 17 00:00:00 2001 From: fredkingham Date: Thu, 25 May 2017 12:02:35 +0100 Subject: [PATCH 1/2] add opal location to the js test runner --- CHANGELOG.md | 4 ++++ doc/docs/reference/testing.md | 3 +++ opal/core/commandline.py | 1 + opal/core/test_runner.py | 4 ++++ opal/static/js/lib/bower_components/ment.io/karma.conf.js | 1 - opal/tests/test_core_commandline.py | 3 +++ opal/tests/test_core_test_runner.py | 1 + 7 files changed, 16 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b61e62e35..c3619e035 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ### 0.8.2 (Minor Release) +#### OPAL_LOCATION is added as a system variable when running js tests +If you run opal test js, your karma config is now run in an environment that has +access to the OPAL_LOCATION variable which points to the opal parent directory. + #### A Data Dictionary In The Extract The Extract zip file has a data dictionary with human readable metadata about each field. diff --git a/doc/docs/reference/testing.md b/doc/docs/reference/testing.md index 8b23758ad..9ef484ac2 100644 --- a/doc/docs/reference/testing.md +++ b/doc/docs/reference/testing.md @@ -50,6 +50,9 @@ module.exports = function(config){ }; ``` +If run from opal test js, we set the path to opal as an env variable called +OPAL_LOCATION + ## Test Coverage The Opal test runner has a `-c` option which runs coverage reports for both Python and Javascript code: diff --git a/opal/core/commandline.py b/opal/core/commandline.py index cf1c5f68c..1e832ec7a 100755 --- a/opal/core/commandline.py +++ b/opal/core/commandline.py @@ -115,6 +115,7 @@ def scaffold(args): def test(args): args.userland_here = USERLAND_HERE + args.opal_location = OPAL.parent test_runner.run_tests(args) return diff --git a/opal/core/test_runner.py b/opal/core/test_runner.py index 3c424c48f..6e2668b40 100644 --- a/opal/core/test_runner.py +++ b/opal/core/test_runner.py @@ -73,6 +73,10 @@ def _run_js_tests(args): """ write("Running Javascript Unit Tests") env = os.environ.copy() + + # used by the karma config file where to find the opal karma defaults + env["OPAL_LOCATION"] = args.opal_location + if TRAVIS: karma = './node_modules/karma/bin/karma' else: diff --git a/opal/static/js/lib/bower_components/ment.io/karma.conf.js b/opal/static/js/lib/bower_components/ment.io/karma.conf.js index 0ba80720c..083ab66d8 100644 --- a/opal/static/js/lib/bower_components/ment.io/karma.conf.js +++ b/opal/static/js/lib/bower_components/ment.io/karma.conf.js @@ -86,4 +86,3 @@ module.exports = function(config) { }); }; - diff --git a/opal/tests/test_core_commandline.py b/opal/tests/test_core_commandline.py index 17d81c482..c4a1119a0 100644 --- a/opal/tests/test_core_commandline.py +++ b/opal/tests/test_core_commandline.py @@ -157,6 +157,9 @@ def test_test(self): mock_args = MagicMock(name='Mock Args') with patch.object(commandline.test_runner, 'run_tests') as rt: commandline.test(mock_args) + mock_args_call = rt.call_args[0][0] + self.assertTrue(mock_args_call.userland_here.endswith("opal")) + self.assertTrue(mock_args_call.opal_location.endswith("opal")) rt.assert_called_with(mock_args) diff --git a/opal/tests/test_core_test_runner.py b/opal/tests/test_core_test_runner.py index 054a6c52e..143b8b781 100644 --- a/opal/tests/test_core_test_runner.py +++ b/opal/tests/test_core_test_runner.py @@ -152,6 +152,7 @@ def test_run_tests_travis(self, check_call): ], check_call.call_args[0][0] ) + self.assertIn("OPAL_LOCATION", check_call.call_args[1]["env"]) @patch.object(test_runner.subprocess, 'check_call') @patch.object(test_runner.sys, 'exit') From 499d4cce97d6025f6e12b342cbe92327ffe4352a Mon Sep 17 00:00:00 2001 From: fredkingham Date: Thu, 25 May 2017 12:16:46 +0100 Subject: [PATCH 2/2] change the default opal path in the jinja2, fix tests in python3 --- opal/core/test_runner.py | 4 +++- .../plugin_scaffold/config/karma.conf.js.jinja2 | 10 +--------- opal/tests/test_core_test_runner.py | 4 ++++ 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/opal/core/test_runner.py b/opal/core/test_runner.py index 6e2668b40..f2a66a674 100644 --- a/opal/core/test_runner.py +++ b/opal/core/test_runner.py @@ -75,7 +75,9 @@ def _run_js_tests(args): env = os.environ.copy() # used by the karma config file where to find the opal karma defaults - env["OPAL_LOCATION"] = args.opal_location + # python3 breaks on ffs if we don't explicitly cast the location + # to a string + env["OPAL_LOCATION"] = str(args.opal_location) if TRAVIS: karma = './node_modules/karma/bin/karma' diff --git a/opal/scaffolding/plugin_scaffold/config/karma.conf.js.jinja2 b/opal/scaffolding/plugin_scaffold/config/karma.conf.js.jinja2 index b74bfc5f6..11c2c6ccf 100644 --- a/opal/scaffolding/plugin_scaffold/config/karma.conf.js.jinja2 +++ b/opal/scaffolding/plugin_scaffold/config/karma.conf.js.jinja2 @@ -1,13 +1,5 @@ module.exports = function(config){ - var opalPath; - if(process.env.TRAVIS){ - python_version = process.env.TRAVIS_PYTHON_VERSION; - opalPath = '/home/travis/virtualenv/python' + python_version + '/src/opal'; - } - else{ - // this should point to the location of Opal on your machine, it may be in the virtualenv - opalPath = '../../opal'; - } + var opalPath = process.env.OPAL_LOCATION; var karmaDefaults = require(opalPath + '/config/karma_defaults.js'); var baseDir = __dirname + '/..'; var coverageFiles = [ diff --git a/opal/tests/test_core_test_runner.py b/opal/tests/test_core_test_runner.py index 143b8b781..874f2dae3 100644 --- a/opal/tests/test_core_test_runner.py +++ b/opal/tests/test_core_test_runner.py @@ -154,6 +154,10 @@ def test_run_tests_travis(self, check_call): ) self.assertIn("OPAL_LOCATION", check_call.call_args[1]["env"]) + self.assertTrue( + isinstance(check_call.call_args[1]["env"]["OPAL_LOCATION"], str) + ) + @patch.object(test_runner.subprocess, 'check_call') @patch.object(test_runner.sys, 'exit') def test_generic_error_in_call(self, exiter, check_call):