Esempio n. 1
0
 def test_clean(self):
     for s1, s2 in [
         ('1.2.2', '1.2.2'),
         ('01.2.2', '1.2.2'),
         ('1.02.2', '1.2.2'),
         ('1.2.02', '1.2.2'),
         ('1.2.02b', '1.2.2b'),
         ('1.2.02beta-3  ', '1.2.2beta-3'),
         ('1.02.02rc1', '1.2.2rc1'),
         ('1.0', '1.0.0'),
         ('1', '1.0.0'),
         ('.0.02', '0.0.2'),
         ('1..02', '1.0.2'),
         ('1..', '1.0.0'),
         ('1.1', '1.1.0'),
         ('1.2.b1', '1.2.0b1'),
         ('9.0beta4', '9.0.0beta4'),  # PostgreSQL format.
         ('9b', '9.0.0b'),
         ('rc1', '0.0.0rc1'),
         ('', '0.0.0'),
         ('..2', '0.0.2'),
         ('1.2.3 a', '1.2.3a'),
         ('..2 b', '0.0.2b'),
         ('  012.2.2', '12.2.2'),
         ('20110204', '20110204.0.0'),
     ]:
         self.assertEqual(SemVer.clean(s1), SemVer(s2))
Esempio n. 2
0
 def ar(s):
     try:
         SemVer.clean(s)
     except ValueError:
         pass
     else:
         self.fail("ValueError not raised: '%s'" % s)
Esempio n. 3
0
 def test_clean(self):
     for s1, s2 in [
         ('1.2.2', '1.2.2'),
         ('01.2.2', '1.2.2'),
         ('1.02.2', '1.2.2'),
         ('1.2.02', '1.2.2'),
         ('1.2.02b', '1.2.2-b'),
         ('1.2.02beta-3  ', '1.2.2-beta-3'),
         ('1.02.02rc1', '1.2.2-rc1'),
         ('1.0', '1.0.0'),
         ('1', '1.0.0'),
         ('.0.02', '0.0.2'),
         ('1..02', '1.0.2'),
         ('1..', '1.0.0'),
         ('1.1', '1.1.0'),
         ('1.2.b1', '1.2.0-b1'),
         ('9.0beta4', '9.0.0-beta4'),  # PostgreSQL format.
         ('9b', '9.0.0-b'),
         ('rc1', '0.0.0-rc1'),
         ('', '0.0.0'),
         ('..2', '0.0.2'),
         ('1.2.3 a', '1.2.3-a'),
         ('..2 b', '0.0.2-b'),
         ('  012.2.2', '12.2.2'),
         ('20110204', '20110204.0.0'),
     ]:
         try:
             self.assertEqual(SemVer.clean(s1), SemVer(s2))
         except Exception:
             print(s1, s2)
             raise
Esempio n. 4
0
 def test_ne(self):
     for s1, s2 in [
         ('1.2.2', '1.2.3'),
         ('0.0.1', '1.0.0'),
         ('1.0.1', '1.1.0'),
         ('1.1.1', '1.1.0'),
         ('1.2.3-b', '1.2.3'),
         ('1.2.3', '1.2.3-b'),
         ('1.2.3-a', '1.2.3-b'),
         ('1.2.3-aaaaaaa1', '1.2.3-aaaaaaa2'),
     ]:
         self.assertNotEqual(SemVer(s1), SemVer(s2))
         self.assertNotEqual(hash(SemVer(s1)), hash(SemVer(s2)))
Esempio n. 5
0
 def test_clean(self):
     for s1, s2 in [
         ('1.2.2',          '1.2.2'),
         ('01.2.2',         '1.2.2'),
         ('1.02.2',         '1.2.2'),
         ('1.2.02',         '1.2.2'),
         ('1.2.02b',        '1.2.2b'),
         ('1.2.02beta-3  ', '1.2.2beta-3'),
         ('1.02.02rc1',     '1.2.2rc1'),
         ('1.0',            '1.0.0'),
         ('1',              '1.0.0'),
         ('.0.02',          '0.0.2'),
         ('1..02',          '1.0.2'),
         ('1..',            '1.0.0'),
         ('1.1',            '1.1.0'),
         ('1.2.b1',         '1.2.0b1'),
         ('9.0beta4',       '9.0.0beta4'), # PostgreSQL format.
         ('9b',             '9.0.0b'),
         ('rc1',            '0.0.0rc1'),
         ('',               '0.0.0'),
         ('..2',            '0.0.2'),
         ('1.2.3 a',        '1.2.3a'),
         ('..2 b',          '0.0.2b'),
         ('  012.2.2',      '12.2.2'),
         ('20110204',  '20110204.0.0'), ]:
         self.assertEqual(SemVer.clean(s1), SemVer(s2))
