Changeset 70006 in webkit


Ignore:
Timestamp:
Oct 18, 2010 4:08:33 PM (14 years ago)
Author:
eric@webkit.org
Message:

2010-10-18 Eric Seidel <eric@webkit.org>

Reviewed by Adam Barth.

Add Queue class and add minimal unittesting of QueueStatusServer code
https://bugs.webkit.org/show_bug.cgi?id=47847

  • QueueStatusServer/handlers/dashboard.py:
  • QueueStatusServer/handlers/queuestatus.py:
  • QueueStatusServer/handlers/recentstatus.py:
  • QueueStatusServer/handlers/statusbubble.py:
  • QueueStatusServer/handlers/updateworkitems.py:
  • QueueStatusServer/model/attachment.py:
  • QueueStatusServer/model/queues.py:
  • QueueStatusServer/model/queues_unittest.py: Added.
  • QueueStatusServer/model/svnrevision.py:
  • Scripts/test-webkitpy:
  • Scripts/webkitpy/test/main.py:
Location:
trunk/WebKitTools
Files:
1 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebKitTools/ChangeLog

    r69986 r70006  
     12010-10-18  Eric Seidel  <eric@webkit.org>
     2
     3        Reviewed by Adam Barth.
     4
     5        Add Queue class and add minimal unittesting of QueueStatusServer code
     6        https://bugs.webkit.org/show_bug.cgi?id=47847
     7
     8        * QueueStatusServer/handlers/dashboard.py:
     9        * QueueStatusServer/handlers/queuestatus.py:
     10        * QueueStatusServer/handlers/recentstatus.py:
     11        * QueueStatusServer/handlers/statusbubble.py:
     12        * QueueStatusServer/handlers/updateworkitems.py:
     13        * QueueStatusServer/model/attachment.py:
     14        * QueueStatusServer/model/queues.py:
     15        * QueueStatusServer/model/queues_unittest.py: Added.
     16        * QueueStatusServer/model/svnrevision.py:
     17        * Scripts/test-webkitpy:
     18        * Scripts/webkitpy/test/main.py:
     19
    1202010-10-18  Anders Carlsson  <andersca@apple.com>
    221
  • trunk/WebKitTools/QueueStatusServer/handlers/dashboard.py

    r66518 r70006  
    3333
    3434from model.attachment import Attachment
    35 from model.queues import queues
     35from model.queues import Queue
    3636
    3737
    3838class Dashboard(webapp.RequestHandler):
     39    # We may want to sort these?
     40    _ordered_queues = Queue.all()
     41    _header_names = [queue.short_name() for queue in _ordered_queues]
    3942
    40     # FIXME: This list probably belongs as part of a Queue object in queues.py
    41     # Arrays are bubble_name, queue_name
    42     # FIXME: Can this be unified with StatusBubble._queues_to_display?
    43     _queues_to_display = [
    44         ["Style", "style-queue"],
    45         ["Cr-Linux", "chromium-ews"],
    46         ["Qt", "qt-ews"],
    47         ["Gtk", "gtk-ews"],
    48         ["Mac", "mac-ews"],
    49         ["Win", "win-ews"],
    50         ["Commit", "commit-queue"],
    51     ]
    52     # Split the zipped list into component parts
    53     _header_names, _ordered_queue_names = zip(*_queues_to_display)
    54 
    55     # This asserts that all of the queues listed above are valid queue names.
    56     assert(reduce(operator.and_, map(lambda name: name in queues, _ordered_queue_names)))
    57 
    58     def _build_bubble(self, attachment, queue_name):
    59         queue_status = attachment.status_for_queue(queue_name)
     43    def _build_bubble(self, attachment, queue):
     44        queue_status = attachment.status_for_queue(queue.name())
    6045        bubble = {
    6146            "status_class": attachment.state_from_queue_status(queue_status) if queue_status else "none",
     
    6853            "bug_id": attachment.bug_id(),
    6954            "attachment_id": attachment.id,
    70             "bubbles": [self._build_bubble(attachment, queue_name) for queue_name in self._ordered_queue_names],
     55            "bubbles": [self._build_bubble(attachment, queue) for queue in self._ordered_queues],
    7156        }
    7257        return row
  • trunk/WebKitTools/QueueStatusServer/handlers/queuestatus.py

    r68453 r70006  
    3030from google.appengine.ext.webapp import template
    3131
    32 from model.queues import queues, display_name_for_queue
     32from model.queues import Queue
    3333from model.workitems import WorkItems
    3434from model.activeworkitems import ActiveWorkItems
     
    5151
    5252    def get(self, queue_name):
    53         queued_items = WorkItems.all().filter("queue_name =", queue_name).get()
    54         active_items = ActiveWorkItems.all().filter("queue_name =", queue_name).get()
    55         statuses = queuestatus.QueueStatus.all().filter("queue_name =", queue_name).order("-date").fetch(15)
     53        queue_name = queue_name.lowercase()
     54        queue = Queue.queue_with_name(queue_name)
     55        if not queue:
     56            self.error(404)
     57
     58        queued_items = WorkItems.all().filter("queue_name =", queue.name()).get()
     59        active_items = ActiveWorkItems.all().filter("queue_name =", queue.name()).get()
     60        statuses = queuestatus.QueueStatus.all().filter("queue_name =", queue.name()).order("-date").fetch(15)
    5661
    5762        status_groups = []
     
    7075
    7176        template_values = {
    72             "display_queue_name": display_name_for_queue(queue_name),
     77            "display_queue_name": queue.display_name(),
    7378            "work_item_rows": self._rows_for_work_items(queued_items, active_items),
    7479            "status_groups": status_groups,
  • trunk/WebKitTools/QueueStatusServer/handlers/recentstatus.py

    r64787 r70006  
    3232from google.appengine.ext.webapp import template
    3333
    34 from model.queues import queues, display_name_for_queue
     34from model.queues import Queue
    3535from model.queuestatus import QueueStatus
    3636from model.workitems import WorkItems
     
    3939class QueueBubble(object):
    4040    """View support class for recentstatus.html"""
    41     def __init__(self, queue_name):
    42         self._queue_name = queue_name
    43         self._work_items = WorkItems.all().filter("queue_name =", queue_name).get()
    44         self._last_status = QueueStatus.all().filter("queue_name =", queue_name).order("-date").get()
     41    def __init__(self, queue):
     42        self._queue = queue
     43        self._work_items = WorkItems.all().filter("queue_name =", queue.name()).get()
     44        self._last_status = QueueStatus.all().filter("queue_name =", queue.name()).order("-date").get()
    4545
     46    # FIXME: name and display_name should be replaced by a .queue() accessor.
    4647    def name(self):
    47         return self._queue_name
     48        return self._queue.name()
    4849
    4950    def display_name(self):
    50         return display_name_for_queue(self._queue_name)
     51        return self._queue.display_name()
    5152
    5253    def _last_status_date(self):
     
    8990    def get(self):
    9091        template_values = {
    91             "queues": [QueueBubble(queue_name) for queue_name in queues],
     92            "queues": [QueueBubble(queue) for queue in Queue.all()],
    9293        }
    9394        self.response.out.write(template.render("templates/recentstatus.html", template_values))
  • trunk/WebKitTools/QueueStatusServer/handlers/statusbubble.py

    r69471 r70006  
    3434from model.attachment import Attachment
    3535from model.workitems import WorkItems
    36 from model.queues import queues, name_with_underscores
     36from model.queues import Queue
    3737
    3838
    3939class StatusBubble(webapp.RequestHandler):
    40     # FIXME: This list probably belongs as part of a Queue object in queues.py
    41     # Arrays are bubble_name, queue_name
    42     _queues_to_display = [
    43         ["style", "style-queue"],
    44         ["cr-linux", "chromium-ews"],
    45         ["gtk", "gtk-ews"],
    46         ["qt", "qt-ews"],
    47         ["mac", "mac-ews"],
    48         ["win", "win-ews"],
    49         ["efl", "efl-ews"],
    50     ]
     40    _queues_to_display = [queue for queue in Queue.all() if queue.is_ews()]
    5141
    52     # This asserts that all of the queues listed above are valid queue names.
    53     assert(reduce(operator.and_, map(lambda name_pair: name_pair[1] in queues, _queues_to_display)))
    54 
    55     def _build_bubble(self, queue_name_pair, attachment):
    56         bubble_name = queue_name_pair[0]
    57         queue_name = queue_name_pair[1]
    58 
    59         queue_status = attachment.status_for_queue(queue_name)
     42    def _build_bubble(self, queue, attachment):
     43        queue_status = attachment.status_for_queue(queue.name())
    6044        bubble = {
    61             "name": bubble_name,
     45            "name": queue.short_name().lowercase(),
    6246            "attachment_id": attachment.id,
    63             "queue_position": attachment.position_in_queue(queue_name),
     47            "queue_position": attachment.position_in_queue(queue.name()),
    6448            "state": attachment.state_from_queue_status(queue_status) if queue_status else "none",
    6549            "status": queue_status,
     
    6953    def get(self, attachment_id):
    7054        attachment = Attachment(int(attachment_id))
    71         bubbles = [self._build_bubble(name_pair, attachment) for name_pair in self._queues_to_display]
     55        bubbles = [self._build_bubble(queue, attachment) for queue in self._queues_to_display]
    7256        template_values = {
    7357            "bubbles": bubbles,
  • trunk/WebKitTools/QueueStatusServer/handlers/updateworkitems.py

    r59986 r70006  
    3131
    3232from handlers.updatebase import UpdateBase
    33 from model.queues import queues
     33from model.queues import Queue
    3434from model.workitems import WorkItems
    3535
     
    4242
    4343    def _work_items_for_queue(self, queue_name):
    44         if queue_name not in queues:
    45             self.response.out.write("\"%s\" is not in queues %s" % (queue_name, queues))
     44        queue = Queue.queue_for_name(queue_name)
     45        if queue:
     46            self.response.out.write("\"%s\" is not in queues %s" % (queue_name, Queue.all()))
    4647            return None
    4748        work_items = WorkItems.all().filter("queue_name =", queue_name).get()
  • trunk/WebKitTools/QueueStatusServer/model/attachment.py

    r59534 r70006  
    3131from google.appengine.api import memcache
    3232
    33 from model.queues import queues, name_with_underscores
     33from model.queues import Queue
    3434from model.queuestatus import QueueStatus
    3535from model.workitems import WorkItems
     
    9292
    9393    def status_for_queue(self, queue_name):
    94         underscore_queue_name = name_with_underscores(queue_name)
     94        underscore_queue_name = Queue(queue_name).name_with_underscores()
    9595        # summary() is a horrible API and should be killed.
    9696        queue_summary = self.summary().get(underscore_queue_name)
     
    135135            status = QueueStatus.all().filter('queue_name =', queue).filter('active_patch_id =', self.id).order('-date').get()
    136136            if status:
    137                 summary[name_with_underscores(queue)] = {
     137                queue_name = Queue(queue_name).name_with_underscores()
     138                # summary() is a horrible API and should be killed.
     139                summary[queue_name] = {
    138140                    "state": self.state_from_queue_status(status),
    139141                    "status": status,
  • trunk/WebKitTools/QueueStatusServer/model/queues.py

    r66564 r70006  
    2727# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2828
     29
    2930import re
    3031
    3132
    32 queues = [
    33     "commit-queue",
    34     "style-queue",
    35     "chromium-ews",
    36     "qt-ews",
    37     "gtk-ews",
    38     "mac-ews",
    39     "win-ews",
    40     "efl-ews",
    41 ]
     33class Queue(object):
    4234
     35    # Eventually the list of queues may be stored in the data store.
     36    _all_queue_names = [
     37        "commit-queue",
     38        "style-queue",
     39        "chromium-ews",
     40        "qt-ews",
     41        "gtk-ews",
     42        "mac-ews",
     43        "win-ews",
     44        "efl-ews",
     45    ]
    4346
    44 # FIXME: We need some sort of Queue object.
    45 def _title_case(string):
    46     words = string.split(" ")
    47     words = map(lambda word: word.capitalize(), words)
    48     return " ".join(words)
     47    def __init__(self, name):
     48        assert(name in self._all_queue_names)
     49        self._name = name
    4950
     51    @classmethod
     52    def queue_with_name(cls, queue_name):
     53        if queue_name not in cls._all_queue_names:
     54            return None
     55        return Queue(queue_name)
    5056
    51 def display_name_for_queue(queue_name):
    52     # HACK: chromium-ews is incorrectly named.
    53     display_name = queue_name.replace("chromium-ews", "cr-linux-ews")
     57    @classmethod
     58    def all(cls):
     59        return [Queue(name) for name in cls._all_queue_names]
    5460
    55     display_name = display_name.replace("-", " ")
    56     display_name = display_name.replace("cr", "chromium")
    57     display_name = _title_case(display_name)
    58     display_name = display_name.replace("Ews", "EWS")
    59     return display_name
     61    def name(self):
     62        return self._name
    6063
     64    def _caplitalize_after_dash(self, string):
     65        return "-".join([word[0].upper() + word[1:] for word in string.split("-")])
    6166
    62 def name_with_underscores(dashed_name):
    63     regexp = re.compile("-")
    64     return regexp.sub("_", dashed_name)
     67    # For use in status bubbles or table headers
     68    def short_name(self):
     69        # HACK: chromium-ews is incorrectly named.
     70        short_name = self._name.replace("chromium-ews", "Cr-Linux-ews")
     71        short_name = short_name.replace("-ews", "")
     72        short_name = short_name.replace("-queue", "")
     73        return self._caplitalize_after_dash(short_name.capitalize())
     74
     75    def display_name(self):
     76        # HACK: chromium-ews is incorrectly named.
     77        display_name = self._name.replace("chromium-ews", "cr-linux-ews")
     78
     79        display_name = display_name.replace("-", " ")
     80        display_name = display_name.replace("cr", "chromium")
     81        display_name = display_name.title()
     82        display_name = display_name.replace("Ews", "EWS")
     83        return display_name
     84
     85    _dash_regexp = re.compile("-")
     86
     87    def name_with_underscores(self):
     88        return self._dash_regexp.sub("_", self._name)
     89
     90    def is_ews(self):
     91        return self._name.endswith("-ews")
  • trunk/WebKitTools/QueueStatusServer/model/svnrevision.py

    r56210 r70006  
    2929from google.appengine.ext import db
    3030
     31
    3132class SVNRevision(db.Model):
    3233    number = db.IntegerProperty()
  • trunk/WebKitTools/Scripts/test-webkitpy

    r68080 r70006  
    228228
    229229
     230def _path_from_webkit_root(*components):
     231    webkit_root = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
     232    return os.path.join(webkit_root, *components)
     233
     234
     235def _test_import(module_path):
     236    try:
     237        sys.path.append(os.path.dirname(module_path))
     238        module_name = os.path.basename(module_path)
     239        __import__(module_name)
     240        return True
     241    except Exception, e:
     242        message = "Skipping tests in %s due to failure (%s)." % (module_path, e)
     243        if module_name.endswith("QueueStatusServer"):
     244            message += "  This module is optional.  The failure is likely due to a missing Google AppEngine install.  (http://code.google.com/appengine/downloads.html)"
     245        _log.warn(message)
     246        return False
     247
    230248if __name__ == "__main__":
    231 
    232     external_package_paths = [os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), 'WebKit2', 'Scripts', 'webkit2')]
     249    # FIXME: We should probably test each package separately to avoid naming conflicts.
     250    external_package_paths = [
     251        _path_from_webkit_root('WebKit2', 'Scripts', 'webkit2'),
     252        _path_from_webkit_root('WebKitTools', 'QueueStatusServer'),
     253    ]
    233254    init(sys.argv[1:], external_package_paths)
    234255
     
    241262    from webkitpy.test.main import Tester
    242263
     264    external_package_paths = filter(_test_import, external_package_paths)
     265
    243266    Tester().run_tests(sys.argv, external_package_paths)
  • trunk/WebKitTools/Scripts/webkitpy/test/main.py

    r68084 r70006  
    5151        return unittest_paths
    5252
    53     def _modules_from_paths(self, webkitpy_dir, paths):
     53    def _modules_from_paths(self, package_root, paths):
    5454        """Return a list of fully-qualified module names given paths."""
    55         webkitpy_dir = os.path.abspath(webkitpy_dir)
    56         webkitpy_name = os.path.split(webkitpy_dir)[1]  # Equals "webkitpy".
     55        package_path = os.path.abspath(package_root)
     56        root_package_name = os.path.split(package_path)[1]  # Equals "webkitpy".
    5757
    58         prefix_length = len(webkitpy_dir)
     58        prefix_length = len(package_path)
    5959
    6060        modules = []
     
    7373                parts.insert(0, tail)
    7474            # We now have, for example: common.config.ports_unittest
    75             parts.insert(0, webkitpy_name)  # Put "webkitpy" at the beginning.
     75            # FIXME: This is all a hack around the fact that we always prefix webkitpy includes with "webkitpy."
     76            parts.insert(0, root_package_name)  # Put "webkitpy" at the beginning.
    7677            module = ".".join(parts)
    7778            modules.append(module)
     
    9293            external_package_paths = []
    9394        else:
     95            # FIXME: We should consider moving webkitpy off of using "webkitpy." to prefix
     96            # all includes.  If we did that, then this would use path instead of dirname(path).
     97            # QueueStatusServer.__init__ has a sys.path import hack due to this code.
    9498            sys.path.extend(set(os.path.dirname(path) for path in external_package_paths))
    9599
     
    102106        # Otherwise, auto-detect all unit tests.
    103107
     108        # FIXME: This should be combined with the external_package_paths code above.
    104109        webkitpy_dir = os.path.dirname(webkitpy.__file__)
    105110
Note: See TracChangeset for help on using the changeset viewer.