Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Popcon tests #55

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 43 additions & 25 deletions pet/classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,35 +175,53 @@ def __init__(self, session, named_trees,
nt, bugs.get(nt.source, []), suite_packages.get(nt.source, []),
tags.get(nt.package_id, [])))

@classmethod
def order_packages_by_popcon(cls, packages):
has_no_popcon = []
packages_queue = PriorityQueue()
for package in packages:
package_popcon = popcon.package(package.name)

# The package has popcon
if package_popcon:
packages_queue.put((-package_popcon[package.name], package))
else:
has_no_popcon.append(package)

ordered_packages = []
while packages_queue.empty() is False:
_, package = packages_queue.get()
ordered_packages.append(package)

for package in has_no_popcon:
ordered_packages.append(package)

return ordered_packages

def classify(self):
self.packages = Classifier.order_packages_by_popcon(self.packages)
classified = dict()
ordered_packages = PriorityQueue()
for p in self.packages:
if p.ready_for_upload:
cls = 'ready_for_upload'
elif p.has_rc_bugs:
cls = 'rc_bugs'
elif p.missing_tag:
cls = 'missing_tag'
elif not p.tags:
cls = 'new'
elif p.newer_upstream:
cls = 'new_upstream'
elif p.watch_problem:
cls = 'watch_problem'
elif p.bugs:
cls = 'bugs'
elif not p.is_tagged:
cls = 'wip'
for package in self.packages:
if package.ready_for_upload:
classification = 'ready_for_upload'
elif package.has_rc_bugs:
classification = 'rc_bugs'
elif package.missing_tag:
classification = 'missing_tag'
elif not package.tags:
classification = 'new'
elif package.newer_upstream:
classification = 'new_upstream'
elif package.watch_problem:
classification = 'watch_problem'
elif package.bugs:
classification = 'bugs'
elif not package.is_tagged:
classification = 'wip'
else:
cls = 'other'
classification = 'other'

package_popcon = popcon.package(p.name)
if package_popcon:
ordered_packages.put((-package_popcon[p.name], cls, p))
while ordered_packages.empty() is False:
_, cls, package = ordered_packages.get()
classified.setdefault(cls, []).append(package)
classified.setdefault(classification, []).append(package)

return classified

Expand Down
26 changes: 24 additions & 2 deletions test/test_classifier.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,33 @@
import unittest
import pet.classifier
from pet.classifier import Classifier
import random
import popcon


class FakePackage():
def __init__(self):
self.name = ''


class TestPetClassifier(unittest.TestCase):

def setUp(self):
pass

def test_something(self):
pass
def test_classify_popcon(self):

package_libdigest_md4_perl = FakePackage()
package_libdigest_md4_perl.name = 'libdigest-md4-perl'
package_libsharyanto_utils_perl = FakePackage()
package_libsharyanto_utils_perl.name = 'libsharyanto-utils-perl'

packages = [package_libdigest_md4_perl, package_libsharyanto_utils_perl]
random.shuffle(packages)
ordered_packages = Classifier.order_packages_by_popcon(packages)

for i in range(0, len(packages) - 1):
package1 = popcon.package(ordered_packages[i].name)
package2 = popcon.package(ordered_packages[i + 1].name)
self.assertGreaterEqual(package1[ordered_packages[i].name],
package2[ordered_packages[i + 1].name])