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_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_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) ]