def test_version(): old_args = copy.copy(sys.argv) sys.argv = ['conda-mirror', '--version'] with pytest.raises(SystemExit): conda_mirror.cli() sys.argv = old_args
def test_cli(tmpdir, channel, platform, repodata, num_threads): info, packages = repodata[channel] smallest_package, = _get_smallest_packages(packages) # drop the html stuff. get just the channel f2 = tmpdir.mkdir(channel.rsplit('/', 1)[-1]) f2.mkdir(platform) f1 = tmpdir.mkdir('conf').join('conf.yaml') f1.write(''' blacklist: - name: "*" whitelist: - name: {} version: {}'''.format(packages[smallest_package]['name'], packages[smallest_package]['version'])) cli_args = ("conda-mirror" " --config {config}" " --upstream-channel {channel}" " --target-directory {target_directory}" " --platform {platform}" " --num-threads {num_threads}" " --pdb" " -vvv" ).format(config=f1.strpath, channel=channel, target_directory=f2.strpath, platform=platform, num_threads=num_threads) old_argv = copy.deepcopy(sys.argv) sys.argv = cli_args.split(' ') # Write a package that does not exist in the upstream repodata into the # mirror path to make sure we exercise a broken code path # https://github.com/maxpoint/conda-mirror/issues/29 _write_bad_package(channel_dir=f2.strpath, platform_name=platform, pkg_name='bad-1-0.tar.bz2') # Write a bad package that does exist in the upstream repodata into the # mirror path to make sure we can handle that case too info, packages = repodata[channel] upstream_pkg_name = next(iter(packages.keys())) _write_bad_package(channel_dir=f2.strpath, platform_name=platform, pkg_name=upstream_pkg_name) conda_mirror.cli() sys.argv = old_argv for f in ['repodata.json', 'repodata.json.bz2']: # make sure the repodata file exists assert f in os.listdir(os.path.join(f2.strpath, platform)) # make sure that the repodata contains less than upstream since we prune it with open(os.path.join(f2.strpath, platform, 'repodata.json'), 'r') as f: disk_repodata = json.load(f) disk_info = disk_repodata.get('info', {}) assert len(disk_info) == len(info) disk_packages = disk_repodata.get('packages', {}) assert len(disk_packages) < len(packages) with bz2.BZ2File(os.path.join(f2.strpath, platform, 'repodata.json.bz2'), 'r') as f: contents = f.read().decode() rd = json.loads(contents) assert len(rd['info']) == len(disk_info) assert len(rd['packages']) == len(disk_packages)
def test_version(): old_args = copy.copy(sys.argv) sys.argv = ['conda-mirror', '--version'] conda_mirror.cli() sys.argv = old_args