def import_data(cls, type, view, view_type=None): type_, type = type, __builtins__['type'] is_format = False if isinstance(type_, str): type_ = qiime.sdk.parse_type(type_) if isinstance(view_type, str): view_type = qiime.sdk.parse_format(view_type) is_format = True if view_type is None: if type(view) is str or isinstance(view, pathlib.PurePath): is_format = True pm = qiime.sdk.PluginManager() output_dir_fmt = pm.get_directory_format(type_) if pathlib.Path(view).is_file(): if not issubclass(output_dir_fmt, model.SingleFileDirectoryFormatBase): raise ValueError("Importing %r requires a" " directory, not %s" % (output_dir_fmt.__name__, view)) view_type = output_dir_fmt.file.format else: view_type = output_dir_fmt else: view_type = type(view) format_ = None md5sums = None if is_format: path = pathlib.Path(view) if path.is_file(): md5sums = {path.name: util.md5sum(path)} elif path.is_dir(): md5sums = util.md5sum_directory(path) else: raise ValueError("Path '%s' does not exist." % path) format_ = view_type provenance_capture = archive.ImportProvenanceCapture(format_, md5sums) return cls._from_view(type_, view, view_type, provenance_capture)
def test_can_use_string(self): string_path = str(self.make_file(b"Normal text\nand things\n")) self.assertEqual(util.md5sum(string_path), "93b048d0202e4b06b658f3aef1e764d3")
def test_large_file(self): path = self.make_file(b"verybigfile" * (1024 * 50)) self.assertEqual(util.md5sum(path), "27d64211ee283283ad866c18afa26611")
def test_single_byte_file(self): self.assertEqual(util.md5sum(self.make_file(b"a")), "0cc175b9c0f1b6a831c399e269772661")
def test_empty_file(self): self.assertEqual(util.md5sum(self.make_file(b"")), "d41d8cd98f00b204e9800998ecf8427e")
def test_large_file(self): path = self.make_file(b'verybigfile' * (1024 * 50)) self.assertEqual(util.md5sum(path), '27d64211ee283283ad866c18afa26611')
def test_single_byte_file(self): self.assertEqual(util.md5sum(self.make_file(b'a')), '0cc175b9c0f1b6a831c399e269772661')
def test_empty_file(self): self.assertEqual(util.md5sum(self.make_file(b'')), 'd41d8cd98f00b204e9800998ecf8427e')
def test_can_use_string(self): string_path = str(self.make_file(b'Normal text\nand things\n')) self.assertEqual(util.md5sum(string_path), '93b048d0202e4b06b658f3aef1e764d3')