Ejemplo n.º 1
0
 def test_simple_comparisons(self):
     self.assertEqual(VersionCompare("0.0.0", "0.0.1"), -1)
     self.assertEqual(VersionCompare("0.0.1", "0.0.2"), -1)
     self.assertEqual(VersionCompare("0.0.2", "0.1.0"), -1)
     self.assertEqual(VersionCompare("0.0.2", "0.0.10"), -1)
     self.assertEqual(VersionCompare("0.0.10", "0.1.0"), -1)
     self.assertEqual(VersionCompare("0.1.0", "0.1.1"), -1)
     self.assertEqual(VersionCompare("0.1.1", "1.0.0"), -1)
Ejemplo n.º 2
0
    def Fetch(self, statepath, update=True, logger=NoopLogger()):
        if os.path.isfile(statepath) and not update:
            logger.Log("no update requested, skipping")
            return

        state = {}

        if os.path.isfile(statepath):
            with open(statepath, 'r', encoding='utf-8') as oldstatefile:
                state = json.load(oldstatefile)
            logger.Log("loaded old state, {} entries".format(len(state)))
        else:
            logger.Log("starting with empty state")

        newdata = json.loads(Get(self.source).text)

        # add new entries in reversed order, oldest first so newest
        # have higher priority; may also compare versions here
        for entry in newdata['releases']:
            if not 'name' in entry:
                logger.Log("skipping entry with no name")
                continue

            if entry['name'] in state:
                oldentry = state[entry['name']]

                if VersionCompare(entry['version'], oldentry['version']) > 0:
                    logger.Log("replacing entry \"{}\", version changed {} -> {}".format(entry['name'], oldentry['version'], entry['version']))
                    state[entry['name']] = entry
            else:
                logger.Log("adding entry \"{}\", version {}".format(entry['name'], entry['version']))
                state[entry['name']] = entry


        temppath = statepath + ".tmp"
        with open(temppath, 'w', encoding='utf-8') as newstatefile:
            json.dump(state, newstatefile)

        os.rename(temppath, statepath)

        logger.Log("saved new state, {} entries".format(len(state)))
Ejemplo n.º 3
0
 def test_miscomparation2(self):
     # #16
     self.assertEqual(VersionCompare("4.89", "4.90.f"), -1)
Ejemplo n.º 4
0
 def test_miscomparation1(self):
     # #16
     self.assertEqual(VersionCompare("1.4c", "1.4e"), -1)
Ejemplo n.º 5
0
 def test_letter_addendum(self):
     self.assertEqual(VersionCompare("1.0", "1.0a"), -1)
     self.assertEqual(VersionCompare("1.0a", "1.0b"), -1)
Ejemplo n.º 6
0
 def test_letter_component(self):
     self.assertEqual(VersionCompare("1.0", "1.0.a"), 1)
     self.assertEqual(VersionCompare("1.0.a", "1.0.b"), -1)
Ejemplo n.º 7
0
 def test_bigger(self):
     self.assertEqual(VersionCompare("20160101", "20160102"), -1)
Ejemplo n.º 8
0
 def test_commutativity(self):
     self.assertEqual(VersionCompare("1.0", "1.1"), -1)
     self.assertEqual(VersionCompare("1.1", "1.0"), 1)
Ejemplo n.º 9
0
 def test_zeroes_at_right(self):
     self.assertEqual(VersionCompare("1", "1.0"), 0)
     self.assertEqual(VersionCompare("1", "1.0.0"), 0)