def test_run_tests_with_test_arg(self, check_call): mock_args = MagicMock(name="args") mock_args.userland_here = ffs.Path('.') mock_args.coverage = False mock_args.test = 'opal.tests.foo' test_runner._run_py_tests(mock_args) check_call.assert_called_once_with(['python', 'runtests.py', 'opal.tests.foo'])
def test_run_tests(self, check_call): mock_args = MagicMock(name="args") mock_args.userland_here = ffs.Path('.') mock_args.coverage = False mock_args.test = None test_runner._run_py_tests(mock_args) check_call.assert_called_once_with(['python', 'runtests.py'])
def test_run_tests_errors(self, exiter, check_call): mock_args = MagicMock(name="args") mock_args.userland_here = ffs.Path('.') mock_args.coverage = False mock_args.test = None check_call.side_effect = subprocess.CalledProcessError(None, None) test_runner._run_py_tests(mock_args) exiter.assert_called_once_with(1)
def test_run_tests_failfast(self, check_call): mock_args = MagicMock(name='args') mock_args.userland_here = ffs.Path('.') mock_args.coverage = False mock_args.test = False mock_args.failfast = True test_runner._run_py_tests(mock_args) check_call.assert_called_with(['python', 'runtests.py', '--failfast'])
def test_run_tests_with_coverage_errors(self, exiter, check_call): mock_args = MagicMock(name="args") mock_args.userland_here = ffs.Path('.') mock_args.coverage = True mock_args.test = None check_call.side_effect = [None, subprocess.CalledProcessError(None, None)] test_runner._run_py_tests(mock_args) self.assertEqual(2, check_call.call_count) exiter.assert_called_once_with(1)
def test_run_tests_for_app_with_test(self, has_file, check_call): mock_args = MagicMock(name="args") mock_args.userland_here = ffs.Path('.') mock_args.coverage = False mock_args.test = 'foo.tests.bar' has_file.side_effect = lambda a, b: b == 'manage.py' test_runner._run_py_tests(mock_args) check_call.assert_called_with(['python', 'manage.py', 'test', 'foo.tests.bar'])
def test_run_tests(self, check_call): mock_args = MagicMock(name="args") mock_args.userland_here = ffs.Path('.') mock_args.coverage = False mock_args.test = None test_runner.TRAVIS = False test_runner._run_js_tests(mock_args) self.assertEqual( ['karma', 'start', 'config/karma.conf.js', '--single-run'], check_call.call_args[0][0])
def test_handles_malformed_xml_errors(self, mock_requests): post_return_value = MagicMock() post_return_value.status_code = 404 post_return_value.reason = 'dunno' post_return_value.test = 'Bad XML' post_return_value.ok = False mock_requests.post.return_value = post_return_value with self.assertRaises(EutilsNCBIError): pmid = 1234569 self.qs.efetch(args={'db': 'pubmed', 'id': pmid})
def test_run_tests(self, check_call): mock_args = MagicMock(name="args") mock_args.userland_here = ffs.Path('.') mock_args.coverage = False mock_args.test = None test_runner.TRAVIS = False test_runner._run_js_tests(mock_args) self.assertEqual( ['karma', 'start', 'config/karma.conf.js', '--single-run'], check_call.call_args[0][0] )
def test_run_tests_for_unknown_config(self, sysexit, writer, has_file): mock_args = MagicMock(name="args") mock_args.userland_here = ffs.Path('.') mock_args.coverage = False mock_args.test = None has_file.return_value = False test_runner._run_py_tests(mock_args) writer.assert_any_call("\n\nCripes!\n") sysexit.assert_called_with(1)
def test_run_tests_with_coverage_and_test_arg(self, check_call): mock_args = MagicMock(name="args") mock_args.userland_here = ffs.Path('.') mock_args.coverage = True mock_args.test = 'opal.tests.foo' mock_args.failfast = False test_runner._run_py_tests(mock_args) calls = [ call(['coverage', 'run', 'runtests.py', 'opal.tests.foo']), call(['coverage', 'html']) ]
def test_run_tests_with_coverage_errors(self, exiter, check_call): mock_args = MagicMock(name="args") mock_args.userland_here = ffs.Path('.') mock_args.coverage = True mock_args.test = None check_call.side_effect = [ None, subprocess.CalledProcessError(None, None) ] test_runner._run_py_tests(mock_args) self.assertEqual(2, check_call.call_count) exiter.assert_called_once_with(1)
def test_run_tests_for_app_with_test(self, has_file, check_call): mock_args = MagicMock(name="args") mock_args.userland_here = ffs.Path('.') mock_args.coverage = False mock_args.test = 'foo.tests.bar' has_file.side_effect = lambda a, b: b == 'manage.py' test_runner._run_py_tests(mock_args) check_call.assert_called_with( ['python', 'manage.py', 'test', 'foo.tests.bar'])
def test_run_tests_with_coverage(self, check_call): mock_args = MagicMock(name="args") mock_args.userland_here = ffs.Path('.') mock_args.coverage = True mock_args.test = None test_runner._run_py_tests(mock_args) calls = [ call(['coverage', 'run', 'runtests.py']), call(['coverage', 'html']) ] check_call.assert_has_calls(calls)
def test_run_tests_travis(self, check_call): mock_args = MagicMock(name="args") mock_args.userland_here = ffs.Path('.') mock_args.coverage = False mock_args.test = None test_runner.TRAVIS = True test_runner._run_js_tests(mock_args) self.assertEqual([ './node_modules/karma/bin/karma', 'start', 'config/karma.conf.js', '--single-run' ], check_call.call_args[0][0]) self.assertIn("OPAL_LOCATION", check_call.call_args[1]["env"]) self.assertTrue( isinstance(check_call.call_args[1]["env"]["OPAL_LOCATION"], str))
def test_run_tests_for_app_with_coverage(self, has_file, check_call): mock_args = MagicMock(name="args") mock_args.userland_here = ffs.Path('.') mock_args.coverage = True mock_args.test = None has_file.side_effect = lambda a, b: b == 'manage.py' test_runner._run_py_tests(mock_args) calls = [ call(['coverage', 'run', 'manage.py', 'test']), call(['coverage', 'html']) ] check_call.assert_has_calls(calls)
def test_run_tests_travis(self, check_call): mock_args = MagicMock(name="args") mock_args.userland_here = ffs.Path('.') mock_args.coverage = False mock_args.test = None test_runner.TRAVIS = True test_runner._run_js_tests(mock_args) self.assertEqual( [ './node_modules/karma/bin/karma', 'start', 'config/karma.conf.js', '--single-run' ], check_call.call_args[0][0] ) self.assertIn("OPAL_LOCATION", check_call.call_args[1]["env"]) self.assertTrue( isinstance(check_call.call_args[1]["env"]["OPAL_LOCATION"], str) )
url="url_token", verify=False, data="body_token".encode("utf-8"), timeout=60, headers={"Content-type": "application/json"}, ) ], ) ], patchers=[Patcher(target=HTTP_REQUEST, return_value=STAUS_500_RESPONSE)], ) # ------------------------------------------------ TEST_ERR_BOOLRULE = MagicMock() TEST_ERR_BOOLRULE.test = MagicMock(side_effect=Exception("exc_token3")) EXP_TEST_ERR_RESPONSE = MagicMock() EXP_TEST_ERR_RESPONSE.json = MagicMock(return_value="json_token2") EXP_TEST_ERR_RESPONSE.status_code = 200 HTTP_CALL_EXP_TEST_ERR_CASE = ComponentTestCase( name="http call bool rule test err case", inputs={ "bk_http_request_method": "method_token", "bk_http_request_url": "url_token", "bk_http_request_body": "body_token", "bk_http_request_header": [], "bk_http_success_exp": "exp_token", "bk_http_timeout": 5, },