Skip to content

Commit

Permalink
Unit test scaffolding for CueJobMonitorTree and Redirect. (#680)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcipriano committed Apr 30, 2020
1 parent b45cf72 commit 03c08a8
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cuegui/cuegui/CueJobMonitorTree.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ def dropEvent(self, event):

self.updateRequest()

def addShow(self, show, update = True):
def addShow(self, show, update=True):
"""Adds a show to the list of monitored shows
@type show: Show name
@param show: string
Expand Down
16 changes: 8 additions & 8 deletions cuegui/cuegui/Redirect.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def __init__(self, selected="pipe", parent=None):
def refresh(self):
self.clear()
shows = opencue.api.getActiveShows()
shows.sort(lambda x,y: cmp(x.data.name, y.data.name))
shows.sort(key=lambda x, y: cmp(x.data.name, y.data.name))

for show in shows:
self.addItem(show.data.name, show)
Expand Down Expand Up @@ -92,7 +92,7 @@ def refresh(self):
Refresh the full list of allocations.
"""
allocs = opencue.api.getAllocations()
allocs.sort(lambda x,y: cmp(x.data.name, y.data.name))
allocs.sort(key=lambda x, y: cmp(x.data.name, y.data.name))

self.__menu.clear()
checked = 0
Expand Down Expand Up @@ -372,11 +372,11 @@ class RedirectWidget(QtWidgets.QWidget):
Displays a table of procs that can be selected for redirect.
"""

HEADERS = ["Name","Cores","Memory","PrcTime", "Group","Service"]
HEADERS = ["Name", "Cores", "Memory", "PrcTime", "Group", "Service"]

def __init__(self, parent=None):
QtWidgets.QWidget.__init__(self, parent)
self.__hosts = { }
self.__hosts = {}

self.__controls = RedirectControls(self)

Expand All @@ -398,17 +398,17 @@ def __init__(self, parent=None):
self.__controls.getClearButton().pressed.connect(self.clearTarget)

def __get_selected_procs_by_alloc(self, selected_items):
'''
"""
Gathers and returns the selected procs, grouped by allocation their
allocation names
@param selected_items: The selected rows to analyze
@type selected_itmes: list<dict<str:varies>>
@type selected_items: list<dict<str:varies>>
@return: A dictionary with the allocation neames are the keys and the
@return: A dictionary with the allocation names are the keys and the
selected procs are the values.
@rtype: dict<str:L{opencue.wrappers.proc.Proc}>
'''
"""

procs_by_alloc = {}
for item in selected_items:
Expand Down
65 changes: 65 additions & 0 deletions cuegui/tests/CueJobMonitorTree_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Copyright (c) OpenCue Project Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


import mock
import unittest

import PySide2.QtCore
import PySide2.QtGui
import PySide2.QtWidgets

import cuegui.CueJobMonitorTree
import cuegui.plugins.MonitorCuePlugin
import cuegui.Style
import opencue.compiled_proto.job_pb2
import opencue.compiled_proto.show_pb2
import opencue.wrappers.show

from . import test_utils


@mock.patch('opencue.cuebot.Cuebot.getStub', new=mock.Mock())
class CueJobMonitorTreeTests(unittest.TestCase):

@mock.patch('opencue.cuebot.Cuebot.getStub')
def setUp(self, get_stub_mock):
test_utils.createApplication()
PySide2.QtGui.qApp.settings = PySide2.QtCore.QSettings()
cuegui.Style.init()

self.show_name = 'arbitrary-show-name'
self.jobs = ['arbitrary-job-name']

# Show is specified by name, and show details are fetched using FindShow.
get_stub_mock.return_value.FindShow.return_value = \
opencue.compiled_proto.show_pb2.ShowFindShowResponse(
show=opencue.compiled_proto.show_pb2.Show(name=self.show_name))

# The widget loads the show's "whiteboard", a nested data structure containing
# all groups and jobs in the show. The top-level item is the show though it
# uses the NestedGroup data type.
get_stub_mock.return_value.GetJobWhiteboard.return_value = \
opencue.compiled_proto.show_pb2.ShowGetJobWhiteboardResponse(
whiteboard=opencue.compiled_proto.job_pb2.NestedGroup(
name=self.show_name,
jobs=self.jobs))

self.main_window = PySide2.QtWidgets.QMainWindow()
self.widget = cuegui.plugins.MonitorCuePlugin.MonitorCueDockWidget(self.main_window)
self.cue_job_monitor_tree = cuegui.CueJobMonitorTree.CueJobMonitorTree(self.widget)
self.cue_job_monitor_tree.addShow(self.show_name)

def test_setup(self):
pass
49 changes: 49 additions & 0 deletions cuegui/tests/Redirect_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Copyright (c) OpenCue Project Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


import mock
import unittest

import PySide2.QtCore
import PySide2.QtGui

import cuegui.Redirect
import cuegui.Style
import opencue.compiled_proto.show_pb2
import opencue.wrappers.show

from . import test_utils


@mock.patch('opencue.cuebot.Cuebot.getStub', new=mock.Mock())
class RedirectTests(unittest.TestCase):

@mock.patch('opencue.cuebot.Cuebot.getStub')
def setUp(self, getStubMock):
test_utils.createApplication()
PySide2.QtGui.qApp.settings = PySide2.QtCore.QSettings()
cuegui.Style.init()

getStubMock.return_value.GetActiveShows.return_value = \
opencue.compiled_proto.show_pb2.ShowGetActiveShowsResponse(
shows=opencue.compiled_proto.show_pb2.ShowSeq(shows=[]))
getStubMock.return_value.FindShow.return_value = \
opencue.compiled_proto.show_pb2.ShowFindShowResponse(
show=opencue.compiled_proto.show_pb2.Show())

self.redirect = cuegui.Redirect.RedirectWidget()

def test_setup(self):
pass

0 comments on commit 03c08a8

Please sign in to comment.