def test_scan_scan_xz(): """ Unit test for scan method, lzma case. """ file_io = FileIO() for method_row, util_row in zip(file_io.scan(TEST_CSV_XZ), util_test_csv(TEST_CSV)): assert method_row == util_row
def test_scan_scan_bzip2(): """ Unit test for scan method, gzip case. """ file_io = FileIO() for method_row, util_row in zip(file_io.scan(TEST_CSV_BZ2), util_test_csv(TEST_CSV)): assert method_row == util_row
def test_scan_tar_files(): """Unit test for method scan, compressed tar file case.""" file_io = FileIO() for ffile in os.listdir(TEST_TAR_LOCATION): for dfile in file_io.scan(os.path.join(TEST_TAR_LOCATION, ffile)): assert os.path.exists(dfile)
def test_scan_csv(): """ Unit test for scan method, txt or csv case. """ file_io = FileIO() for method_row, util_row in zip(file_io.scan(TEST_CSV), util_test_csv(TEST_CSV)): assert method_row == util_row
def test_scan_unknown_file(self): """ Unit test for scan method, unknown file case """ file_io = FileIO() with self.assertRaises(FileTypeNotSupportedYet): next(file_io.scan(TEST_UNKNOWN))
def test_infer_file_type_from_uri_remote(): """ Unit test for method infer_file_type_from_uri, remote case. """ file_io = FileIO() assert file_io.infer_file_type_from_uri(TEST_URL) == 'JPG'
def test_scan_compressed_tar_file_http(): """Unit test for method scan_compressed_tar_file, http case.""" test_uri = 'http://localhost:8888/images.tar.xz' test_file_reader = 'r|xz' file_io = FileIO() for ffile in file_io.scan_compressed_tar_file(test_uri, test_file_reader): assert os.path.exists(ffile)
def test_infer_file_type_from_uri_no_mimetype(): """ Unit test for method infer_file_type_from_uri, no mimetype case """ file_io = FileIO() assert file_io.infer_file_type_from_uri(TEST_LOCAL, mimetype=False) == 'JPG'
def test_infer_file_type_from_uri_with_mimetype(): """ Unit test for method infer_file_type_from_uri, with mimetype case """ file_io = FileIO() _, mime = file_io.infer_file_type_from_uri(TEST_LOCAL, mimetype=True) assert mime == 'image/jpeg'
def test_infer_file_type_from_uri_unsupported(self): """ Unit test for method infer_file_type_from_uri, unsupported file type case """ file_io = FileIO() with self.assertRaises(FileTypeNotSupportedYet): file_io.infer_file_type_from_uri(TEST_UNSUPPORTED_FILE_TYPE, mimetype=True)
def test_dump(): """Unit test for method dump.""" file_io = FileIO() file_io.dump(TEST_SCAN_DIR, tempfile.gettempdir()) assert is_tarfile( os.path.join( tempfile.gettempdir(), '.'.join( (os.path.basename(file_io.resolve_path_end(TEST_SCAN_DIR)), 'pupyl'))))
def test_scan_directory(): """ Unit test for scan method, directory case """ file_io = FileIO() test_against_tree = [ abspath(f'{TEST_SCAN_DIR}{ffile}') for ffile in [*walk(TEST_SCAN_DIR)][0][-1] ] test_current_tree = [*file_io.scan(abspath(TEST_SCAN_DIR))] assert test_current_tree == test_against_tree
def test_bind(): """Unit test for method bind.""" file_io = FileIO() file_io.dump(TEST_SCAN_DIR, tempfile.gettempdir()) file_io.bind( os.path.join( tempfile.gettempdir(), '.'.join( (os.path.basename(file_io.resolve_path_end(TEST_SCAN_DIR)), 'pupyl'))), os.path.join(tempfile.gettempdir(), TEST_SCAN_DIR)) assert os.path.isdir(os.path.join(tempfile.gettempdir(), TEST_SCAN_DIR))
def test_infer_file_type_tar_files(): """Unit test for method infer_file_type_from_uri, tar file case.""" file_io = FileIO() for ffile in os.listdir(TEST_TAR_LOCATION): test_file_type = mimetypes.guess_type( os.path.join(TEST_TAR_LOCATION, ffile))[1] assert file_io.infer_file_type_from_uri( os.path.join(TEST_TAR_LOCATION, ffile), mimetype=True) == TarCompressedTypes.mime(test_file_type) assert file_io.infer_file_type_from_uri( os.path.join(TEST_TAR_LOCATION, ffile), mimetype=False) == TarCompressedTypes.name(test_file_type)
def test_scan_compressed_tar_file_local(): """Unit test for method scan_compressed_tar_file, local case.""" test_tar_compressed_file_readers = { 'TZ2': 'r:bz2', 'TGZ': 'r:gz', 'TXZ': 'r:xz' } file_io = FileIO() for ffile in os.listdir(TEST_TAR_LOCATION): test_file_type = mimetypes.guess_type( os.path.join(TEST_TAR_LOCATION, ffile))[1] for dfile in file_io.scan_compressed_tar_file( os.path.join(TEST_TAR_LOCATION, ffile), test_tar_compressed_file_readers[TarCompressedTypes.name( test_file_type)]): assert os.path.exists(dfile)
def test_scan_file(self): """ Unit test for scan method, file case.""" file_io = FileIO() with self.assertRaises(FileScanNotPossible): assert next(file_io.scan(TEST_LOCAL)) == TEST_LOCAL
def test_infer_file_type_from_uri_unknown(self): """ Unit test infer_file_type_from_uri, unknown case. """ with self.assertRaises(FileTypeNotSupportedYet): file_io = FileIO() file_io.infer_file_type_from_uri(TEST_UNKNOWN)