forked from sentinel-hub/eo-learn
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updating functions, adding unit tests
- Loading branch information
Matic Lubej
committed
Nov 27, 2019
1 parent
5cbfcb4
commit 4b49b32
Showing
11 changed files
with
83 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
""" | ||
Credits: | ||
Copyright (c) 2017-2019 Matej Aleksandrov, Matej Batič, Andrej Burja, Eva Erzin (Sinergise) | ||
Copyright (c) 2017-2019 Grega Milčinski, Matic Lubej, Devis Peresutti, Jernej Puc, Tomislav Slijepčević (Sinergise) | ||
Copyright (c) 2017-2019 Blaž Sovdat, Jovan Višnjić, Anže Zupanc, Lojze Žust (Sinergise) | ||
This source code is licensed under the MIT license found in the LICENSE | ||
file in the root directory of this source tree. | ||
""" | ||
|
||
import unittest | ||
import logging | ||
import os | ||
import pickle | ||
import boto3 | ||
from moto import mock_s3 | ||
|
||
from eolearn.core import EOPatch | ||
|
||
logging.basicConfig(level=logging.DEBUG) | ||
|
||
|
||
class TestEOPatchAWS(unittest.TestCase): | ||
PATCH_FILENAME = os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../../example_data/TestEOPatchAWS') | ||
eop = EOPatch.load(PATCH_FILENAME) | ||
|
||
MY_BUCKET = "test-bucket" | ||
MY_PREFIX = "TestEOPatchAWS" | ||
|
||
@mock_s3 | ||
def create_and_fill_s3_bucket(self): | ||
s3client = boto3.client('s3', region_name='eu-central-1') | ||
s3resource = boto3.resource('s3', region_name='eu-central-1') | ||
s3resource.create_bucket(Bucket=self.MY_BUCKET) | ||
self.eop.save_aws(bucket_name=self.MY_BUCKET, patch_location=self.MY_PREFIX, s3client=s3client) | ||
return s3client, s3resource | ||
|
||
def empty_and_delete_s3_bucket(self, s3resource): | ||
bucket = s3resource.Bucket(self.MY_BUCKET) | ||
for key in bucket.objects.all(): | ||
key.delete() | ||
bucket.delete() | ||
|
||
@mock_s3 | ||
def test_save_eopatch(self): | ||
stats_filename = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'stats/test_save_stats.pkl') | ||
saved_content = pickle.load(open(stats_filename, 'rb')) | ||
|
||
s3client, s3resource = self.create_and_fill_s3_bucket() | ||
|
||
response = s3client.list_objects(Bucket=self.MY_BUCKET, Prefix=self.MY_PREFIX) | ||
content = [x['Key'] for x in response['Contents']] | ||
|
||
update_stats = True | ||
if update_stats: | ||
pickle.dump(content, open(stats_filename, 'wb')) | ||
|
||
self.empty_and_delete_s3_bucket(s3resource) | ||
self.assertEqual(saved_content, content) | ||
|
||
@mock_s3 | ||
def test_load_eopatch(self): | ||
s3client, s3resource = self.create_and_fill_s3_bucket() | ||
eop = EOPatch.load_aws(bucket_name=self.MY_BUCKET, patch_location=self.MY_PREFIX, s3client=s3client) | ||
|
||
self.empty_and_delete_s3_bucket(s3resource) | ||
self.assertEqual(self.eop, eop) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,5 @@ numpy>=1.16 | |
geopandas | ||
sentinelhub>=2.5.0 | ||
tqdm>=4.27 | ||
boto3 | ||
moto |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.