# Path: matl_online/utils.py
# def unzip(fileobj, destination, flatten=True):
#     """Unzip an archive to a specific directory and flatten the shared prefix."""
#     archive = zipfile.ZipFile(fileobj)
# 
#     # Ensure that the destination exists
#     if not os.path.isdir(destination):
#         os.makedirs(destination)
# 
#     inputs = ()
# 
#     if flatten:
#         inputs = (get_members(archive),)
# 
#     archive.extractall(destination, *inputs)
# 
# Path: tests/mocks.py
# class MockZipFile:
#     """Mock zip file that implements only the methods we use for testing."""
# 
#     def __init__(self, *args, **kwargs):
#         """Initialize the mock object."""
#         self.files = []
#         self.extract_arguments = ()
# 
#     def add_files(self, *args):
#         """Add files to this archive."""
#         self.files.extend(args)
# 
#     def namelist(self):
#         """Get a list of all files in the archive."""
#         return self.files
# 
#     def infolist(self):
#         """Get metadata about all of the files."""
#         # filename: filename
#         return [type('info', (object,), {'filename': x}) for x in self.files]
# 
#     def extractall(self, *args):
#         """Pretend to extract all of the files and record inputs."""
#         self.extract_arguments = args


import os
import shutil
from matl_online.utils import unzip
from .mocks import MockZipFile
"""Unit tests for utils module."""




class TestUnzip:
    """Test unzip functionality."""

    def test_unzip_and_flatten(self, mocker, tmpdir):
        """Check that flattening of parent directories works as expected."""
        mzip = MockZipFile()
        mzip.add_files('mydir/abcde', 'mydir/fghij')

        zipfile = mocker.patch('matl_online.utils.zipfile.ZipFile')
        zipfile.return_value = mzip


# Path: matl_online/utils.py
# def unzip(fileobj, destination, flatten=True):
#     """Unzip an archive to a specific directory and flatten the shared prefix."""
#     archive = zipfile.ZipFile(fileobj)
# 
#     # Ensure that the destination exists
#     if not os.path.isdir(destination):
#         os.makedirs(destination)
# 
#     inputs = ()
# 
#     if flatten:
#         inputs = (get_members(archive),)
# 
#     archive.extractall(destination, *inputs)
# 
# Path: tests/mocks.py
# class MockZipFile:
#     """Mock zip file that implements only the methods we use for testing."""
# 
#     def __init__(self, *args, **kwargs):
#         """Initialize the mock object."""
#         self.files = []
#         self.extract_arguments = ()
# 
#     def add_files(self, *args):
#         """Add files to this archive."""
#         self.files.extend(args)
# 
#     def namelist(self):
#         """Get a list of all files in the archive."""
#         return self.files
# 
#     def infolist(self):
#         """Get metadata about all of the files."""
#         # filename: filename
#         return [type('info', (object,), {'filename': x}) for x in self.files]
# 
#     def extractall(self, *args):
#         """Pretend to extract all of the files and record inputs."""
#         self.extract_arguments = args


# Path: tests/test_utils.py
import os
import shutil
from matl_online.utils import unzip
from .mocks import MockZipFile

"""Unit tests for utils module."""




class TestUnzip:
    """Test unzip functionality."""

    def test_unzip_and_flatten(self, mocker, tmpdir):
        """Check that flattening of parent directories works as expected."""
        mzip = MockZipFile()
        mzip.add_files('mydir/abcde', 'mydir/fghij')

        zipfile = mocker.patch('matl_online.utils.zipfile.ZipFile')
        zipfile.return_value = mzip


        unzip('', tmpdir.strpath)