def test_is_sac_bytes_io(self): """ Tests the _is_sac function for BytesIO objects. """ with io.BytesIO() as buf: # Read file to BytesIO. with open(self.file, "rb") as fh: buf.write(fh.read()) buf.seek(0, 0) self.assertTrue(_is_sac(buf)) # Should naturally fail for an XY file. with io.BytesIO() as buf: # Read file to BytesIO. with open(self.filexy, "rb") as fh: buf.write(fh.read()) buf.seek(0, 0) self.assertFalse(_is_sac(buf))
def get_files(file_list): """ Return a sequence of SAC file names from either a list of file names (trivial) or a text file list (presumable because there are too many files to use normal shell expansion). """ if len(file_list) == 1 and not _is_sac(file_list[0]): #make a generator of non-blank lines try: listfile = open(file_list[0], 'r') files = (line.strip() for line in listfile if line.strip()) except IOError: msg = "{0} does not exist.".format(file_list[0]) raise IOError(msg) else: files = file_list return files
def get_files(options): """ Return a sequence of SAC file names from either a list of file names (trivial) or a text file list (presumable because there are too many files to use normal shell expansion). """ if len(options.files) == 1 and not _is_sac(options.files[0]): #make a generator of non-blank lines try: listfile = open(options.files[0], 'r') files = (line.strip() for line in listfile if line.strip()) except IOError: msg = "{0} does not exist.".format(options.files[0]) raise IOError(msg) else: files = options.files return files
def test_is_sac_open_file(self): """ Tests the _is_sac function for open files. """ with open(self.file, "rb") as fh: self.assertTrue(_is_sac(fh))