本文整理汇总了Python中snakeoil.compatibility.cmp函数的典型用法代码示例。如果您正苦于以下问题:Python cmp函数的具体用法?Python cmp怎么用?Python cmp使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cmp函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __cmp__
def __cmp__(self, other):
c = cmp(self.location, other.location)
if c:
return c
if isinstance(other, self.__class__):
return cmp(self.target, other.target)
return 0
示例2: test_cmp
def test_cmp(self):
pkg1 = self.make_fakepkg()
pkg2 = self.make_fakepkg(ver=2)
mpkg1 = MutatedPkg(pkg1, {})
mpkg2 = MutatedPkg(pkg2, {})
for lpkg in (pkg1, mpkg1):
self.assertTrue(cmp(lpkg, mpkg2) < 0)
self.assertTrue(cmp(mpkg2, lpkg) > 0)
self.assertEqual(mpkg1, mpkg1)
self.assertEqual(pkg1, mpkg1)
示例3: assertEqual2
def assertEqual2(self, o1, o2):
# logic bugs hidden behind short circuiting comparisons for metadata
# is why we test the comparison *both* ways.
self.assertEqual(o1, o2)
c = cmp(o1, o2)
self.assertEqual(c, 0,
msg="checking cmp for %r, %r, aren't equal: got %i" % (o1, o2, c))
self.assertEqual(o2, o1)
c = cmp(o2, o1)
self.assertEqual(c, 0,
msg="checking cmp for %r, %r,aren't equal: got %i" % (o2, o1, c))
示例4: assertNotEqual2
def assertNotEqual2(self, o1, o2):
# is why we test the comparison *both* ways.
self.assertNotEqual(o1, o2)
c = cmp(o1, o2)
self.assertNotEqual(c, 0,
msg="checking cmp for %r, %r, not supposed to be equal, got %i"
% (o1, o2, c))
self.assertNotEqual(o2, o1)
c = cmp(o2, o1)
self.assertNotEqual(c, 0,
msg="checking cmp for %r, %r, not supposed to be equal, got %i"
% (o2, o1, c))
示例5: ver_cmp
def ver_cmp(ver1, rev1, ver2, rev2):
if ver1 == ver2:
return cmp(rev1, rev2)
if ver1 is None:
ver1 = ''
if ver2 is None:
ver2 = ''
c = cmp(cpy_CPV("fake", "pkg", ver1, versioned=bool(ver1)),
cpy_CPV("fake", "pkg", ver2, versioned=bool(ver2)))
if c != 0:
return c
return cmp(rev1, rev2)
示例6: cpy_ver_cmp
def cpy_ver_cmp(ver1, rev1, ver2, rev2):
if ver1 == ver2:
return cmp(rev1, rev2)
if ver1 is None:
ver1 = ''
if ver2 is None:
ver2 = ''
c = cmp(cpy_CPV(fake_cat, fake_pkg, ver1, versioned=bool(ver1)),
cpy_CPV(fake_cat, fake_pkg, ver2, versioned=bool(ver2)))
if c != 0:
return c
return cmp(rev1, rev2)
示例7: sort_func
def sort_func(x, y):
if x.is_dir:
if not y.is_dir:
return -1
return cmp(x, y)
elif y.is_dir:
return +1
elif x.is_reg:
if y.is_reg:
return cmp(files_ordering[x.data], files_ordering[y.data])
return +1
elif y.is_reg:
return -1
return cmp(x, y)
示例8: __cmp__
def __cmp__(self, other):
if not isinstance(other, self.__class__):
raise TypeError("other isn't of %s type, is %s" %
(self.__class__, other.__class__))
c = cmp(self.category, other.category)
if c:
return c
c = cmp(self.package, other.package)
if c:
return c
c = cmp(self.op, other.op)
if c:
return c
c = cpv.ver_cmp(self.version, self.revision,
other.version, other.revision)
if c:
return c
c = cmp(self.blocks, other.blocks)
if c:
# invert it; cmp(True, False) == 1
# want non blockers then blockers.
return -c
c = cmp(self.blocks_strongly, other.blocks_strongly)
if c:
# want !! prior to !
return c
c = cmp(self.negate_vers, other.negate_vers)
if c:
return c
def f(v):
return '' if v is None else v
c = cmp(f(self.slot), f(other.slot))
if c:
return c
c = cmp(self.use, other.use)
if c:
return c
return cmp(self.repo_id, other.repo_id)
示例9: __cmp__
def __cmp__(self, other):
try:
if self.cpvstr == other.cpvstr:
return 0
if (self.category and other.category and self.category != other.category):
return cmp(self.category, other.category)
if self.package and other.package and self.package != other.package:
return cmp(self.package, other.package)
# note I chucked out valueerror, none checks on versions
# passed in. I suck, I know.
# ~harring
# fails in doing comparison of unversioned atoms against
# versioned atoms
return native_ver_cmp(self.version, self.revision, other.version,
other.revision)
except AttributeError:
return 1
示例10: f
def f(x, y):
c = cmp(x, y)
if c:
return c
elif x.repo.livefs:
if y.repo.livefs:
return 0
return -1
elif y.repo.livefs:
return 1
return 0
示例11: test_simple
def test_simple(self):
t = tuple([1, 2, 3])
o = make_DI(tuple, lambda: t)
objs = [o, t]
self.assertEqual(*map(str, objs))
self.assertEqual(*map(repr, objs))
self.assertEqual(*map(hash, objs))
self.assertEqual(*objs)
self.assertTrue(cmp(t, o) == 0)
self.assertFalse(t < o)
self.assertTrue(t <= o)
self.assertTrue(t == o)
self.assertTrue(t >= o)
self.assertFalse(t > o)
self.assertFalse(t != o)
示例12: __eq__
def __eq__(self, other):
if isinstance(other, wrapper):
return cmp(self._raw_pkg, other._raw_pkg) == 0
return cmp(self._raw_pkg, other) == 0
示例13: test_cmp
def test_cmp(self):
ukls, vkls = self.ukls, self.vkls
assert cmp(vkls("dev-util/diffball-0.1"), vkls("dev-util/diffball-0.2")) < 0
base = "dev-util/diffball-0.7.1"
assert not cmp(vkls(base), vkls(base))
for rev in ("", "-r1"):
last = None
for suf in ["_alpha", "_beta", "_pre", "", "_p"]:
if suf == "":
sufs = [suf]
else:
sufs = [suf, suf+"4"]
for x in sufs:
cur = vkls(base+x+rev)
assert cur == vkls(base+x+rev)
if last is not None:
assert cur > last
assert vkls("da/ba-6a") > vkls("da/ba-6")
assert vkls("da/ba-6a-r1") > vkls("da/ba-6a")
assert vkls("da/ba-6.0") > vkls("da/ba-6")
assert vkls("da/ba-6.0.0") > vkls("da/ba-6.0b")
assert vkls("da/ba-6.02") > vkls("da/ba-6.0.0")
# float comparison rules.
assert vkls("da/ba-6.2") > vkls("da/ba-6.054")
assert vkls("da/ba-6") == vkls("da/ba-6")
assert ukls("db/ba") > ukls("da/ba")
assert ukls("da/bb") > ukls("da/ba")
assert vkls("da/ba-6.0_alpha0_p1") > vkls("da/ba-6.0_alpha")
assert vkls("da/ba-6.0_alpha") == vkls("da/ba-6.0_alpha0")
assert vkls("da/ba-6.1") > vkls("da/ba-6.09")
assert vkls("da/ba-6.0.1") > vkls("da/ba-6.0")
assert vkls("da/ba-12.2.5") > vkls("da/ba-12.2b")
# test for gentoo bug 287848
assert vkls("dev-lang/erlang-12.2.5") > vkls("dev-lang/erlang-12.2b")
assert vkls("dev-lang/erlang-12.2.5-r1") > vkls("dev-lang/erlang-12.2b")
assert vkls("da/ba-6.01.0") == vkls("da/ba-6.010.0")
for v1, v2 in (("1.001000000000000000001", "1.001000000000000000002"),
("1.00100000000", "1.0010000000000000001"),
("1.01", "1.1")):
assert vkls(f"da/ba-{v2}") > vkls(f"da/ba-{v1}")
for x in (18, 36, 100):
s = "0" * x
assert vkls(f"da/ba-10{s}1") > vkls(f"da/ba-1{s}1")
for x in (18, 36, 100):
s = "0" * x
assert vkls(f"da/ba-1-r10{s}1") > vkls(f"da/ba-1-r1{s}1")
assert vkls('sys-apps/net-tools-1.60_p2010081516093') > \
vkls('sys-apps/net-tools-1.60_p2009072801401')
assert vkls('sys-apps/net-tools-1.60_p20100815160931') > \
vkls('sys-apps/net-tools-1.60_p20090728014017')
assert vkls('sys-apps/net-tools-1.60_p20100815160931') > \
vkls('sys-apps/net-tools-1.60_p20090728014017-r1')
# Regression test: python does comparison slightly differently
# if the classes do not match exactly (it prefers rich
# comparison over __cmp__).
class DummySubclass(self.kls):
pass
assert DummySubclass("da/ba-6.0_alpha0_p1", versioned=True) != vkls("da/ba-6.0_alpha")
assert DummySubclass("da/ba-6.0_alpha0", versioned=True) == vkls("da/ba-6.0_alpha")
assert DummySubclass("da/ba-6.0", versioned=True) != "foon"
assert DummySubclass("da/ba-6.0", versioned=True) == \
DummySubclass("da/ba-6.0-r0", versioned=True)
示例14: __cmp__
def __cmp__(self, other):
return cmp(self.value, other.value)
示例15: test_cmp
def test_cmp(self):
ukls, vkls = self.ukls, self.vkls
self.assertTrue(cmp(vkls("dev-util/diffball-0.1"), vkls("dev-util/diffball-0.2")) < 0)
base = "dev-util/diffball-0.7.1"
self.assertFalse(cmp(vkls(base), vkls(base)))
for rev in ("", "-r1"):
last = None
for suf in ["_alpha", "_beta", "_pre", "", "_p"]:
if suf == "":
sufs = [suf]
else:
sufs = [suf, suf + "4"]
for x in sufs:
cur = vkls(base + x + rev)
self.assertEqual(cur, vkls(base + x + rev))
if last is not None:
self.assertGT(cur, last)
self.assertGT(vkls("da/ba-6a"), vkls("da/ba-6"))
self.assertGT(vkls("da/ba-6a-r1"), vkls("da/ba-6a"))
self.assertGT(vkls("da/ba-6.0"), vkls("da/ba-6"))
self.assertGT(vkls("da/ba-6.0.0"), vkls("da/ba-6.0b"))
self.assertGT(vkls("da/ba-6.02"), vkls("da/ba-6.0.0"))
# float comparison rules.
self.assertGT(vkls("da/ba-6.2"), vkls("da/ba-6.054"))
self.assertEqual(vkls("da/ba-6"), vkls("da/ba-6"))
self.assertGT(ukls("db/ba"), ukls("da/ba"))
self.assertGT(ukls("da/bb"), ukls("da/ba"))
self.assertGT(vkls("da/ba-6.0_alpha0_p1"), vkls("da/ba-6.0_alpha"))
self.assertEqual(vkls("da/ba-6.0_alpha"), vkls("da/ba-6.0_alpha0"))
self.assertGT(vkls("da/ba-6.1"), vkls("da/ba-6.09"))
self.assertGT(vkls("da/ba-6.0.1"), vkls("da/ba-6.0"))
self.assertGT(vkls("da/ba-12.2.5"), vkls("da/ba-12.2b"))
# test for gentoo bug 287848
self.assertGT(vkls("dev-lang/erlang-12.2.5"), vkls("dev-lang/erlang-12.2b"))
self.assertGT(vkls("dev-lang/erlang-12.2.5-r1"), vkls("dev-lang/erlang-12.2b"))
self.assertEqual(vkls("da/ba-6.01.0"), vkls("da/ba-6.010.0"))
for v1, v2 in (
("1.001000000000000000001", "1.001000000000000000002"),
("1.00100000000", "1.0010000000000000001"),
("1.01", "1.1"),
):
self.assertGT(vkls("da/ba-%s" % v2), vkls("da/ba-%s" % v1))
for x in (18, 36, 100):
s = "0" * x
self.assertGT(vkls("da/ba-10%s1" % s), vkls("da/ba-1%s1" % s))
for x in (18, 36, 100):
s = "0" * x
self.assertGT(vkls("da/ba-1-r10%s1" % s), vkls("da/ba-1-r1%s1" % s))
self.assertGT(vkls("sys-apps/net-tools-1.60_p2010081516093"), vkls("sys-apps/net-tools-1.60_p2009072801401"))
self.assertGT(vkls("sys-apps/net-tools-1.60_p20100815160931"), vkls("sys-apps/net-tools-1.60_p20090728014017"))
self.assertGT(
vkls("sys-apps/net-tools-1.60_p20100815160931"), vkls("sys-apps/net-tools-1.60_p20090728014017-r1")
)
# Regression test: python does comparison slightly differently
# if the classes do not match exactly (it prefers rich
# comparison over __cmp__).
class DummySubclass(self.kls):
pass
self.assertNotEqual(DummySubclass("da/ba-6.0_alpha0_p1", versioned=True), vkls("da/ba-6.0_alpha"))
self.assertEqual(DummySubclass("da/ba-6.0_alpha0", versioned=True), vkls("da/ba-6.0_alpha"))
self.assertNotEqual(DummySubclass("da/ba-6.0", versioned=True), "foon")
self.assertEqual(DummySubclass("da/ba-6.0", versioned=True), DummySubclass("da/ba-6.0-r0", versioned=True))