def newer_than(self, other_package): """Compare this package to another package with the same name. Return True if this package is newer, False if it is older, and None if they have equal versions. We first look at the version field and then the patch_version field. """ assert other_package.name==self.name, \ "Attempt to run newer_than() comparison between two different package types: %s and %s" % \ (self.name, other_package.name) v = compare_versions(self.version, other_package.version) if v==1: return True elif v==(-1): return False else: # same release level if self.patch_version==other_package.patch_version: return None # equal versions elif self.patch_version==None: return False # other version has a patch, so we'll consider it newer elif other_package.patch_version==None: return True # this version has a patch, so its newer else: pv = compare_versions(self.patch_version, other_package.patch_version) if pv==1: return True elif pv==(-1): return False else: return None
def test_second_less_than_first(): assert compare_versions('1.2.3', '0.1.0') == "Version '0.1.0' is less than '1.2.3'"
def test_equal_vertions(): assert compare_versions('1.2.3', '1.2.3') == "Version '1.2.3' is equal to '1.2.3'" assert compare_versions('0.1', '0.1.0') == "Version '0.1' is equal to '0.1.0'" assert compare_versions('1', '1.0.0') == "Version '1' is equal to '1.0.0'"
def test_first_less_than_second(): assert compare_versions('1.2.3', '2.1.0') == "Version '1.2.3' is less than '2.1.0'"
def test_second_less_on_digit_two(): assert compare_versions('1.3.1', '1.5.0') == "Version '1.3.1' is less than '1.5.0'"
def test_first_minor_on_last_digit(): assert compare_versions( '1.0.9', '1.0.10') == "Version '1.0.9' is less than '1.0.10'" assert compare_versions('0.3', '0.4') == "Version '0.3' is less than '0.4'" assert compare_versions('1', '2') == "Version '1' is less than '2'"
def test_one_value_vs_more_values(): assert compare_versions('1', '2.1.0') == "Version '1' is less than '2.1.0'" assert compare_versions('1', '2.1') == "Version '1' is less than '2.1'" assert compare_versions('1.0', '2') == "Version '1.0' is less than '2'"