def test_remote(self): with patch('rastervision.utils.files.download_if_needed', side_effect=download_if_needed) as patched_download: s3_path = 's3://{}/{}'.format(self.bucket_name, self.file_name) str_to_file(self.content_str, s3_path) path = get_cached_file(self.cache_dir, s3_path) self.assertTrue(os.path.isfile(path)) # Check that calling it again doesn't invoke the download method again. path = get_cached_file(self.cache_dir, s3_path) self.assertTrue(os.path.isfile(path)) self.assertEqual(patched_download.call_count, 1)
def get_tile_features(tile_uri, z, x, y): """Get GeoJSON features for a specific tile using in-memory caching.""" cache_dir = os.path.join(RVConfig.get_tmp_dir_root(), 'vector-tiles') tile_path = get_cached_file(cache_dir, tile_uri) cmd = ['tippecanoe-decode', '-f', '-c', tile_path, str(z), str(x), str(y)] tile_geojson_str = check_output(cmd).decode('utf-8') tile_features = [json.loads(ts) for ts in tile_geojson_str.split('\n')] return tile_features
def test_local_zip(self): local_path = os.path.join(self.temp_dir.name, self.file_name) local_gz_path = local_path + '.gz' with gzip.open(local_gz_path, 'wb') as f: f.write(bytes(self.content_str, encoding='utf-8')) with patch('gzip.open', side_effect=gzip.open) as patched_gzip_open: path = get_cached_file(self.cache_dir, local_gz_path) self.assertTrue(os.path.isfile(path)) self.assertNotEqual(path, local_gz_path) with open(path, 'r') as f: self.assertEqual(f.read(), self.content_str) # Check that calling it again doesn't invoke the gzip.open method again. path = get_cached_file(self.cache_dir, local_gz_path) self.assertTrue(os.path.isfile(path)) self.assertNotEqual(path, local_gz_path) with open(path, 'r') as f: self.assertEqual(f.read(), self.content_str) self.assertEqual(patched_gzip_open.call_count, 1)
def test_local(self): local_path = os.path.join(self.temp_dir.name, self.file_name) str_to_file(self.content_str, local_path) path = get_cached_file(self.cache_dir, local_path) self.assertTrue(os.path.isfile(path))