def test_version(self): from pgxnclient import Spec from pgxnclient.commands.install import Download from pgxnclient.errors import ResourceNotFound opt = Mock() opt.status = Spec.STABLE cmd = Download(opt) for spec, res, data in [ ("foo", "1.2.0", {"stable": ["1.2.0"]}), ("foo", "1.2.0", {"stable": ["1.2.0", "1.2.0b"]}), ("foo=1.2", "1.2.0", {"stable": ["1.2.0"]}), ("foo>=1.1", "1.2.0", {"stable": ["1.1.0", "1.2.0"]}), ("foo>=1.1", "1.2.0", {"stable": ["1.1.0", "1.2.0"], "testing": ["1.3.0"], "unstable": ["1.4.0"]}), ]: spec = Spec.parse(spec) data = {"releases": dict([(k, [{"version": v} for v in vs]) for k, vs in data.items()])} self.assertEqual(res, cmd.get_best_version(data, spec)) for spec, res, data in [ ("foo>=1.3", "1.2.0", {"stable": ["1.2.0"]}), ("foo>=1.3", "1.2.0", {"stable": ["1.2.0"], "testing": ["1.3.0"]}), ]: spec = Spec.parse(spec) data = {"releases": dict([(k, [{"version": v} for v in vs]) for k, vs in data.items()])} self.assertRaises(ResourceNotFound, cmd.get_best_version, data, spec) opt.status = Spec.TESTING for spec, res, data in [ ("foo>=1.1", "1.3.0", {"stable": ["1.1.0", "1.2.0"], "testing": ["1.3.0"], "unstable": ["1.4.0"]}) ]: spec = Spec.parse(spec) data = {"releases": dict([(k, [{"version": v} for v in vs]) for k, vs in data.items()])} self.assertEqual(res, cmd.get_best_version(data, spec)) opt.status = Spec.UNSTABLE for spec, res, data in [ ("foo>=1.1", "1.4.0", {"stable": ["1.1.0", "1.2.0"], "testing": ["1.3.0"], "unstable": ["1.4.0"]}) ]: spec = Spec.parse(spec) data = {"releases": dict([(k, [{"version": v} for v in vs]) for k, vs in data.items()])} self.assertEqual(res, cmd.get_best_version(data, spec))
def get_spec(self, _can_be_local=False): """ Return the package specification requested. Return a `Spec` instance. """ spec = self.opts.spec try: spec = Spec.parse(spec) except (ValueError, BadSpecError), e: self.parser.error(_("cannot parse package '%s': %s") % (spec, e))
def get_spec(self, _can_be_local=False, _can_be_url=False): """ Return the package specification requested. Return a `Spec` instance. """ spec = self.opts.spec try: spec = Spec.parse(spec) except (ValueError, BadSpecError), e: self.parser.error(_("cannot parse package '%s': %s") % (spec, e))
def get_spec(self, _can_be_local=False, _can_be_url=False): """ Return the package specification requested. Return a `Spec` instance. """ spec = self.opts.spec try: spec = Spec.parse(spec) except (ValueError, BadSpecError) as e: self.parser.error(_("cannot parse package '%s': %s") % (spec, e)) if not _can_be_local and spec.is_local(): raise PgxnClientException( _("you cannot use a local resource with this command")) if not _can_be_url and spec.is_url(): raise PgxnClientException( _("you cannot use an url with this command")) return spec
def test_version(self): from pgxnclient import Spec from pgxnclient.commands.install import Download from pgxnclient.errors import ResourceNotFound opt = Mock() opt.status = Spec.STABLE cmd = Download(opt) for spec, res, data in [ ('foo', '1.2.0', { 'stable': ['1.2.0'] }), ('foo', '1.2.0', { 'stable': ['1.2.0', '1.2.0b'] }), ('foo=1.2', '1.2.0', { 'stable': ['1.2.0'] }), ('foo>=1.1', '1.2.0', { 'stable': ['1.1.0', '1.2.0'] }), ('foo>=1.1', '1.2.0', { 'stable': ['1.1.0', '1.2.0'], 'testing': ['1.3.0'], 'unstable': ['1.4.0'], }), ]: spec = Spec.parse(spec) data = { 'releases': dict([(k, [{ 'version': v } for v in vs]) for k, vs in data.items()]) } self.assertEqual(res, cmd.get_best_version(data, spec)) for spec, res, data in [ ('foo>=1.3', '1.2.0', { 'stable': ['1.2.0'] }), ('foo>=1.3', '1.2.0', { 'stable': ['1.2.0'], 'testing': ['1.3.0'], }), ]: spec = Spec.parse(spec) data = { 'releases': dict([(k, [{ 'version': v } for v in vs]) for k, vs in data.items()]) } self.assertRaises(ResourceNotFound, cmd.get_best_version, data, spec) opt.status = Spec.TESTING for spec, res, data in [ ('foo>=1.1', '1.3.0', { 'stable': ['1.1.0', '1.2.0'], 'testing': ['1.3.0'], 'unstable': ['1.4.0'], }), ]: spec = Spec.parse(spec) data = { 'releases': dict([(k, [{ 'version': v } for v in vs]) for k, vs in data.items()]) } self.assertEqual(res, cmd.get_best_version(data, spec)) opt.status = Spec.UNSTABLE for spec, res, data in [ ('foo>=1.1', '1.4.0', { 'stable': ['1.1.0', '1.2.0'], 'testing': ['1.3.0'], 'unstable': ['1.4.0'], }), ]: spec = Spec.parse(spec) data = { 'releases': dict([(k, [{ 'version': v } for v in vs]) for k, vs in data.items()]) } self.assertEqual(res, cmd.get_best_version(data, spec))
def test_version(self): from pgxnclient import Spec from pgxnclient.commands.install import Download from pgxnclient.errors import ResourceNotFound opt = Mock() opt.status = Spec.STABLE cmd = Download(opt) for spec, res, data in [ ('foo', '1.2.0', {'stable': [ '1.2.0' ]}), ('foo', '1.2.0', {'stable': [ '1.2.0', '1.2.0b' ]}), ('foo=1.2', '1.2.0', {'stable': [ '1.2.0' ]}), ('foo>=1.1', '1.2.0', {'stable': [ '1.1.0', '1.2.0' ]}), ('foo>=1.1', '1.2.0', { 'stable': [ '1.1.0', '1.2.0' ], 'testing': [ '1.3.0' ], 'unstable': [ '1.4.0' ], }), ]: spec = Spec.parse(spec) data = { 'releases': dict([(k, [{'version': v} for v in vs]) for k, vs in data.items()]) } self.assertEqual(res, cmd.get_best_version(data, spec)) for spec, res, data in [ ('foo>=1.3', '1.2.0', {'stable': [ '1.2.0' ]}), ('foo>=1.3', '1.2.0', { 'stable': [ '1.2.0' ], 'testing': [ '1.3.0' ], }), ]: spec = Spec.parse(spec) data = { 'releases': dict([(k, [{'version': v} for v in vs]) for k, vs in data.items()]) } self.assertRaises(ResourceNotFound, cmd.get_best_version, data, spec) opt.status = Spec.TESTING for spec, res, data in [ ('foo>=1.1', '1.3.0', { 'stable': [ '1.1.0', '1.2.0' ], 'testing': [ '1.3.0' ], 'unstable': [ '1.4.0' ], }), ]: spec = Spec.parse(spec) data = { 'releases': dict([(k, [{'version': v} for v in vs]) for k, vs in data.items()]) } self.assertEqual(res, cmd.get_best_version(data, spec)) opt.status = Spec.UNSTABLE for spec, res, data in [ ('foo>=1.1', '1.4.0', { 'stable': [ '1.1.0', '1.2.0' ], 'testing': [ '1.3.0' ], 'unstable': [ '1.4.0' ], }), ]: spec = Spec.parse(spec) data = { 'releases': dict([(k, [{'version': v} for v in vs]) for k, vs in data.items()]) } self.assertEqual(res, cmd.get_best_version(data, spec))
def test_str(self): self.assertEqual(str(Spec('foo')), 'foo') self.assertEqual(str(Spec('foo>2.0')), 'foo>2.0') self.assertEqual(str(Spec('foo>2.0')), 'foo>2.0') self.assertEqual(str(Spec(dirname='/foo')), '/foo') self.assertEqual(str(Spec(dirname='/foo/foo.zip')), '/foo/foo.zip')