def fetch_test_data():
    """
    Fetches test data if it's missing.
    """

    data_dir = os.path.join(SETUP_DIR, 'tests', 'data')

    # if tests/data exists, is empty, and .gitmodules exists, run the
    # appropriate git-submodule(1) command
    if (os.path.isdir(data_dir) and not os.listdir(data_dir) and
            os.path.isfile(os.path.join(SETUP_DIR, '.gitmodules'))):
        import subprocess
        subprocess.call(['git', 'submodule', 'update',
                         '--init', '--recursive'])
    # if tests/data either doesn't exist or is empty, download the
    # busbus-test-data zip from GitHub and unpack it
    else:
        try:
            os.mkdir(data_dir)
        except __HOLE__ as exc:
            if exc.errno != errno.EEXIST:
                raise

        if not os.listdir(data_dir):
            # at this point requests and six are already installed
            import requests
            import six

            resp = requests.get('https://github.com/spaceboats/busbus-test-'
                                'data/archive/v{0}.zip'.format(VERSION))
            with zipfile.ZipFile(six.BytesIO(resp.content)) as z:
                prefix = 'busbus-test-data-{0}/'.format(VERSION)
                for filename in z.namelist():
                    if filename == prefix or not filename.startswith(prefix):
                        continue
                    filename = filename[len(prefix):]
                    if filename.endswith('/'):
                        os.mkdir(os.path.join(data_dir, filename))
                    else:
                        with open(os.path.join(data_dir, filename), 'wb') as f:
                            f.write(z.read(prefix + filename))
dataset/ETHPy150Open spaceboats/busbus/setup.py/fetch_test_data