def test_localadas(path): adas_class = "adf11" adas_file = Path("scd89") / "scd12_h.dat" with TemporaryDirectory() as path: reader = ADASReader(path, MagicMock()) filepath = Path(path) / adas_class / adas_file filepath.parent.mkdir(parents=True) filepath.touch() filestream = reader._get_file(adas_class, adas_file) assert filestream.name == str(filepath)
def test_cache_openadas(): # TODO: Compile different options so can test with larger range of inputs adas_class = "adf11" adas_file = Path("scd89") / "scd12_h.dat" with cachedir() as cache, patch( "indica.readers.adas.urlretrieve") as urlretrieve: reader = ADASReader("", MagicMock()) cachepath = Path().home() / cache cache_file = cachepath / "adas" / "adf11" / adas_file urlretrieve.side_effect = lambda x, y: y.touch() filestream = reader._get_file(adas_class, adas_file) assert filestream.name == str(cache_file) urlretrieve.assert_called_once_with( f"https://open.adas.ac.uk/download/{adas_class}/{adas_file}", cache_file, ) urlretrieve.reset_mock() filestream2 = reader._get_file(adas_class, adas_file) assert filestream2.name == str(cache_file) urlretrieve.assert_not_called()
def test_read_invalid_adf11(): reader = ADASReader("", MagicMock()) quantity = "scd" # The following check is not strictly necessary but is included in case # ADF11_GENERAL_DATATYPES is changed in the future to exclude "scd" for some reason. try: _ = ADF11_GENERAL_DATATYPES[quantity] except Exception as e: raise e with assert_raises(AssertionError): invalid_file_name = Path("tests/unit/readers/invalid_adf11_file.dat") with open(invalid_file_name, "r") as invalid_file: reader._get_file = MagicMock(return_value=invalid_file) _ = reader.get_adf11(quantity, "he", "89")