def vsifile_22(): # VSIOpenL doesn't set errorno gdal.VSIErrorReset() if gdal.VSIGetLastErrorNo() != 0: gdaltest.post_reason("Expected Err=0 after VSIErrorReset(), got %d" % gdal.VSIGetLastErrorNo()) return 'fail' fp = gdal.VSIFOpenL('tmp/not-existing', 'r') if fp is not None: gdaltest.post_reason("Expected None from VSIFOpenL") return 'fail' if gdal.VSIGetLastErrorNo() != 0: gdaltest.post_reason("Expected Err=0 from VSIFOpenL, got %d" % gdal.VSIGetLastErrorNo()) return 'fail' # VSIOpenExL does fp = gdal.VSIFOpenExL('tmp/not-existing', 'r', 1) if fp is not None: gdaltest.post_reason("Expected None from VSIFOpenExL") return 'fail' if gdal.VSIGetLastErrorNo() != 1: gdaltest.post_reason("Expected Err=1 from VSIFOpenExL, got %d" % gdal.VSIGetLastErrorNo()) return 'fail' if len(gdal.VSIGetLastErrorMsg()) == 0: gdaltest.post_reason("Expected a VSI error message") return 'fail' gdal.VSIErrorReset() if gdal.VSIGetLastErrorNo() != 0: gdaltest.post_reason("Expected Err=0 after VSIErrorReset(), got %d" % gdal.VSIGetLastErrorNo()) return 'fail' return 'success'
def test_vsifile_22(): # VSIOpenL doesn't set errorno gdal.VSIErrorReset() assert gdal.VSIGetLastErrorNo() == 0, \ ("Expected Err=0 after VSIErrorReset(), got %d" % gdal.VSIGetLastErrorNo()) fp = gdal.VSIFOpenL('tmp/not-existing', 'r') assert fp is None, "Expected None from VSIFOpenL" assert gdal.VSIGetLastErrorNo() == 0, \ ("Expected Err=0 from VSIFOpenL, got %d" % gdal.VSIGetLastErrorNo()) # VSIOpenExL does fp = gdal.VSIFOpenExL('tmp/not-existing', 'r', 1) assert fp is None, "Expected None from VSIFOpenExL" assert gdal.VSIGetLastErrorNo() == 1, \ ("Expected Err=1 from VSIFOpenExL, got %d" % gdal.VSIGetLastErrorNo()) assert len(gdal.VSIGetLastErrorMsg()) != 0, "Expected a VSI error message" gdal.VSIErrorReset() assert gdal.VSIGetLastErrorNo() == 0, \ ("Expected Err=0 after VSIErrorReset(), got %d" % gdal.VSIGetLastErrorNo())
def _check_error(self): if gdal.VSIGetLastErrorNo() != 0: raise SimpleVSIMemFileError(gdal.VSIGetLastErrorMsg())