afscgap.test.test_tools
Convienence functions for testing afscgap.
(c) 2023 Regents of University of California / The Eric and Wendy Schmidt Center for Data Science and the Environment at UC Berkeley.
This file is part of afscgap released under the BSD 3-Clause License. See LICENSE.md.
1""" 2Convienence functions for testing afscgap. 3 4(c) 2023 Regents of University of California / The Eric and Wendy Schmidt Center 5for Data Science and the Environment at UC Berkeley. 6 7This file is part of afscgap released under the BSD 3-Clause License. See 8LICENSE.md. 9""" 10import json 11import os 12import pathlib 13import unittest 14 15# pylint: disable=C0115, C0116 16 17 18def get_test_file_path(filename: str) -> str: 19 parent_dir = pathlib.Path(__file__).parent.absolute() 20 data_dir = os.path.join(parent_dir, 'data') 21 full_path = os.path.join(data_dir, filename) 22 return full_path 23 24 25def load_test_data_json(filename: str) -> dict: 26 full_path = get_test_file_path(filename) 27 28 with open(full_path) as f: 29 loaded_data = json.load(f) 30 31 return loaded_data 32 33 34def load_test_data_text(filename: str) -> str: 35 full_path = get_test_file_path(filename) 36 37 with open(full_path) as f: 38 loaded_data = f.read() 39 40 return loaded_data 41 42 43def make_result_json(filename: str): 44 new_mock = unittest.mock.MagicMock() 45 new_mock.status_code = 200 46 47 loaded_data = load_test_data_json(filename) 48 49 new_mock.json = unittest.mock.MagicMock( 50 return_value=loaded_data 51 ) 52 53 return new_mock 54 55 56def make_result_text(filename: str): 57 new_mock = unittest.mock.MagicMock() 58 new_mock.status_code = 200 59 60 loaded_data = load_test_data_text(filename) 61 new_mock.text = loaded_data 62 63 return new_mock
def
get_test_file_path(filename: str) -> str:
def
load_test_data_json(filename: str) -> dict:
def
load_test_data_text(filename: str) -> str:
def
make_result_json(filename: str):
def
make_result_text(filename: str):