Esempio n. 6
0
 def print_versions(self, spec):
     data = self._get_dist_data(spec.name)
     name = data['name']
     vs = [(SemVer(d['version']), s) for s, ds in data['releases'].items()
           for d in ds]
     vs = [(v, s) for v, s in vs if spec.accepted(v)]
     vs.sort(reverse=True)
     for v, s in vs:
         emit("%s %s %s" % (name, v, s))
Esempio n. 7
0
 def test_eq(self):
     for s1, s2 in [
         ('1.2.2', '1.2.2'),
         ('1.2.23', '1.2.23'),
         ('0.0.0', '0.0.0'),
         ('999.888.7777', '999.888.7777'),
         ('0.1.2beta3', '0.1.2beta3'),
         ('1.0.0rc-1', '1.0.0RC-1'),
     ]:
         self.assertEqual(SemVer(s1), SemVer(s2))
         self.assertEqual(hash(SemVer(s1)), hash(SemVer(s2)))
         self.assert_(
             SemVer(s1) <= SemVer(s2), "%s <= %s failed" % (s1, s2))
         self.assert_(
             SemVer(s1) >= SemVer(s2), "%s >= %s failed" % (s1, s2))
Esempio n. 8
0
    def get_best_version_from_ext(self, data, spec):
        """
        Return the best distribution version from an extension's data
        """
        # Get the maximum version for each release status satisfying the spec
        vers = [[] for i in range(len(Spec.STATUS))]
        vmap = {}  # ext_version -> (dist_name, dist_version)
        for ev, dists in data.get('versions', {}).items():
            ev = SemVer(ev)
            if not spec.accepted(ev):
                continue
            for dist in dists:
                dv = SemVer(dist['version'])
                ds = dist.get('status', 'stable')
                vers[Spec.STATUS[ds]].append(ev)
                vmap[ev] = (dist['dist'], dv)

        # for each rel status only take the max one.
        for i in range(len(vers)):
            vers[i] = vers[i] and max(vers[i]) or None

        ev = self._get_best_version(vers, spec, quiet=False)
        return vmap[ev]
Esempio n. 9
0
 def test_ok(self):
     for s in [
             '1.2.2',
             '0.2.2',
             '1.2.2',
             '0.0.0',
             '0.1.999',
             '9999.9999999.823823',
             '1.0.0beta1',
             '1.0.0beta2',
             '1.0.0',
             '20110204.0.0',
     ]:
         self.assertEqual(SemVer(s), s)
Esempio n. 10
0
 def test_dis(self):
     for s1, s2 in [
         ('2.2.2', '1.1.1'),
         ('2.2.2', '2.1.1'),
         ('2.2.2', '2.2.1'),
         ('2.2.2b', '2.2.1'),
         ('2.2.2', '2.2.2b'),
         ('2.2.2c', '2.2.2b'),
         ('2.2.2rc-2', '2.2.2RC-1'),
         ('0.9.10', '0.9.9'),
     ]:
         self.assert_(
             SemVer(s1) >= SemVer(s2), "%s >= %s failed" % (s1, s2))
         self.assert_(SemVer(s1) > SemVer(s2), "%s > %s failed" % (s1, s2))
         self.assert_(
             SemVer(s2) <= SemVer(s1), "%s <= %s failed" % (s2, s1))
         self.assert_(SemVer(s2) < SemVer(s1), "%s < %s failed" % (s2, s1))
Esempio n. 11
0
 def test_ok(self):
     for s in [
         '1.2.2',
         '0.2.2',
         '1.2.2',
         '0.0.0',
         '0.1.999',
         '9999.9999999.823823',
         '1.0.0beta1',  # no more valid according to semver
         '1.0.0beta2',  # no more valid according to semver
         '1.0.0-beta1',
         '1.0.0-beta2',
         '1.0.0',
         '20110204.0.0',
     ]:
         self.assertEqual(SemVer(s), s)
Esempio n. 12
0
    def get_best_version(self, data, spec, quiet=False):
        """
        Return the best version an user may want for a distribution.

        Return a `SemVer` instance.

        Raise `ResourceNotFound` if no version is found with the provided
        specification and options.
        """
        drels = data['releases']

        # Get the maximum version for each release status satisfying the spec
        vers = [None] * len(Spec.STATUS)
        for n, d in drels.items():
            vs = list(filter(spec.accepted, [SemVer(r['version']) for r in d]))
            if vs:
                vers[Spec.STATUS[n]] = max(vs)

        return self._get_best_version(vers, spec, quiet)
Esempio n. 13
0
    def run(self):
        spec = self.get_spec()
        assert not spec.is_local()

        if spec.is_url():
            return self._run_url(spec)

        data = self.get_meta(spec)

        try:
            chk = data['sha1']
        except KeyError:
            raise PgxnClientException(
                "sha1 missing from the distribution meta")

        with self.api.download(data['name'], SemVer(data['version'])) as fin:
            fn = network.download(fin, self.opts.target)

        self.verify_checksum(fn, chk)
        return fn