112882Sspwilson2@wisc.edu# Copyright (c) 2017 Mark D. Hill and David A. Wood
212882Sspwilson2@wisc.edu# All rights reserved.
312882Sspwilson2@wisc.edu#
412882Sspwilson2@wisc.edu# Redistribution and use in source and binary forms, with or without
512882Sspwilson2@wisc.edu# modification, are permitted provided that the following conditions are
612882Sspwilson2@wisc.edu# met: redistributions of source code must retain the above copyright
712882Sspwilson2@wisc.edu# notice, this list of conditions and the following disclaimer;
812882Sspwilson2@wisc.edu# redistributions in binary form must reproduce the above copyright
912882Sspwilson2@wisc.edu# notice, this list of conditions and the following disclaimer in the
1012882Sspwilson2@wisc.edu# documentation and/or other materials provided with the distribution;
1112882Sspwilson2@wisc.edu# neither the name of the copyright holders nor the names of its
1212882Sspwilson2@wisc.edu# contributors may be used to endorse or promote products derived from
1312882Sspwilson2@wisc.edu# this software without specific prior written permission.
1412882Sspwilson2@wisc.edu#
1512882Sspwilson2@wisc.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1612882Sspwilson2@wisc.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1712882Sspwilson2@wisc.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1812882Sspwilson2@wisc.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
1912882Sspwilson2@wisc.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2012882Sspwilson2@wisc.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2112882Sspwilson2@wisc.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2212882Sspwilson2@wisc.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2312882Sspwilson2@wisc.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2412882Sspwilson2@wisc.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2512882Sspwilson2@wisc.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2612882Sspwilson2@wisc.edu#
2712882Sspwilson2@wisc.edu# Authors: Sean Wilson
2812882Sspwilson2@wisc.edu
2912882Sspwilson2@wisc.eduimport terminal
3012882Sspwilson2@wisc.eduimport log
3112882Sspwilson2@wisc.edu
3212882Sspwilson2@wisc.edu# TODO Refactor print logic out of this so the objects
3312882Sspwilson2@wisc.edu# created are separate from print logic.
3412882Sspwilson2@wisc.educlass QueryRunner(object):
3512882Sspwilson2@wisc.edu    def __init__(self, test_schedule):
3612882Sspwilson2@wisc.edu        self.schedule = test_schedule
3712882Sspwilson2@wisc.edu
3812882Sspwilson2@wisc.edu    def tags(self):
3912882Sspwilson2@wisc.edu        tags = set()
4012882Sspwilson2@wisc.edu        for suite in self.schedule:
4112882Sspwilson2@wisc.edu            tags = tags | set(suite.tags)
4212882Sspwilson2@wisc.edu        return tags
4312882Sspwilson2@wisc.edu
4412882Sspwilson2@wisc.edu    def suites(self):
4512882Sspwilson2@wisc.edu        return [suite for suite in self.schedule]
4612882Sspwilson2@wisc.edu
4712882Sspwilson2@wisc.edu    def suites_with_tag(self, tag):
4812882Sspwilson2@wisc.edu        return filter(lambda suite: tag in suite.tags, self.suites())
4912882Sspwilson2@wisc.edu
5012882Sspwilson2@wisc.edu    def list_tests(self):
5112882Sspwilson2@wisc.edu        log.test_log.message(terminal.separator())
5212882Sspwilson2@wisc.edu        log.test_log.message('Listing all Test Cases.', bold=True)
5312882Sspwilson2@wisc.edu        log.test_log.message(terminal.separator())
5412882Sspwilson2@wisc.edu        for suite in self.schedule:
5512882Sspwilson2@wisc.edu            for test in suite:
5612882Sspwilson2@wisc.edu                log.test_log.message(test.uid, machine_readable=True)
5712882Sspwilson2@wisc.edu
5812882Sspwilson2@wisc.edu    def list_suites(self):
5912882Sspwilson2@wisc.edu        log.test_log.message(terminal.separator())
6012882Sspwilson2@wisc.edu        log.test_log.message('Listing all Test Suites.', bold=True)
6112882Sspwilson2@wisc.edu        log.test_log.message(terminal.separator())
6212882Sspwilson2@wisc.edu        for suite in self.suites():
6312882Sspwilson2@wisc.edu            log.test_log.message(suite.uid, machine_readable=True)
6412882Sspwilson2@wisc.edu
6512882Sspwilson2@wisc.edu    def list_tags(self):
6612882Sspwilson2@wisc.edu        log.test_log.message(terminal.separator())
6712882Sspwilson2@wisc.edu        log.test_log.message('Listing all Test Tags.', bold=True)
6812882Sspwilson2@wisc.edu        log.test_log.message(terminal.separator())
6912882Sspwilson2@wisc.edu
7012882Sspwilson2@wisc.edu        for tag in self.tags():
7112882Sspwilson2@wisc.edu            log.test_log.message(tag, machine_readable=True)