def test_feed_filter_compatible_requirements(): "Install#feed() Should skip requirements that already have compatible matches in the mapping" # Given that I have the install command index = Index('') index.storage = {} install = Install(conf={'index': index}) # And I mock the finder service end-point install.finder.queue = Mock() install.pipeline() # When I feed the installer with a requirement *without dependencies* install.feed('tests', requirement='package (1.0)') # And I feed the installer with another requirement for the same # package above, requested by `something-else` install.feed('tests', requirement='package (3.0)', dependency_of='something-else') # Then I see that the requirement without any dependencies # (primary requirement) is the chosen one install.finder.queue.assert_called_once_with('tests', requirement='package (1.0)') install.mapping.requirements.should.equal(set(['package (1.0)']))
def test_index_feed_backend(): "It should be possible to save package paths granularly" # Given the following index index = Index('') # When I index a couple files index.index('http://localhost:800/p/gherkin-0.1.0-py27-none-any.whl') index.index('gherkin-0.1.0.tar.gz') index.index('Gherkin-0.1.5.tar.gz') # I know, weird right? index.index('a/weird/dir/gherkin-0.2.0.tar.gz') index.index('package.name-0.1.0.tar.gz') # Then I see that the backend structure looks right dict(index.storage).should.equal({ 'gherkin': { '0.2.0': [ 'gherkin-0.2.0.tar.gz', ], '0.1.5': [ 'Gherkin-0.1.5.tar.gz', ], '0.1.0': [ 'gherkin-0.1.0-py27-none-any.whl', 'gherkin-0.1.0.tar.gz', ], }, 'package.name': { '0.1.0': [ 'package.name-0.1.0.tar.gz', ] } })
def test_feed_filter_dups(): "Install#feed() Should skip duplicated requirements" # Given that I have the install command index = Index('') index.storage = {} install = Install(conf={'index': index}) # And I mock the finder service end-point install.finder.queue = Mock() install.pipeline() # Feed the installer with the requirement install.feed('tests', requirement='package') install.finder.queue.assert_called_once_with('tests', requirement='package') install.mapping.requirements.should.equal(set(['package'])) # When I fire the finder.finished() signal with proper data install.feed('tests', requirement='package') # Then I see the feed function just skipped this repeated requirement install.finder.queue.assert_called_once_with('tests', requirement='package') install.mapping.requirements.should.equal(set(['package']))
def test_request_install_cached_wheels(): "Request the installation of a cached package" # Given that I have a loaded local cache index = Index('') index.storage = {'gherkin': {'0.1.0': ['storage1/gherkin-0.1.0-py27-none-any.whl']}} # And that I have an environment associated with that local cache env = Env(conf={'index': index}) env.check_installed = Mock(return_value=False) env.services['download'] = Mock() env.services['install'] = Mock() # When I request an installation of a package env.request_install('gherkin==0.1.0').should.be.false # Then I see that, since the package was not installed, the locall cache # was queried and returned the right entry env.check_installed.assert_called_once_with('gherkin==0.1.0') # And I see that the install queue was populated env.services['install'].queue.assert_called_once_with( 'gherkin==0.1.0', 'main', path='storage1/gherkin-0.1.0-py27-none-any.whl') # And that the download queue was not touched env.services['download'].queue.called.should.be.false
def test_pipeline_downloader_tarzip_curdler(): "Install#pipeline() should route all the tar/zip files to the curdler" # Given that I have the install command index = Index('') index.storage = {} install = Install(conf={'index': index}) # And I mock the curdler service end-point and start all the services install.curdler.queue = Mock(__name__=str('queue')) install.pipeline() # Feed the installer with the requirement install.finder.queue = Mock() install.feed('tests', requirement='curdling') # When I fire the download.finished() signal with proper data install.downloader.emit('finished', 'downloader', requirement='curdling', tarball='curdling-0.1.tar.gz') # Than I see that the curdler received a request install.curdler.queue.assert_called_once_with( 'downloader', requirement='curdling', tarball='curdling-0.1.tar.gz')
def test_request_install_cached_wheels(): "Request the installation of a cached package" # Given that I have a loaded local cache index = Index('') index.storage = { 'gherkin': { '0.1.0': ['storage1/gherkin-0.1.0-py27-none-any.whl'] } } # And that I have an environment associated with that local cache env = Env(conf={'index': index}) env.check_installed = Mock(return_value=False) env.services['download'] = Mock() env.services['install'] = Mock() # When I request an installation of a package env.request_install('gherkin==0.1.0').should.be.false # Then I see that, since the package was not installed, the locall cache # was queried and returned the right entry env.check_installed.assert_called_once_with('gherkin==0.1.0') # And I see that the install queue was populated env.services['install'].queue.assert_called_once_with( 'gherkin==0.1.0', 'main', path='storage1/gherkin-0.1.0-py27-none-any.whl') # And that the download queue was not touched env.services['download'].queue.called.should.be.false
def test_retrieve_and_build(): "Install#retrieve_and_build() " # Given that I have an installer with a working index index = Index(FIXTURE('tmp')) installer = Install(**{ 'conf': { 'index': index, 'pypi_urls': ['http://localhost:8000/simple'] }, }) installer.pipeline() # And I feed the installer with a requirement installer.feed('tests', requirement='gherkin') # And start the installer installer.start() # When I run the retrieve and build loop packages = installer.retrieve_and_build() # Than I see that the package was retrieved packages.should.equal(set(['gherkin'])) # And I clean the mess index.delete()
def test_install_feed_when_theres_a_wheel_cached(): "Install#feed() Should route the requirements that already have a wheel to the dependencer" # Given that I have a loaded local cache index = Index('') index.storage = { 'gherkin': { '0.1.0': ['storage1/gherkin-0.1.0-py27-none-any.whl'] } } # And that I have an environment associated with that local cache env = Install(conf={'index': index}) env.pipeline() env.downloader.queue = Mock() env.dependencer.queue = Mock() env.curdler.queue = Mock() # When I request an installation of a package env.feed('tests', requirement='gherkin==0.1.0') # # Then I see that, since the package was not installed, the locall cache # # was queried and returned the right entry # env.check_installed.assert_called_once_with('gherkin==0.1.0') # And I see that the install queue was populated env.dependencer.queue.assert_called_once_with( 'tests', requirement='gherkin==0.1.0', wheel='storage1/gherkin-0.1.0-py27-none-any.whl', ) # And that the download queue was not touched env.downloader.queue.called.should.be.false
def test_curd_package(): "It should possible to convert regular packages to wheels" # Given that I have a storage containing a package index = Index(FIXTURE('storage1')) index.scan() # And a curdling using that index curdling = Curdler(**{'index': index}) # When I request a curd to be created package = curdling.handle('main', { 'tarball': index.get('gherkin==0.1.0;~whl'), 'requirement': 'gherkin (0.1.0)', }) # Then I see it's a wheel package. package['wheel'].should.match( FIXTURE('storage1/gherkin-0.1.0-py\d{2}-none-any.whl')) # And that it's present in the index package = index.get('gherkin==0.1.0;whl') # And that the file was created in the file system os.path.exists(package).should.be.true # And I delete the file os.unlink(package)
def test_curd_package(): "It should possible to convert regular packages to wheels" # Given that I have a storage containing a package index = Index(FIXTURE('storage1')) index.scan() # And a curdling using that index curdling = Curdling(index=index) # When I request a curd to be created package = curdling.wheel('gherkin==0.1.0', ('main', { 'path': index.get('gherkin==0.1.0;~whl')})) # Then I see it's a wheel package. package.should.equal({ 'path': FIXTURE('storage1/gherkin-0.1.0-py27-none-any.whl'), }) # And that it's present in the index package = index.get('gherkin==0.1.0;whl') # And that the file was created in the file system os.path.exists(package).should.be.true # And I delete the file os.unlink(package)
def test_pipeline_curdler_wheel_dependencer(): "Install#pipeline() should route all the wheel files from the curdler to the dependencer" # Given that I have the install command index = Index('') index.storage = {} install = Install(conf={'index': index}) # And I mock the curdler service end-point and start all the services install.dependencer.queue = Mock(__name__=str('queue')) install.pipeline() # Feed the installer with the requirement install.finder.queue = Mock() install.feed('tests', requirement='curdling') # When I fire the curdler.finished() signal with proper data install.curdler.emit('finished', 'curdler', requirement='curdling', wheel='curdling-0.1.0-py27-none-any.whl') # Than I see that the dependencer received a request install.dependencer.queue.assert_called_once_with( 'curdler', requirement='curdling', wheel='curdling-0.1.0-py27-none-any.whl')
def test_install_feed_when_theres_a_wheel_cached(): "Install#feed() Should route the requirements that already have a wheel to the dependencer" # Given that I have a loaded local cache index = Index('') index.storage = {'gherkin': {'0.1.0': ['storage1/gherkin-0.1.0-py27-none-any.whl']}} # And that I have an environment associated with that local cache env = Install(conf={'index': index}) env.pipeline() env.downloader.queue = Mock() env.dependencer.queue = Mock() env.curdler.queue = Mock() # When I request an installation of a package env.feed('tests', requirement='gherkin==0.1.0') # # Then I see that, since the package was not installed, the locall cache # # was queried and returned the right entry # env.check_installed.assert_called_once_with('gherkin==0.1.0') # And I see that the install queue was populated env.dependencer.queue.assert_called_once_with( 'tests', requirement='gherkin==0.1.0', wheel='storage1/gherkin-0.1.0-py27-none-any.whl', ) # And that the download queue was not touched env.downloader.queue.called.should.be.false
def test_index_get_corner_case_pkg_name(): "It should be possible to search for packages that contain `_` in their name" # Given that I have an index loaded with a couple package references index = Index("") index.storage = {"python-gherkin": {"0.1.0": ["python_gherkin-0.1.0.tar.gz"]}} index.get("python-gherkin==0.1.0;~whl").should.equal("python_gherkin-0.1.0.tar.gz")
def test_index_scan_when_there_is_no_dir(): "Index.scan() should not fail when the dir does not exist" # Given that I have an index that points to a directory that already # contains packages index = Index('I know this directory does not exist') # When I scan the directory, I see it does not fail index.scan()
def test_index_ensure_path_for_existing_dirs(patched_os): "Test utility method Index.ensure_path() for existing directories" # We'll need that inside of ensure_path() patched_os.path.dirname = os.path.dirname # Given that I have an index index = Index('') # When I call ensure_path(resource) against a directory that exists to # exists, it *SHOULD NOT* try to create the directory patched_os.path.isdir.return_value = True index.ensure_path('path/to/my/resource') patched_os.makedirs.called.should.be.false
def test_index_scan(): "It should be possible to scan for already existing folders" # Given that I have an index that points to a folder that already contains # packages index = Index(FIXTURE('storage1')) # When I scan the directory index.scan() # Then I can look for packages index.get('gherkin==0.1.0').should.equal( FIXTURE('storage1/gherkin-0.1.0.tar.gz'), )
def test_index_ensure_path(patched_os): "Test utility method Index.ensure_path()" # We'll need that inside of ensure_path() patched_os.path.dirname = os.path.dirname # Given that I have an index index = Index('') # When I call ensure_path(resource) against a directory that doesn't seem # to exist, it should try to create the directory for the resource patched_os.path.isdir.return_value = False index.ensure_path('path/to/my/resource') patched_os.makedirs.assert_called_once_with('path/to/my')
def test_index_get_corner_case_pkg_name(): "It should be possible to search for packages that contain `_` in their name" # Given that I have an index loaded with a couple package references index = Index('') index.storage = { 'python-gherkin': { '0.1.0': [ 'python_gherkin-0.1.0.tar.gz', ] } } index.get('python-gherkin==0.1.0;~whl').should.equal('python_gherkin-0.1.0.tar.gz')
def test_pipeline_finder_found_downloader(): "Install#pipeline() should route the finder output to the downloader" # Given that I have the install command index = Index('') index.storage = {} install = Install(conf={'index': index}) # And I mock the downloader service end-point install.finder.queue = Mock(__name__=str('queue')) install.downloader.queue = Mock(__name__=str('queue')) install.pipeline() # Feed the installer with the requirement install.finder.queue = Mock() install.feed('tests', requirement='package') install.feed('tests', requirement='package (0.0.1)') # When I fire the finder.finished() signal with proper data install.finder.emit( 'finished', 'finder', requirement='package', url='http://srv.com/package.tar.gz', locator_url='http://*****:*****@srv.com/simple', ) # And manually add the first package to the `processing_packages` set, # because we mock `queue`, the component that actually does that for us. install.downloader.processing_packages.add('package.tar.gz') # And When I fire another finished signal with a different requirement but # the same url install.finder.emit( 'finished', 'finder', requirement='package (0.0.1)', url='http://another.srv.com/package.tar.gz', locator_url='http://srv.com/simple', ) # Then I see that the downloader received a single request. The second one # was duplicated install.downloader.queue.assert_called_once_with( 'finder', requirement='package', url='http://srv.com/package.tar.gz', locator_url='http://*****:*****@srv.com/simple', )
def test_index_get_corner_case_pkg_name(): "It should be possible to search for packages that contain `_` in their name" # Given that I have an index loaded with a couple package references index = Index('') index.storage = { 'python-gherkin': { '0.1.0': [ 'python_gherkin-0.1.0.tar.gz', ] } } index.get('python-gherkin==0.1.0;~whl').should.equal( 'python_gherkin-0.1.0.tar.gz')
def test_install_package(): "It should possible to install wheels" # Given that I have an installer configured with a loaded index index = Index(FIXTURE("storage2")) index.scan() installer = Installer(**{"index": index}) # When I request a curd to be created installer.handle("main", {"requirement": "gherkin==0.1.0", "wheel": index.get("gherkin==0.1.0;whl")}) # Then I see that the package was installed Database.check_installed("gherkin==0.1.0").should.be.true # And I uninstall the package Database.uninstall("gherkin==0.1.0")
def test_downloader(): "It should be possible to download packages from pip repos" # Given the following downloader component sources = [PipSource(urls=['http://localhost:8000/simple'])] index = Index(FIXTURE('tmpindex')) downloader = DownloadManager(sources=sources, index=index) # When I try to retrieve a package from it package = downloader.retrieve('gherkin==0.1.0', 'main') # Then I see that the package was downloaded correctly to the storage index.get('gherkin==0.1.0').should_not.be.empty # And I cleanup the mess index.delete()
def test_pipeline_finder_found_downloader(): "Install#pipeline() should route the finder output to the downloader" # Given that I have the install command index = Index('') index.storage = {} install = Install(conf={'index': index}) # And I mock the downloader service end-point install.finder.queue = Mock(__name__=str('queue')) install.downloader.queue = Mock(__name__=str('queue')) install.pipeline() # Feed the installer with the requirement install.finder.queue = Mock() install.feed('tests', requirement='package') install.feed('tests', requirement='package (0.0.1)') # When I fire the finder.finished() signal with proper data install.finder.emit('finished', 'finder', requirement='package', url='http://srv.com/package.tar.gz', locator_url='http://*****:*****@srv.com/simple', ) # And manually add the first package to the `processing_packages` set, # because we mock `queue`, the component that actually does that for us. install.downloader.processing_packages.add('package.tar.gz') # And When I fire another finished signal with a different requirement but # the same url install.finder.emit('finished', 'finder', requirement='package (0.0.1)', url='http://another.srv.com/package.tar.gz', locator_url='http://srv.com/simple', ) # Then I see that the downloader received a single request. The second one # was duplicated install.downloader.queue.assert_called_once_with( 'finder', requirement='package', url='http://srv.com/package.tar.gz', locator_url='http://*****:*****@srv.com/simple', )
def test_feed_filter_blacklisted_packages(): "Install#feed() Should skip blacklisted package names" # Given that I have the install command index = Index('') index.storage = {} install = Install(conf={'index': index}) # And I mock the finder service end-point install.finder.queue = Mock() install.pipeline() # When I feed the installer with the requirement install.feed('tests', requirement='setuptools') # Then I see it was just skipped install.finder.queue.called.should.be.false
def test_install_package(): "It should possible to install wheels" # Given that I have an installer configured with a loaded index index = Index(FIXTURE('storage2')) index.scan() installer = Installer(index=index) # When I request a curd to be created installer.install('gherkin==0.1.0', ('main', { 'path': index.get('gherkin==0.1.0;whl')})) # Then I see that the package was installed Env({}).check_installed('gherkin==0.1.0').should.be.true # And I uninstall the package Env({}).uninstall('gherkin==0.1.0')
def test_pipeline_update_mapping_errors(): "Install#pipeline() Should update Install#mapping#errors whenever an error occurs" # Given that I have the install command index = Index('') index.storage = {} install = Install(conf={'index': index}) install.pipeline() install.finder.handle = Mock(side_effect=Exception('P0wned!')) # When I feed the installer with a requirement install.feed('tests', requirement='pkg (0.1)') install.finder.queue(None) install.finder._worker() install.mapping.errors.should.have.length_of(1) str(install.mapping.errors['pkg'][0]['exception']).should.equal('P0wned!')
def test_feed_requirement_finder(): "Install#feed() should route all queued requirements to the finder" # Given that I have the install command index = Index('') index.storage = {} install = Install(conf={'index': index}) install.pipeline() # And I mock some service end-points install.finder.queue = Mock() # When I request the installation of a new requirement install.feed('tests', requirement='curdling') # Then I see the finder received a request install.finder.queue.assert_called_once_with('tests', requirement='curdling')
def test_pipeline_dependencer_queue(): "Install#pipeline() should route all the requirements from the dependencer to Install#feed()" # Given that I have the install command index = Index('') index.storage = {} install = Install(conf={'index': index}) # And I mock the curdler service end-point and start all the services install.feed = Mock(__name__=str('feed')) install.pipeline() # When I fire the download.finished() signal with proper data install.dependencer.emit('dependency_found', 'dependencer', requirement='curdling (0.3.0)') # Than I see that the curdler received a request install.feed.assert_called_once_with( 'dependencer', requirement='curdling (0.3.0)')
def test_feed_requirement_finder(): "Install#feed() should route all queued requirements to the finder" # Given that I have the install command index = Index('') index.storage = {} install = Install(conf={'index': index}) install.pipeline() # And I mock some service end-points install.finder.queue = Mock() # When I request the installation of a new requirement install.feed('tests', requirement='curdling') # Then I see the finder received a request install.finder.queue.assert_called_once_with( 'tests', requirement='curdling')
def test_pipeline_dependencer_queue(): "Install#pipeline() should route all the requirements from the dependencer to Install#handle()" # Given that I have the install command index = Index('') index.storage = {} install = Install(conf={'index': index}) # And I mock the curdler service end-point and start all the services install.queue = Mock(__name__=str('handle')) install.pipeline() # When I fire the download.finished() signal with proper data install.dependencer.emit('dependency_found', 'dependencer', requirement='curdling (0.3.0)') # Than I see that the curdler received a request install.queue.assert_called_once_with( 'dependencer', requirement='curdling (0.3.0)')
def test_install_package(): "It should possible to install wheels" # Given that I have an installer configured with a loaded index index = Index(FIXTURE('storage2')) index.scan() installer = Installer(index=index) # When I request a curd to be created installer.install('gherkin==0.1.0', ('main', { 'path': index.get('gherkin==0.1.0;whl') })) # Then I see that the package was installed Env({}).check_installed('gherkin==0.1.0').should.be.true # And I uninstall the package Env({}).uninstall('gherkin==0.1.0')
def test_downloader_with_no_sources(): "It should be possible to download packages from pip repos" # Given the following downloader component with NO SOURCES downloader = DownloadManager(sources=[], index=Index('')) # When I try to retrieve a package from it, than I see it just blows up # with a nice exception downloader.retrieve.when.called_with( 'main', 'gherkin==0.1.0').should.throw(ReportableError)
def test_install_package(): "It should possible to install wheels" # Given that I have an installer configured with a loaded index index = Index(FIXTURE('storage2')) index.scan() installer = Installer(**{'index': index}) # When I request a curd to be created installer.handle('main', { 'requirement': 'gherkin==0.1.0', 'wheel': index.get('gherkin==0.1.0;whl'), }) # Then I see that the package was installed Database.check_installed('gherkin==0.1.0').should.be.true # And I uninstall the package Database.uninstall('gherkin==0.1.0')
def test_install_package(): "It should possible to install wheels" # Given that I have an installer configured with a loaded index index = Index(FIXTURE('storage2')) index.scan() installer = Installer(**{'index': index}) # When I request a curd to be created installer.handle( 'main', { 'requirement': 'gherkin==0.1.0', 'wheel': index.get('gherkin==0.1.0;whl'), }) # Then I see that the package was installed Database.check_installed('gherkin==0.1.0').should.be.true # And I uninstall the package Database.uninstall('gherkin==0.1.0')
def test_pipeline_update_mapping_stats(): "Install#pipeline() Should update the Install#mapping#stats" # Given that I have the install command index = Index('') index.storage = {} install = Install(conf={'index': index}) install.pipeline() install.finder.handle = Mock(return_value={ 'requirement': 'pkg', 'url': 'pkg.tar.gz', }) # When I feed the installer with a requirement install.feed('tests', requirement='pkg') install.finder.queue(None) install.finder._worker() install.mapping.count('finder').should.equal(1)
def test_feed_link_download(): "Install#feed() should route all queued links to the downloader" # Given that I have the install command index = Index('') index.storage = {} install = Install(conf={'index': index}) install.pipeline() # And I mock some service end-points install.downloader.queue = Mock() # When I request the installation of a new requirement install.feed('tests', requirement='http://srv/pkgs/curdling-0.1.tar.gz') # I see that the downloader received a request install.downloader.queue.assert_called_once_with( 'tests', requirement='http://srv/pkgs/curdling-0.1.tar.gz', url='http://srv/pkgs/curdling-0.1.tar.gz')
def test_downloader_with_no_packages(): "After downloading packages, the result queue should be fed" # Given the following downloader component sources = [PipSource(urls=['http://localhost:8000/simple'])] index = Index(FIXTURE('tmpindex')) downloader = DownloadManager(sources=sources, index=index) # When I try to retrieve a package from it downloader.retrieve.when.called_with( 'donotexist==0.1.0', ('main', {})).should.throw( ReportableError, 'No distributions found for donotexist==0.1.0')
def test_downloader(): "It should be possible to download packages from pip repos" # Given that I have a finder pointing to our local pypi server finder = Finder(**{"conf": {"pypi_urls": ["http://localhost:8000/simple"]}}) # And a downloader pointing to a temporary index index = Index(FIXTURE("tmpindex")) downloader = Downloader(**{"index": index}) # When I find the link link = finder.handle("tests", {"requirement": "gherkin (== 0.1.0)"}) # And When I try to retrieve a package from it downloader.handle("main", link) # Then I see that the package was downloaded correctly to the storage index.get("gherkin==0.1.0").should_not.be.empty # And I cleanup the mess index.delete()
def test_curd_package(): "It should possible to convert regular packages to wheels" # Given that I have a storage containing a package index = Index(FIXTURE('storage1')) index.scan() # And a curdling using that index curdling = Curdling(index=index) # When I request a curd to be created package = curdling.wheel('gherkin==0.1.0', ('main', { 'path': index.get('gherkin==0.1.0;~whl') })) # Then I see it's a wheel package. package.should.equal({ 'path': FIXTURE('storage1/gherkin-0.1.0-py27-none-any.whl'), }) # And that it's present in the index package = index.get('gherkin==0.1.0;whl') # And that the file was created in the file system os.path.exists(package).should.be.true # And I delete the file os.unlink(package)
def test_curd_package(): "It should possible to convert regular packages to wheels" # Given that I have a storage containing a package index = Index(FIXTURE('storage1')) index.scan() # And a curdling using that index curdling = Curdler(**{'index': index}) # When I request a curd to be created package = curdling.handle( 'main', { 'tarball': index.get('gherkin==0.1.0;~whl'), 'requirement': 'gherkin (0.1.0)', }) # Then I see it's a wheel package. package['wheel'].should.match( FIXTURE('storage1/gherkin-0.1.0-py\d{2}-none-any.whl')) # And that it's present in the index package = index.get('gherkin==0.1.0;whl') # And that the file was created in the file system os.path.exists(package).should.be.true # And I delete the file os.unlink(package)
def test_downloader(): "It should be possible to download packages from pip repos" # Given that I have a finder pointing to our local pypi server finder = Finder(**{ 'conf': { 'pypi_urls': ['http://localhost:8000/simple'] }, }) # And a downloader pointing to a temporary index index = Index(FIXTURE('tmpindex')) downloader = Downloader(**{'index': index}) # When I find the link link = finder.handle('tests', {'requirement': 'gherkin (== 0.1.0)'}) # And When I try to retrieve a package from it downloader.handle('main', link) # Then I see that the package was downloaded correctly to the storage index.get('gherkin==0.1.0').should_not.be.empty # And I cleanup the mess index.delete()
def test_retrieve_and_build(): "Install#retrieve_and_build() " # Given that I have an installer with a working index index = Index(FIXTURE("tmp")) installer = Install(**{"conf": {"index": index, "pypi_urls": ["http://localhost:8000/simple"]}}) installer.pipeline() # And I handle the installer with a requirement installer.queue("tests", requirement="gherkin") # And start the installer installer.start() # When I run the retrieve and build loop packages = installer.retrieve_and_build() # Than I see that the package was retrieved packages.should.equal(set(["gherkin"])) # And I clean the mess index.delete()
def test_index_from_data(): "It should be possible to index data from memory" # Given the following index index = Index(FIXTURE('index')) # When I index a file data = open(FIXTURE('storage1/gherkin-0.1.0.tar.gz'), 'rb').read() index.from_data(path='gherkin-0.1.0.tar.gz', data=data) # Then I see it inside of the index index.get('gherkin==0.1.0').should.equal( FIXTURE('index/gherkin-0.1.0.tar.gz'), ) # And I clean the mess index.delete()
def test_downloader(): "It should be possible to download packages from pip repos" # Given that I have a finder pointing to our local pypi server finder = Finder(**{ 'conf': {'pypi_urls': ['http://localhost:8000/simple']}, }) # And a downloader pointing to a temporary index index = Index(FIXTURE('tmpindex')) downloader = Downloader(**{'index': index}) # When I find the link link = finder.handle('tests', {'requirement': 'gherkin (== 0.1.0)'}) # And When I try to retrieve a package from it downloader.handle('main', link) # Then I see that the package was downloaded correctly to the storage index.get('gherkin==0.1.0').should_not.be.empty # And I cleanup the mess index.delete()
def test_load_installer_forward_errors(): "Install#load_installer() Should forward errors from other services when `installable_packages` != `initial_requirements`" # Given that I have the install command with an empty index index = Index('') index.storage = {} install = Install(conf={'index': index}) install.pipeline() # And I feed the installer with a requirement install.feed('tests', requirement='package') # And I cause an error in the download worker install.downloader.handle = Mock(side_effect=Exception('Beep-Bop')) # And I mock the installer queue install.installer.queue = Mock(__name__=str('queue')) # When I try to retrieve and build all the requirements install.start() install.retrieve_and_build() # And When I load the installer names, errors = install.load_installer() # Then I see the list of all successfully processed packages names.should.be.empty # And Then I see that the error list was filled properly errors.should.have.length_of(1) errors.should.have.key('package').with_value.being.a(list) errors['package'].should.have.length_of(1) errors['package'][0]['dependency_of'].should.equal([None]) errors['package'][0]['exception'].should.be.a(ReportableError) str(errors['package'][0]['exception']).should.equal( 'Requirement `package\' not found')
def test_index_from_file(): "It should be possible to index packages from files" # Given the following index index = Index(FIXTURE('index')) # When I index a file index.from_file(FIXTURE('storage1/gherkin-0.1.0.tar.gz')) # Then I see it inside of the index index.get('gherkin==0.1.0;gz').should.equal( FIXTURE('index/gherkin-0.1.0.tar.gz'), ) # And that there's no wheel available yet index.get.when.called_with('gherkin==0.1.0;whl').should.throw( PackageNotFound, ) # And I clean the mess index.delete()