aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Piotr Jaroszyński <peper@gentoo.org> 2007-05-21 18:54:14 +0000
committerAvatar Piotr Jaroszyński <peper@gentoo.org> 2007-05-21 18:54:14 +0000
commitd1c634757dfc39799736c7082e3af22e09c1a501 (patch)
tree91113d161cfe353d2987899a38fdc5dede88f0fc
parent5b54c8f5395bd8043221e1aaba09042d3585242e (diff)
downloadpaludis-d1c634757dfc39799736c7082e3af22e09c1a501.tar.gz
paludis-d1c634757dfc39799736c7082e3af22e09c1a501.tar.xz
(python) Bring comparison operartors up to date.
-rwxr-xr-xpython/dep_spec_TEST.py6
-rw-r--r--python/name.cc8
-rwxr-xr-xpython/name_TEST.py6
-rw-r--r--python/package_database.cc4
-rwxr-xr-xpython/paludis_python.hh19
-rwxr-xr-xpython/repository_TEST.py8
-rw-r--r--python/version_operator.cc4
-rw-r--r--python/version_requirements.cc4
-rwxr-xr-xpython/version_requirements_TEST.py6
-rw-r--r--python/version_spec.cc5
-rwxr-xr-xpython/version_spec_TEST.py28
11 files changed, 53 insertions, 45 deletions
diff --git a/python/dep_spec_TEST.py b/python/dep_spec_TEST.py
index 71da156..bb1a6ad 100755
--- a/python/dep_spec_TEST.py
+++ b/python/dep_spec_TEST.py
@@ -60,9 +60,9 @@ class TestCase_1_DepSpecs(unittest.TestCase):
self.get_depspecs()
vrc = self.pds.version_requirements
-# self.assertEquals(len(list(vrc)), 1)
-# self.assertEquals(iter(vrc).next().version_spec, VersionSpec("1"))
-# self.assertEquals(iter(vrc).next().version_operator.value, VersionOperator(">=").value)
+ self.assertEquals(len(list(vrc)), 1)
+ self.assertEquals(iter(vrc).next().version_spec, VersionSpec("1"))
+ self.assertEquals(iter(vrc).next().version_operator.value, VersionOperator(">=").value)
def test_08_version_requirements_mode(self):
self.get_depspecs()
diff --git a/python/name.cc b/python/name.cc
index 4273dc0..fffd144 100644
--- a/python/name.cc
+++ b/python/name.cc
@@ -138,9 +138,7 @@ void PALUDIS_VISIBLE expose_name()
qpn.def(bp::init<const CategoryNamePart &, const PackageNamePart &>());
qpn.def_readwrite("category", &QualifiedPackageName::category);
qpn.def_readwrite("package", &QualifiedPackageName::package);
-#ifdef CIARANM_REMOVED_THIS
- qpn.def("__cmp__", &QualifiedPackageName::compare);
-#endif
+ qpn.def("__cmp__", &__cmp__<QualifiedPackageName>);
qpn.def(bp::self_ns::str(bp::self));
bp::implicitly_convertible<std::string, QualifiedPackageName>();
@@ -156,9 +154,7 @@ void PALUDIS_VISIBLE expose_name()
bp::init<const std::string &, IUseFlagParseMode>("__init__(string, IUseFlagParseMode")
);
iuf.def(bp::init<const UseFlagName &, const UseFlagState &>("__init__(UseFlagName, UseFlagState)"));
-#ifdef CIARANM_REMOVED_THIS
- iuf.def("__cmp__", &IUseFlag::compare);
-#endif
+ iuf.def("__cmp__", &__cmp__<IUseFlag>);
iuf.def(bp::self_ns::str(bp::self));
iuf.def_readwrite("flag", &IUseFlag::flag,
"[rw] UseFlagName"
diff --git a/python/name_TEST.py b/python/name_TEST.py
index ea43e26..e1d9240 100755
--- a/python/name_TEST.py
+++ b/python/name_TEST.py
@@ -58,9 +58,9 @@ class TestCase_Names(unittest.TestCase):
self.assertEqual(str(IUseFlag("foo", UseFlagState.ENABLED)), "+foo")
-# def test_4_operators(self):
-# self.assert_(CategoryNamePart("cat-foo") + PackageNamePart("pkg") == QualifiedPackageName("cat-foo/pkg"))
-# self.assert_(IUseFlag("foo", UseFlagState.ENABLED) == IUseFlag("+foo", IUseFlagParseMode.PERMISSIVE))
+ def test_4_operators(self):
+ self.assert_(CategoryNamePart("cat-foo") + PackageNamePart("pkg") == QualifiedPackageName("cat-foo/pkg"))
+ self.assert_(IUseFlag("foo", UseFlagState.ENABLED) == IUseFlag("+foo", IUseFlagParseMode.PERMISSIVE))
def test_5_data_members(self):
diff --git a/python/package_database.cc b/python/package_database.cc
index 2875547..39fb9da 100644
--- a/python/package_database.cc
+++ b/python/package_database.cc
@@ -95,9 +95,7 @@ void PALUDIS_VISIBLE expose_package_database()
);
pde.def(bp::self_ns::str(bp::self));
pde.def("__eq__", &PackageDatabaseEntry::operator==);
-#ifdef CIARANM_REMOVED_THIS
- pde.def("__ne__", &PackageDatabaseEntry::operator!=);
-#endif
+ pde.def("__ne__", &__ne__<PackageDatabaseEntry>);
class_collection<PackageDatabaseEntryCollection>
pdec("PackageDatabaseEntryCollection",
diff --git a/python/paludis_python.hh b/python/paludis_python.hh
index 7e6133a..0b78f65 100755
--- a/python/paludis_python.hh
+++ b/python/paludis_python.hh
@@ -98,6 +98,25 @@ namespace paludis
}
}
+ // Compare
+ template <typename T_>
+ int __cmp__(T_ & a, T_ & b)
+ {
+ if (a == b)
+ return 0;
+ else if (a < b)
+ return -1;
+ else
+ return 1;
+ }
+
+ // Not equal
+ template <typename T_>
+ bool __ne__(T_ & a, T_ & b)
+ {
+ return ! (a == b);
+ }
+
// Translates Paludis C++ exception to a Python one with output of message() and backtrace() saved
// in the corresponding string attributes of the Python exception.
template <typename Ex_>
diff --git a/python/repository_TEST.py b/python/repository_TEST.py
index aec093c..87be830 100755
--- a/python/repository_TEST.py
+++ b/python/repository_TEST.py
@@ -78,10 +78,10 @@ class TestCase_Repository(unittest.TestCase):
def test_08_version_specs(self):
self.get_foo()
-# self.assertEquals(list(self.repo.version_specs("foo/bar")),
-# [VersionSpec("1.0"), VersionSpec("2.0")]
-# )
-# self.assertEquals(len(list(self.repo.version_specs("bar/baz"))), 0)
+ self.assertEquals(list(self.repo.version_specs("foo/bar")),
+ [VersionSpec("1.0"), VersionSpec("2.0")]
+ )
+ self.assertEquals(len(list(self.repo.version_specs("bar/baz"))), 0)
def test_09_category_names(self):
self.get_foo()
diff --git a/python/version_operator.cc b/python/version_operator.cc
index 516a6a9..ac25a73 100644
--- a/python/version_operator.cc
+++ b/python/version_operator.cc
@@ -27,7 +27,7 @@ using namespace paludis::python;
namespace bp = boost::python;
bool
-compare(const VersionOperator & self, const VersionSpec & v1, const VersionSpec & v2)
+vo_compare(const VersionOperator & self, const VersionSpec & v1, const VersionSpec & v2)
{
return self.as_version_spec_comparator()(v1, v2);
}
@@ -48,7 +48,7 @@ void PALUDIS_VISIBLE expose_version_operator()
vo.add_property("value", &VersionOperator::value,
"[ro] VersionOperatorValue"
);
- vo.def("compare", &compare,
+ vo.def("compare", &vo_compare,
"compare(VersionSpec, VersionSpec) -> bool\n"
"Compare two VersionSpecs with this operator."
);
diff --git a/python/version_requirements.cc b/python/version_requirements.cc
index 57b3de8..161befa 100644
--- a/python/version_requirements.cc
+++ b/python/version_requirements.cc
@@ -40,9 +40,7 @@ void PALUDIS_VISIBLE expose_version_requirements()
"[rw] VersionSpec"
);
vr.def("__eq__", &VersionRequirement::operator==);
-#ifdef CIARANM_REMOVED_THIS
- vr.def("__neq__", &VersionRequirement::operator!=);
-#endif
+ vr.def("__ne__", &__ne__<VersionRequirement>);
enum_auto("VersionRequirementsMode", last_vr);
diff --git a/python/version_requirements_TEST.py b/python/version_requirements_TEST.py
index 542d8e9..0129095 100755
--- a/python/version_requirements_TEST.py
+++ b/python/version_requirements_TEST.py
@@ -38,9 +38,9 @@ class TestCase_VersionRequirements(unittest.TestCase):
v1 = VersionRequirement("<", "0")
v2 = VersionRequirement("<", "0")
-# self.assert_(v1 == v2)
-# v1.version_operator = ">"
-# self.assert_(v1 != v2)
+ self.assert_(v1 == v2)
+ v1.version_operator = ">"
+ self.assert_(v1 != v2)
if __name__ == "__main__":
unittest.main()
diff --git a/python/version_spec.cc b/python/version_spec.cc
index cd8700c..9cc943f 100644
--- a/python/version_spec.cc
+++ b/python/version_spec.cc
@@ -53,10 +53,7 @@ void PALUDIS_VISIBLE expose_version_spec()
"revision_only() -> string\n"
"Revision part only (or \"r0\")."
);
-#ifdef CIARANM_REMOVED_THIS
- int (*compare_ptr)(const VersionSpec &, const VersionSpec &) = &compare;
- vs.def("__cmp__", compare_ptr);
-#endif
+ vs.def("__cmp__", &VersionSpec::compare);
vs.def(bp::self_ns::str(bp::self));
bp::implicitly_convertible<std::string, VersionSpec>();
diff --git a/python/version_spec_TEST.py b/python/version_spec_TEST.py
index 8473f99..58c925c 100755
--- a/python/version_spec_TEST.py
+++ b/python/version_spec_TEST.py
@@ -34,30 +34,30 @@ class TestCase_VersionSpec(unittest.TestCase):
v2 = VersionSpec("1.0_beta3")
v3 = VersionSpec("1.0")
-# self.assert_(v0 < v1);
-# self.assert_(v1 < v2);
-# self.assert_(v2 < v3);
+ self.assert_(v0 < v1);
+ self.assert_(v1 < v2);
+ self.assert_(v2 < v3);
-# self.assert_(v0 >= v0);
-# self.assert_(v1 >= v1);
-# self.assert_(v3 >= v2);
+ self.assert_(v0 >= v0);
+ self.assert_(v1 >= v1);
+ self.assert_(v3 >= v2);
def test_04_str(self):
self.assertEqual("0.1_beta2-r3", str(VersionSpec("0.1_beta2-r3")))
self.assertEqual("1", str(VersionSpec("0.1_beta2-r3").bump()))
-# def test_05_remove_revision(self):
-# self.assertEqual(VersionSpec("0.1"), VersionSpec("0.1-r1").remove_revision())
+ def test_05_remove_revision(self):
+ self.assertEqual(VersionSpec("0.1"), VersionSpec("0.1-r1").remove_revision())
def test_06_revision_only(self):
self.assertEqual("r3", VersionSpec("0.1r_alpha1-r3").revision_only())
-# def test_07_bump(self):
-# self.assertEqual(VersionSpec("2"), VersionSpec("1").bump())
-# self.assertEqual(VersionSpec("2"), VersionSpec("1.2").bump())
-# self.assertEqual(VersionSpec("1.3"), VersionSpec("1.2.3").bump())
-# self.assertEqual(VersionSpec("1.3"), VersionSpec("1.2.3_beta1-r4").bump())
-# self.assertEqual(VersionSpec("scm"), VersionSpec("scm").bump())
+ def test_07_bump(self):
+ self.assertEqual(VersionSpec("2"), VersionSpec("1").bump())
+ self.assertEqual(VersionSpec("2"), VersionSpec("1.2").bump())
+ self.assertEqual(VersionSpec("1.3"), VersionSpec("1.2.3").bump())
+ self.assertEqual(VersionSpec("1.3"), VersionSpec("1.2.3_beta1-r4").bump())
+ self.assertEqual(VersionSpec("scm"), VersionSpec("scm").bump())
def test_08_is_scm(self):
self.assert_(VersionSpec("scm").is_scm)