def ta_bank_bad_file(self, ta_bank): """ add an unreadable file to the wave bank, then return new bank """ path = ta_bank.bank_path new_file_path = os.path.join(path, "bad_file.mseed") with open(new_file_path, "w") as fi: fi.write("this is not an mseed file, duh") # remove old index if it exists if os.path.exists(ta_bank.index_path): os.remove(ta_bank.index_path) return sbank.WaveBank(path)
def ta_bank_empty_files(self, ta_bank, tmpdir): """ add many empty files to bank, ensure index still reads all files """ old_path = Path(ta_bank.bank_path) new_path = Path(tmpdir) / "waveforms" shutil.copytree(old_path, new_path) # create 100 empty files for a in range(100): new_file_path = new_path / f"{a}.mseed" with new_file_path.open("wb") as fi: pass # remove old index if it exists index_path = new_path / (Path(ta_bank.index_path).name) if index_path.exists(): os.remove(index_path) bank = sbank.WaveBank(old_path) bank.update_index() return bank
def ta_bank(tmp_ta_dir): """ init a bank on the test TA dataset """ inventory_path = os.path.join(tmp_ta_dir, "inventory.xml") bank_path = os.path.join(tmp_ta_dir, "waveforms") return sbank.WaveBank(bank_path, inventory=inventory_path)
def ta_bank_no_index(self, ta_bank): """ return the ta bank, but first delete the index if it exists """ index_path = os.path.join(ta_bank.bank_path, ".index.h5") if os.path.exists(index_path): os.remove(index_path) return sbank.WaveBank(ta_bank.bank_path)
def test_bad_inventory(self, tmp_ta_dir): """ ensure giving a bad stations str raises """ with pytest.raises(Exception): sbank.WaveBank(tmp_ta_dir, inventory="some none existent file")