def test_handle_overrides_handles_anything_cleanly_no_process_junk(text): # Check that it doesn't just crash with random input with mock.patch("notebooker.web.handle_overrides.subprocess.check_output" ) as popen: popen.side_effect = lambda args: mock.MagicMock( res=_handle_overrides_safe(args[4], args[6])) handle_overrides(text, issues=[])
def test_handle_overrides_normal(test_name, input_str, expected_output_values, expected_issues): issues = [] override_dict = handle_overrides(input_str, issues) assert sorted(issues) == sorted(expected_issues) assert sorted(override_dict.items()) == sorted( expected_output_values.items())
def test_handle_overrides_handles_imports(input_txt): with mock.patch("notebooker.web.handle_overrides.subprocess.check_output" ) as popen: popen.side_effect = lambda args: mock.MagicMock( res=_handle_overrides_safe(args[4], args[6])) issues = [] overrides = handle_overrides(input_txt, issues) assert overrides == {"d": datetime.datetime(2018, 1, 1).isoformat()}
def test_handle_overrides_handles_anything_cleanly_no_process_variable(text): with mock.patch("notebooker.web.handle_overrides.subprocess.check_output" ) as popen: popen.side_effect = lambda args: mock.MagicMock( res=_handle_overrides_safe(args[4], args[6])) issues = [] overrides = handle_overrides(text, issues) if any(t for t in text.split("\n") if t.strip()): assert len(issues) >= 1 or len(overrides) >= 1 else: assert len(issues) == 0 and len(overrides) == 0
def test_handle_overrides_normal(test_name, input_str, expected_output_values, expected_issues): issues = [] override_dict = handle_overrides(input_str, issues) if sorted(issues) != sorted(expected_issues) and expected_issues: for expected_issue in expected_issues: fail_msg = "Issue {} was not found in the list of issues: {}".format( expected_issue, issues) assert any(expected_issue in issue for issue in issues), fail_msg assert sorted(issues) == sorted(expected_issues) assert sorted(override_dict.items()) == sorted( expected_output_values.items())
def run_checks_http(report_name): """ Execute a notebook from an HTTP request. :param report_name: The parameter here should be a "/"-delimited string which mirrors the directory structure of \ the notebook templates. :returns: 202-redirects to the "task_status" interface. """ issues = [] # Get and process raw python overrides overrides_dict = handle_overrides(request.values.get("overrides"), issues) return _handle_run_report(report_name, overrides_dict, issues)
def test_handle_overrides_handles_imports_with_issues(input_txt): with mock.patch("notebooker.web.handle_overrides.subprocess.check_output" ) as popen: popen.side_effect = lambda args: mock.MagicMock( res=_handle_overrides_safe(args[4], args[6])) issues = [] overrides = handle_overrides(input_txt, issues) assert overrides == {} if sys.version_info < (3, 7): error_string = "Object of type 'datetime' is not JSON serializable, Value: 0010-01-01 00:00:00" else: error_string = "Object of type datetime is not JSON serializable, Value: 0010-01-01 00:00:00" assert issues == [ 'Could not JSON serialise a parameter ("d") - ' "this must be serialisable so that we can execute " "the notebook with it! " "(Error: {})".format(error_string) ]