From cbbdbaee477ea0b353bff69a9cd1880f629634f1 Mon Sep 17 00:00:00 2001 From: James Banting Date: Fri, 26 Oct 2018 21:32:59 -0600 Subject: [PATCH 1/2] Added CI (#24) Added CI --- .circleci/config.yml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 .circleci/config.yml diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 00000000..78768724 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,28 @@ +version: 2 +jobs: + build: + branches: + only: + - dev + - master + - ci + working_directory: ~/circleci/stac-validator + docker: + - image: circleci/python:3.6.4 + steps: + - checkout + - run: sudo chown -R circleci:circleci /usr/local/bin + - run: sudo chown -R circleci:circleci /usr/local/lib/python3.6/site-packages + - restore_cache: + key: v1-python-requirements-{{ checksum "requirements.txt" }} + - run: + command: | + pip install -r requirements.txt + - save_cache: + key: v1-python-requirements-{{ checksum "requirements.txt" }} + paths: + - "~/.cache/pip" + - "/usr/local/lib/python3.6/site-packages" + - run: + command: | + python -m pytest \ No newline at end of file From 0ea6aa368e5ac3b61711790a6ad7aa253a881eab Mon Sep 17 00:00:00 2001 From: James Banting Date: Sun, 28 Oct 2018 20:08:23 -0600 Subject: [PATCH 2/2] better error handleing --- stac_validator.py | 24 +++++++++++++++++------- tests/test_stac_validator.py | 4 ++-- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/stac_validator.py b/stac_validator.py index 8020c71b..d8f5e388 100755 --- a/stac_validator.py +++ b/stac_validator.py @@ -160,10 +160,9 @@ async def _validate_child(self, child_url, messages): messages.append(stac.message) - if "valid_json" in stac.message and not stac.message["valid_json"]: - stac.message.pop("valid_json", None) - stac.status.pop("valid_json", None) - pass + if "error_type" in stac.message: + stac.message.pop("error_type", None) + stac.status.pop("error_type", None) else: self.status["catalogs"]["valid"] += stac.status["catalogs"]["valid"] self.status["catalogs"]["invalid"] += stac.status["catalogs"]["invalid"] @@ -221,10 +220,15 @@ async def run(self): self.stac_file = data except JSONDecodeError as e: self.message["valid_stac"] = False - self.message["valid_json"] = False + self.message["error_type"] = "InvalidJSON" self.message["error"] = f"{self.stac_file} is not Valid JSON" self.status = self.message - return json.dumps(self.message) + # return json.dumps(self.message) + except FileNotFoundError as e: + self.message["valid_stac"] = False + self.message["error_type"] = "FileNotFoundError" + self.message["error"] = f"{self.stac_file} cannot be found" + self.status = self.message # Check STAC Type if "catalog" in self.fpath.stem: @@ -239,7 +243,9 @@ async def run(self): else: self.status["catalogs"]["invalid"] += 1 self.message["children"] = await self.validate_catalog_contents() - elif any(field in Collections_Fields for field in self.stac_file.keys()): + elif (self.stac_file) is dict and ( + field in Collections_Fields for field in self.stac_file.keys() + ): # Congratulations, It's a Collection! # Collections will validate as catalog. self.message["asset_type"] = "collection" @@ -252,6 +258,10 @@ async def run(self): else: self.status["collections"]["invalid"] += 1 self.message["children"] = await self.validate_catalog_contents() + elif "error_type" in self.message: + self.message.pop("error_type", None) + self.status.pop("error_type", None) + else: # Congratulations, It's an Item! self.message["asset_type"] = "item" diff --git a/tests/test_stac_validator.py b/tests/test_stac_validator.py index d8a6c032..79fbfe22 100644 --- a/tests/test_stac_validator.py +++ b/tests/test_stac_validator.py @@ -138,11 +138,11 @@ def test_bad_url(): ) assert stac.status == { "valid_stac": False, - "valid_json": False, "error": "https://s3.amazonaws.com/spacenet-stac/spacenet-dataset/AOI_4_Shanghai_MUL-PanSharpen_Cloud is not Valid JSON", + "path": "https:/s3.amazonaws.com/spacenet-stac/spacenet-dataset/AOI_4_Shanghai_MUL-PanSharpen_Cloud" } assert stac.message == { "valid_stac": False, - "valid_json": False, "error": "https://s3.amazonaws.com/spacenet-stac/spacenet-dataset/AOI_4_Shanghai_MUL-PanSharpen_Cloud is not Valid JSON", + "path": "https:/s3.amazonaws.com/spacenet-stac/spacenet-dataset/AOI_4_Shanghai_MUL-PanSharpen_Cloud" }