def check_xform(path_to_xform): """Run ODK Validate against the XForm in `path_to_xform`. Returns an array of warnings if the form is valid. Throws an exception if it is not """ # check for available java version check_java_version() # resultcode indicates validity of the form # timeout indicates whether validation ran out of time to complete # stdout is not used because it has some warnings that always # appear and can be ignored. # stderr is treated as a warning if the form is valid or an error # if it is invalid. returncode, timeout, _stdout, stderr = _call_validator( path_to_xform=path_to_xform) warnings = [] stderr = decode_stream(stderr) if timeout: return ["XForm took to long to completely validate."] else: if returncode > 0: # Error invalid raise ODKValidateError("ODK Validate Errors:\n" + ErrorCleaner.odk_validate(stderr)) elif returncode == 0: if stderr: warnings.append("ODK Validate Warnings:\n" + stderr) elif returncode < 0: return ["Bad return code from ODK Validate."] return warnings
def test_cleanup_error_message(self): test_str = self.config.get(self.cls_name, "test_cleanup_error_message_test") expected_str = self.config.get(self.cls_name, "test_cleanup_error_message_expected") self.assertEqual(ErrorCleaner.odk_validate(test_str), expected_str.strip())
def check_xform(path_to_xform): """ Returns an array of warnings if the form is valid. Throws an exception if it is not """ # provide useful error message if java is not installed if not _java_installed(): raise EnvironmentError( "pyxform odk validate dependency: java not found") # resultcode indicates validity of the form # timeout indicates whether validation ran out of time to complete # stdout is not used because it has some warnings that always # appear and can be ignored. # stderr is treated as a warning if the form is valid or an error # if it is invalid. returncode, timeout, stdout, stderr = run_popen_with_timeout( ["java", "-jar", ODK_VALIDATE_JAR, path_to_xform], 100) warnings = [] stderr = decode_stream(stderr) if timeout: return ["XForm took to long to completely validate."] else: if returncode > 0: # Error invalid raise ODKValidateError( 'ODK Validate Errors:\n' + ErrorCleaner.odk_validate(stderr)) elif returncode == 0: if stderr: warnings.append('ODK Validate Warnings:\n' + stderr) return warnings elif returncode < 0: return ["Bad return code from ODK Validate."]
def check_xform(path_to_xform): """Run ODK Validate against the XForm in `path_to_xform`. Returns an array of warnings if the form is valid. Throws an exception if it is not """ # check for available java version check_java_version() # resultcode indicates validity of the form # timeout indicates whether validation ran out of time to complete # stdout is not used because it has some warnings that always # appear and can be ignored. # stderr is treated as a warning if the form is valid or an error # if it is invalid. returncode, timeout, _stdout, stderr = _call_validator(path_to_xform=path_to_xform) warnings = [] stderr = decode_stream(stderr) if timeout: return ["XForm took to long to completely validate."] else: if returncode > 0: # Error invalid raise ODKValidateError( b"ODK Validate Errors:\n" + ErrorCleaner.odk_validate(stderr).encode("utf-8") ) elif returncode == 0: if stderr: warnings.append("ODK Validate Warnings:\n" + stderr) elif returncode < 0: return ["Bad return code from ODK Validate."] return warnings
def test_cleanup_error_message(self): test_str = self.config.get( self.cls_name, "test_cleanup_error_message_test") expected_str = self.config.get( self.cls_name, "test_cleanup_error_message_expected") self.assertEqual( ErrorCleaner.odk_validate(test_str), expected_str.strip())
def test_jarfile_error_returned_asis(self): """Should return a jarfile error as-is, to avoid tokenising the path.""" test_str = self.config.get(self.cls_name, "test_jarfile_error_returned_asis_test") expected_str = self.config.get( self.cls_name, "test_jarfile_error_returned_asis_expected") self.assertEqual(ErrorCleaner.odk_validate(test_str), expected_str.strip())
def test_single_line_error_still_output(self): """Should emit errors that are a single line of text.""" test_str = self.config.get(self.cls_name, "test_single_line_error_still_output_test") expected_str = self.config.get( self.cls_name, "test_single_line_error_still_output_expected") self.assertEqual(ErrorCleaner.odk_validate(test_str), expected_str.strip())
def test_jarfile_error_returned_asis(self): """Should return a jarfile error as-is, to avoid tokenising the path.""" test_str = self.config.get( self.cls_name, "test_jarfile_error_returned_asis_test") expected_str = self.config.get( self.cls_name, "test_jarfile_error_returned_asis_expected") self.assertEqual( ErrorCleaner.odk_validate(test_str), expected_str.strip())
def test_single_line_error_still_output(self): """Should emit errors that are a single line of text.""" test_str = self.config.get( self.cls_name, "test_single_line_error_still_output_test") expected_str = self.config.get( self.cls_name, "test_single_line_error_still_output_expected") self.assertEqual( ErrorCleaner.odk_validate(test_str), expected_str.strip())
def test_do_not_over_trim_javarosa_errors(self): test_str = self.config.get( self.cls_name, "test_do_not_over_trim_javarosa_errors_test") # Unescape tabs in string test_str = test_str.replace("\n\\t", "\n\t") expected_str = self.config.get( self.cls_name, "test_do_not_over_trim_javarosa_errors_expected") self.assertEqual(ErrorCleaner.odk_validate(test_str), expected_str.strip())
def test_do_not_over_trim_javarosa_errors(self): test_str = self.config.get( self.cls_name, "test_do_not_over_trim_javarosa_errors_test") # Unescape tabs in string test_str = test_str.replace("\n\\t", "\n\t") expected_str = self.config.get( self.cls_name, "test_do_not_over_trim_javarosa_errors_expected") self.assertEqual( ErrorCleaner.odk_validate(test_str), expected_str.strip())
def should_clean_odk_validate_stacktrace(self): message = """java.lang.NullPointerException Null Pointer\norg.javarosa.xform.parse.XFormParseException Parser""" cleaned = ErrorCleaner.odk_validate(message) self.assertEqual(cleaned, " Null Pointer\n Parser")