def test_download_package__too_many_packages(bucket_and_keys): """If requesting a package with too many options, raise SystemExit.""" bucket, keys = bucket_and_keys with pytest.raises(SystemExit) as exit_error: download.prefer_wheels(keys, parse_package("error_pkg")) expected = ( "Found too many results for error-pkg:\n" " error-pkg/error-pkg-2.3.4-py2.py3-none-any.whl\n" " error-pkg/error-pkg-2.3.4-py2-none-any.whl\n" " error-pkg/error_pkg-2.3.4.tar.gz" ) assert expected in exit_error.value.args with pytest.raises(SystemExit) as exit_error: download.prefer_wheels(keys, parse_package("error_pkg==2.3.4")) expected = ( "Found too many results for error-pkg==2.3.4:\n" " error-pkg/error-pkg-2.3.4-py2.py3-none-any.whl\n" " error-pkg/error-pkg-2.3.4-py2-none-any.whl\n" " error-pkg/error_pkg-2.3.4.tar.gz" ) assert expected in exit_error.value.args
def test_download_package__prefers_wheels(bucket_and_keys): """When multiple versions are available, by default prefer wheels.""" bucket, keys = bucket_and_keys with mock.patch.object(download, "write_key") as patched_write: download.download_package(bucket, parse_package("package_two==0.0.1")) patched_write.assert_called_once_with(keys[6])
def test_download_package__not_found(bucket_and_keys): """SystemExit should be raised when the package is not found.""" with pytest.raises(SystemExit) as exit_error: download.download_package( bucket_and_keys[0], parse_package("package-unknown"), ) assert "Package package-unknown not found" in exit_error.value.args with pytest.raises(SystemExit) as specific_error: download.download_package( bucket_and_keys[0], parse_package("something==1.2.3") ) assert "Package something==1.2.3 not found" in specific_error.value.args
def test_download_package__prefer_egg(bucket_and_keys, argv_cleanup): """Ensure you can receive an egg if you request one.""" bucket, keys = bucket_and_keys download.sys.argv = ["download", "package_two==0.0.1", "--egg"] with mock.patch.object(download, "write_key") as patched_write: download.download_package(bucket, parse_package("package_two==0.0.1")) patched_write.assert_called_once_with(keys[8])
def test_download_package__specific(bucket_and_keys): """Verify the calls made to succesfully download a specific package.""" bucket, keys = bucket_and_keys with mock.patch.object(download, "write_key") as patched_write: download.download_package( bucket, parse_package("package-one == 1.2.3-alpha1") ) patched_write.assert_called_once_with(keys[0])
def test_list_packages__specific(capfd, bucket_and_keys): """Verify the exact release is listed if requested.""" parsed_pkg = parse_package("package_two==0.0.1") with mock.patch.object(lister, "print_versioned") as patched_print: lister.list_package(bucket_and_keys[0], parsed_pkg) patched_print.assert_called_once_with( [ "package-two-0.0.1-py2.py3-none-any.whl", "package_two-0.0.1.tar.gz", "package-two-0.0.1-py2.7.egg", ], parsed_pkg, )
def test_list_packages__ranges(capfd, bucket_and_keys): """Ensure we can use gt/lt/ge/le type ranges for listing.""" parsed_pkg = parse_package("package_one < 1.2.4") with mock.patch.object(lister, "print_versioned") as patched_print: lister.list_package( bucket_and_keys[0], parsed_pkg, ) patched_print.assert_called_once_with( [ "package-one-1.2.3-alpha1-py2.py3-none-any.whl", "package-one-1.2.3-py2.py3-none-any.whl", ], parsed_pkg, )
def test_print_versioned__in_order(capfd): releases = [ "some_thing-0.0.1-py2.py3-none-any.whl", "some_thing-1.2.4.egg", "some_thing-1.5.2.dev1.tar.gz", "some_thing-2.4.3.tar.gz", "some_thing-1.5.2-py2.py3-none-any.whl", "some_thing-1.7.5.tar.gz", ] expected = [ "some-thing==2.4.3 : some_thing-2.4.3.tar.gz", "some-thing==1.7.5 : some_thing-1.7.5.tar.gz", "some-thing==1.5.2 : some_thing-1.5.2-py2.py3-none-any.whl", "some-thing==1.5.2.dev1 : some_thing-1.5.2.dev1.tar.gz", "some-thing==1.2.4 : some_thing-1.2.4.egg", "some-thing==0.0.1 : some_thing-0.0.1-py2.py3-none-any.whl", ] lister.print_versioned(releases, parse_package("some_thing")) out, err = capfd.readouterr() assert not err assert "\n".join(expected) in out