def test_file_is_recreated_when_out_of_date(self): hspatial.PointTimeseries(self.point, prefix=self.prefix).get_cached(self.dest) self._setup_additional_raster() # Make existing file read-only os.chmod(self.dest, S_IREAD | S_IRGRP | S_IROTH) # Try again—it should raise exception with self.assertRaises(PermissionError): hspatial.PointTimeseries(self.point, prefix=self.prefix).get_cached(self.dest)
def test_file_is_not_recreated(self): hspatial.PointTimeseries(self.point, prefix=self.prefix).get_cached(self.dest) # Make existing file read-only os.chmod(self.dest, S_IREAD | S_IRGRP | S_IROTH) # Try again—it shouldn't try to write, therefore it shouldn't raise exception hspatial.PointTimeseries(self.point, prefix=self.prefix).get_cached(self.dest) with open(self.dest, "r", newline="\n") as f: self._check_against_expected(HTimeseries(f))
def test_end_date(self): end_date = dt.datetime(2014, 11, 22, 16, 1) result = hspatial.PointTimeseries(self.point, prefix=self.prefix, end_date=end_date).get_cached( self.dest) self.assertEqual(result.data.index[-1], end_date)
def test_version(self): hspatial.PointTimeseries(self.point, prefix=self.prefix).get_cached(self.dest, version=2) with open(self.dest, "r") as f: first_line = f.readline() self.assertEqual(first_line, "Version=2\n")
def test_with_prefix_and_geodjango(self): point = GeoDjangoPoint(22.01001, 37.98001) prefix = os.path.join(self.tempdir, "test") ts = hspatial.PointTimeseries(point, prefix=prefix, default_time=dt.time(23, 58)).get() self._check_against_expected(ts)
def test_with_prefix(self): # Same as test_with_list_of_files(), but with prefix. point = hspatial.coordinates2point(22.01001, 37.98001) prefix = os.path.join(self.tempdir, "test") ts = hspatial.PointTimeseries(point, prefix=prefix, default_time=dt.time(23, 58)).get() self._check_against_expected(ts)
def test_with_list_of_files(self): # Use co-ordinates almost to the common corner of the four lower left points, # and only a little bit towards the center. point = hspatial.coordinates2point(22.01001, 37.98001) filenames = [ os.path.join(self.tempdir, "test-2014-11-22-16-1.tif"), os.path.join(self.tempdir, "test-2014-11-21-16-1.tif"), os.path.join(self.tempdir, "test-2014-11-23-16-1.tif"), ] ts = hspatial.PointTimeseries(point, filenames=filenames).get() self._check_against_expected(ts)
def test_file(self): hspatial.PointTimeseries(self.point, prefix=self.prefix).get_cached(self.dest) with open(self.dest, "r", newline="\n") as f: self._check_against_expected(HTimeseries(f))
def test_result(self): result = hspatial.PointTimeseries( self.point, prefix=self.prefix).get_cached(self.dest) self._check_against_expected(result)
def test_unit_of_measurement(self): point = hspatial.coordinates2point(22.01001, 37.98001) prefix = os.path.join(self.tempdir, "test") ts = hspatial.PointTimeseries(point, prefix=prefix).get() self.assertEqual(ts.unit, "microkernels")
def test_with_prefix_and_geodjango(self): point = hspatial.coordinates2point(22.01001, 37.98001) prefix = os.path.join(self.tempdir, "test") ts = hspatial.PointTimeseries(point, prefix=prefix).get() self._check_against_expected(ts)