def test_compare_partial_to_self(self): for text in self.partial_versions: with self.subTest(text=text): self.assertEqual( base.Version(text, partial=True), base.Version(text, partial=True)) self.assertNotEqual(text, base.Version(text, partial=True))
def test_select_incompatible(self): s = base.Spec('>=0.1.1,!=0.1.4') res = s.select([ base.Version('0.1.0'), base.Version('0.1.4'), base.Version('0.1.4-alpha'), ]) self.assertIsNone(res)
def test_filter_incompatible(self): s = base.Spec('>=0.1.1,!=0.1.4') res = tuple(s.filter([ base.Version('0.1.0'), base.Version('0.1.4'), base.Version('0.1.4-alpha'), ])) self.assertEqual((), res)
def test_spec(self): for spec, lists in self.examples.items(): matching, failing = lists for version in matching: with self.subTest(spec=spec, version=version): self.assertIn(base.Version(version), base.NpmSpec(spec)) for version in failing: with self.subTest(spec=spec, version=version): self.assertNotIn(base.Version(version), base.NpmSpec(spec))
def test_matches(self): for spec_text, versions in self.matches.items(): spec = base.SpecItem(spec_text) matching, failing = versions for version_text in matching: version = base.Version(version_text) self.assertTrue(spec.match(version), "%r should match %r" % (version, spec)) for version_text in failing: version = base.Version(version_text) self.assertFalse(spec.match(version), "%r should not match %r" % (version, spec))
def test_parsing(self): for text, expected_fields in self.versions.items(): with self.subTest(text=text): version = base.Version(text) actual_fields = (version.major, version.minor, version.patch, version.prerelease, version.build) self.assertEqual(expected_fields, actual_fields)
def test_parsing_partials(self): for text, expected_fields in self.partial_versions.items(): version = base.Version(text, partial=True) actual_fields = (version.major, version.minor, version.patch, version.prerelease, version.build) self.assertEqual(expected_fields, actual_fields) self.assertTrue(version.partial, "%r should have partial=True" % version)
def test_coerce(self): for equivalent, samples in self.examples.items(): target = base.Version(equivalent) for sample in samples: with self.subTest(target=equivalent, sample=sample): v_sample = base.Version.coerce(sample) self.assertEqual(target, v_sample)
def test_str_partials(self): for text in self.partial_versions: with self.subTest(text=text): version = base.Version(text, partial=True) self.assertEqual(text, str(version)) self.assertEqual("Version('%s', partial=True)" % text, repr(version))
def test_matches(self): for spec_list_text, versions in self.matches.items(): spec_list = base.Spec(spec_list_text) matching, failing = versions for version_text in matching: version = base.Version(version_text) self.assertTrue(version in spec_list, "%r should be in %r" % (version, spec_list)) self.assertTrue(spec_list.match(version), "%r should match %r" % (version, spec_list)) for version_text in failing: version = base.Version(version_text) self.assertFalse(version in spec_list, "%r should not be in %r" % (version, spec_list)) self.assertFalse(spec_list.match(version), "%r should not match %r" % (version, spec_list))
def test_filter_compatible(self): s = base.Spec('>=0.1.1,!=0.1.4,<0.2.0') res = tuple(s.filter([ base.Version('0.1.0'), base.Version('0.1.1'), base.Version('0.1.5'), base.Version('0.1.4-alpha'), base.Version('0.1.2'), base.Version('0.2.0-rc1'), base.Version('3.14.15'), ])) expected = ( base.Version('0.1.1'), base.Version('0.1.5'), base.Version('0.1.2'), ) self.assertEqual(expected, res)
def test_select_compatible(self): s = base.Spec('>=0.1.1,!=0.1.4,<0.2.0') res = s.select([ base.Version('0.1.0'), base.Version('0.1.1'), base.Version('0.1.5'), base.Version('0.1.4-alpha'), base.Version('0.1.2'), base.Version('0.2.0-rc1'), base.Version('3.14.15'), ]) self.assertEqual(base.Version('0.1.5'), res)
def test_invalid_comparisons(self): v = base.Version('0.1.0') with self.assertRaises(TypeError): v < '0.1.0' with self.assertRaises(TypeError): v <= '0.1.0' with self.assertRaises(TypeError): v > '0.1.0' with self.assertRaises(TypeError): v >= '0.1.0' self.assertTrue(v != '0.1.0') self.assertFalse(v == '0.1.0')
def test_hash(self): self.assertEqual(1, len(set([base.Version('0.1.0'), base.Version('0.1.0')]))) self.assertEqual(2, len(set([base.Version('0.1.0'), base.Version('0.1.0', partial=True)]))) # A fully-defined 'partial' version isn't actually partial. self.assertEqual(1, len(set([ base.Version('0.1.0-a1+34'), base.Version('0.1.0-a1+34', partial=True) ])) )
def test_bump_prerelease_versions(self): # We Test each property explicitly as the == comparator for versions # does not distinguish between prerelease or builds for equality. v = base.Version('1.0.0-pre+build') v = v.next_major() self.assertEqual(v.major, 1) self.assertEqual(v.minor, 0) self.assertEqual(v.patch, 0) self.assertEqual(v.prerelease, ()) self.assertEqual(v.build, ()) v = base.Version('1.0.0-pre+build') v = v.next_minor() self.assertEqual(v.major, 1) self.assertEqual(v.minor, 0) self.assertEqual(v.patch, 0) self.assertEqual(v.prerelease, ()) self.assertEqual(v.build, ()) v = base.Version('1.0.0-pre+build') v = v.next_patch() self.assertEqual(v.major, 1) self.assertEqual(v.minor, 0) self.assertEqual(v.patch, 0) self.assertEqual(v.prerelease, ()) self.assertEqual(v.build, ()) v = base.Version('1.1.0-pre+build') v = v.next_major() self.assertEqual(v.major, 2) self.assertEqual(v.minor, 0) self.assertEqual(v.patch, 0) self.assertEqual(v.prerelease, ()) self.assertEqual(v.build, ()) v = base.Version('1.1.0-pre+build') v = v.next_minor() self.assertEqual(v.major, 1) self.assertEqual(v.minor, 1) self.assertEqual(v.patch, 0) self.assertEqual(v.prerelease, ()) self.assertEqual(v.build, ()) v = base.Version('1.1.0-pre+build') v = v.next_patch() self.assertEqual(v.major, 1) self.assertEqual(v.minor, 1) self.assertEqual(v.patch, 0) self.assertEqual(v.prerelease, ()) self.assertEqual(v.build, ()) v = base.Version('1.0.1-pre+build') v = v.next_major() self.assertEqual(v.major, 2) self.assertEqual(v.minor, 0) self.assertEqual(v.patch, 0) self.assertEqual(v.prerelease, ()) self.assertEqual(v.build, ()) v = base.Version('1.0.1-pre+build') v = v.next_minor() self.assertEqual(v.major, 1) self.assertEqual(v.minor, 1) self.assertEqual(v.patch, 0) self.assertEqual(v.prerelease, ()) self.assertEqual(v.build, ()) v = base.Version('1.0.1-pre+build') v = v.next_patch() self.assertEqual(v.major, 1) self.assertEqual(v.minor, 0) self.assertEqual(v.patch, 1) self.assertEqual(v.prerelease, ()) self.assertEqual(v.build, ())
def test_compare_to_self(self): for text in self.versions: self.assertEqual(base.Version(text), base.Version(text)) self.assertNotEqual(text, base.Version(text))
def test_str(self): for text in self.versions: version = base.Version(text) self.assertEqual(text, str(version)) self.assertEqual("Version('%s')" % text, repr(version))