def test_job_loop_expected_errors(self): worker = MockWorker() worker.write_status = Mock() worker.args.one = False exceptions = [ requests.ConnectionError(), errors.ServerError("error"), errors.NotFound("not found") ] def exception_factory(a, b, c, exceptions=exceptions): """ raises each of the exceptions in order NotFound exception should break the loop The others should just trigger another iteration """ raise exceptions.pop(0) worker.bs.pop_build_job.side_effect = exception_factory with self.assertRaises(errors.NotFound): for i, job in enumerate(worker.job_loop()): if i > 3: raise RuntimeError('Ran loop more times than expected') worker.write_status.assert_called_with( False, "Trouble connecting to binstar") worker.write_status.assert_called_with(False, "Server error") worker.write_status.assert_called_with(False, "worker not found")
def test_package_not_exist(self): with patch('conda_env.specs.binstar.get_binstar') as get_binstar_mock: package = MagicMock(side_effect=errors.NotFound('msg')) binstar = MagicMock(package=package) get_binstar_mock.return_value = binstar spec = BinstarSpec(name='darth/no-exist') self.assertEqual(spec.package, None) self.assertEqual(spec.can_handle(), False)
def main(args): binstar = get_binstar(args, cls=BinstarBuildAPI) package_name = None user_name = None if args.git_url: args.path = args.git_url if args.git_url or is_url(args.path): args.git_url = args.path args.git_url_path = get_urlpath(args.path) args.dont_git_ignore = True submit_git_build(binstar, args) # not a github repo (must check for valid .binstar.yml file else: binstar_yml = join(args.path, '.binstar.yml') if not isfile(binstar_yml): raise UserError("file %s does not exist\n perhaps you should run\n\n binstar-build init\n" % binstar_yml) package_name = None user_name = None with open(binstar_yml) as cfg: for build in yaml.load_all(cfg): if build.get('package'): package_name = build.get('package') if build.get('user'): user_name = build.get('user') # Force package to exist if args.package: if user_name and not args.package.user == user_name: log.warn('User name does not match the user specified in the .binstar.yml file (%s != %s)', args.package.user, user_name) user_name = args.package.user if package_name and not args.package.name == package_name: log.warn('Package name does not match the user specified in the .binstar.yml file (%s != %s)', args.package.name, package_name) package_name = args.package.name else: if user_name is None: user = binstar.user() user_name = user['login'] if not package_name: raise UserError("You must specify the package name in the .binstar.yml file or the command line") try: _ = binstar.package(user_name, package_name) except errors.NotFound: log.error("The package %s/%s does not exist." % (user_name, package_name)) log.error("Run: \n\n binstar package --create %s/%s\n\n to create this package" % (user_name, package_name)) raise errors.NotFound('Package %s/%s' % (user_name, package_name)) args.package = PackageSpec(user_name, package_name) submit_build(binstar, args)
def main(args): binstar = get_binstar() # Force user auth user = binstar.user() package_name = None user_name = None binstar_yml = join(args.path, '.binstar.yml') if not isfile(binstar_yml): raise UserError("file %s does not exist" % binstar_yml) with open(binstar_yml) as cfg: for build in yaml.load_all(cfg): package_name = build.get('package') user_name = build.get('user') # Force package to exist if args.package: if user_name and not args.package.user == user_name: log.warn( 'User name does not match the user specified in the .binstar.yml file (%s != %s)', args.package.user, user_name) user_name = args.package.user if package_name and not args.package.name == package_name: log.warn( 'Package name does not match the user specified in the .binstar.yml file (%s != %s)', args.package.name, package_name) package_name = args.package.name else: if user_name is None: user_name = user['login'] if not package_name: raise UserError( "You must specify the package name in the .binstar.yml file or the command line" ) try: _ = binstar.package(user_name, package_name) except errors.NotFound: log.error("The package %s/%s does not exist." % (user_name, package_name)) log.error( "Run: 'binstar package --create %s/%s' to create this package" % (user_name, package_name)) raise errors.NotFound('Package %s/%s' % (user_name, package_name)) args.package = PackageSpec(user_name, package_name) if args.resubmit: log.info("Re submit build %s", args.resubmit) return resubmit_build(binstar, args) if args.tail: return tail(binstar, args) if args.halt: return halt_build(binstar, args) if args.list: return list_builds(binstar, args)
def test_package(self): binstar = mock.MagicMock() binstar.package.side_effect = errors.NotFound([]) binstar.add_package.return_value = 'package' uploader = Uploader(binstar, 'project') self.assertEqual(uploader.package, 'package')
def test_release_not_exist(self): binstar = mock.MagicMock() binstar.release.side_effect = errors.NotFound([]) binstar.add_release.return_value = 'release' uploader = Uploader(binstar, 'project') self.assertEqual(uploader.release, 'release')
def test_package(self): aserver_api = mock.MagicMock() aserver_api.package.side_effect = errors.NotFound([]) aserver_api.add_package.return_value = 'package' uploader = Uploader(aserver_api, 'project') self.assertEqual(uploader.package, 'package')
def test_release_not_exist(self): aserver_api = mock.MagicMock() aserver_api.release.side_effect = errors.NotFound([]) aserver_api.add_release.return_value = 'release' uploader = Uploader(aserver_api, 'project') self.assertEqual(uploader.release, 'release')