Gentoo Archives: gentoo-commits

From: Virgil Dupras <vdupras@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/gentoolkit:master commit in: pym/gentoolkit/test/, pym/gentoolkit/
Date: Mon, 17 Sep 2018 23:32:17
Message-Id: 1537227087.ce821ea62cd40b0110fc128f92e140da4e7482cf.vdupras@gentoo
1 commit: ce821ea62cd40b0110fc128f92e140da4e7482cf
2 Author: Virgil Dupras <vdupras <AT> gentoo <DOT> org>
3 AuthorDate: Mon Sep 17 23:31:27 2018 +0000
4 Commit: Virgil Dupras <vdupras <AT> gentoo <DOT> org>
5 CommitDate: Mon Sep 17 23:31:27 2018 +0000
6 URL: https://gitweb.gentoo.org/proj/gentoolkit.git/commit/?id=ce821ea6
7
8 Atom.intersects: simplify name-only matching logic
9
10 Remove old "optimization". Slicing two strings can't possibly be faster
11 than checking if `.category` is `None`: the call to `.cp` earlier
12 ensures that we've already populated that property.
13
14 Also, add tests for it.
15
16 pym/gentoolkit/atom.py | 12 +++---------
17 pym/gentoolkit/test/test_atom.py | 11 +++++++++--
18 2 files changed, 12 insertions(+), 11 deletions(-)
19
20 diff --git a/pym/gentoolkit/atom.py b/pym/gentoolkit/atom.py
21 index b5b755c..b86c89c 100644
22 --- a/pym/gentoolkit/atom.py
23 +++ b/pym/gentoolkit/atom.py
24 @@ -209,15 +209,9 @@ class Atom(portage.dep.Atom, CPV):
25 # Our "cp" (cat/pkg) must match exactly:
26 if self.cp != other.cp:
27 # Check to see if one is name only:
28 - # Avoid slow partitioning if we're definitely not matching
29 - # (yes, this is hackish, but it's faster):
30 - if self.cp[-1:] != other.cp[-1:]:
31 - return False
32 -
33 - if ((not self.category and self.name == other.name) or
34 - (not other.category and other.name == self.name)):
35 - return True
36 - return False
37 + # We don't bother checking if self.category is None: it can't be
38 + # because we're an Atom subclass and that would be invalid.
39 + return (not other.category and self.name == other.name)
40
41 # Slot dep only matters if we both have one. If we do they
42 # must be identical:
43
44 diff --git a/pym/gentoolkit/test/test_atom.py b/pym/gentoolkit/test/test_atom.py
45 index 399905e..6177222 100644
46 --- a/pym/gentoolkit/test/test_atom.py
47 +++ b/pym/gentoolkit/test/test_atom.py
48 @@ -8,6 +8,7 @@
49 import unittest
50
51 from gentoolkit.atom import Atom
52 +from gentoolkit.cpv import CPV
53 from gentoolkit.test import cmp
54
55 """Atom test suite (verbatim) from pkgcore."""
56 @@ -140,10 +141,16 @@ class TestGentoolkitAtom(unittest.TestCase):
57 result, that_atom.intersects(this_atom),
58 '%s intersecting %s should be %s' % (that, this, result))
59
60 + def test_intersects_nameonly(self):
61 + atom = Atom('cat/pkg')
62 + self.assertTrue(atom.intersects(CPV('pkg')))
63 + self.assertFalse(atom.intersects(CPV('other')))
64 + self.assertFalse(atom.intersects(CPV('dkg')))
65 +
66
67 def test_main():
68 - suite = unittest.TestLoader().loadTestsFromTestCase(TestGentoolkitAtom)
69 - unittest.TextTestRunner(verbosity=2).run(suite)
70 + suite = unittest.TestLoader().loadTestsFromTestCase(TestGentoolkitAtom)
71 + unittest.TextTestRunner(verbosity=2).run(suite)
72 test_main.__test__ = False