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

Fix comments ui unit tests #1360

Merged
Merged
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ htmlcov/
/.env
.envrc
.vscode
.venv/
22 changes: 18 additions & 4 deletions cuegui/cuegui/Comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,13 @@ def refreshComments(self):
last_items = []
for i in range(self.__treeSubjects.topLevelItemCount()):
comment_source = self.__treeSubjects.topLevelItem(i)
last_items.append(comment_source.child(comment_source.childCount()-1))
comment = comment_source.child(comment_source.childCount()-1)
if comment:
last_items.append(comment)
if not last_items:
self.__createNewComment()
return

identical = all(item.getInstance().message() == last_items[0].getInstance().message() and
item.getInstance().subject() == last_items[0].getInstance().subject()
for item in last_items)
Expand All @@ -254,9 +260,10 @@ def refreshComments(self):
def __macroLoad(self):
"""Loads the defined comment macros from settings"""
comments_macro = self.app.settings.value("Comments", pickle.dumps({}))
try:
self.__macroList = pickle.loads(
comments_macro if isinstance(comments_macro, bytes) else comments_macro.encode('UTF-8'))
try:
self.__macroList = pickle.loads(
comments_macro if isinstance(comments_macro, bytes) \
else comments_macro.encode('UTF-8'))
except TypeError:
self.__macroList = pickle.loads(str(comments_macro))
self.__macroRefresh()
Expand Down Expand Up @@ -342,6 +349,13 @@ def __addComment(self, subject, message):
for source in self.__source:
source.addComment(str(subject), str(message) or " ")

def getComments(self):
"""Get Comments"""
comments = {}
for source in self.__source:
comments[source.data.name] = source.getComments()
return comments


class CommentMacroDialog(QtWidgets.QDialog):
"""A dialog for adding or modifying macro comments"""
Expand Down
2 changes: 1 addition & 1 deletion cuegui/cuegui/ServiceDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
from qtpy import QtWidgets

import opencue
from opencue.wrappers.service import ServiceOverride

import cuegui.Constants
import cuegui.TagsWidget
import cuegui.Utils
from opencue.wrappers.service import ServiceOverride


class ServiceForm(QtWidgets.QWidget):
Expand Down
17 changes: 9 additions & 8 deletions cuegui/tests/Comments_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,21 @@ def setUp(self, getStubMock):
opencue.compiled_proto.job_pb2.JobGetCommentsResponse(
comments=opencue.compiled_proto.comment_pb2.CommentSeq(comments=[commentProto]))

self.job = opencue.wrappers.job.Job(opencue.compiled_proto.job_pb2.Job(name='fooJob'))
self.job_name = "fooJob"
self.job = opencue.wrappers.job.Job(opencue.compiled_proto.job_pb2.Job(name=self.job_name))
self.parentWidget = QtWidgets.QWidget()
self.commentListDialog = cuegui.Comments.CommentListDialog(
self.job, parent=self.parentWidget)
[self.job], parent=self.parentWidget)

def test_shouldDisplayComment(self):
self.assertEqual(
1, self.commentListDialog._CommentListDialog__treeSubjects.topLevelItemCount())
gotTreeWidgetItem = self.commentListDialog._CommentListDialog__treeSubjects.topLevelItem(0)
gotComment = gotTreeWidgetItem._Comment__comment
self.assertEqual(self.comment.timestamp(), gotComment.timestamp())
self.assertEqual(self.comment.user(), gotComment.user())
self.assertEqual(self.comment.subject(), gotComment.subject())
self.assertEqual(self.comment.message(), gotComment.message())
comments_per_job = self.commentListDialog.getComments()
comment = comments_per_job[self.job_name][0]
self.assertEqual(self.comment.timestamp(), comment.timestamp())
self.assertEqual(self.comment.user(), comment.user())
self.assertEqual(self.comment.subject(), comment.subject())
self.assertEqual(self.comment.message(), comment.message())

def test_shouldRefreshJobComments(self):
self.job.getComments = mock.Mock(return_value=[])
Expand Down
4 changes: 3 additions & 1 deletion cuesubmit/cuesubmit/ui/Widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ def __init__(self, label=None, parent=None,
max_value=999,
float_precision=None):
super(CueLabelSlider, self).__init__(parent=parent)
self._labelValue = f'{label} ({{value}})'
self._labelValue = "%s ({value})" % label
self.float_mult = 1
if float_precision:
self.float_mult = 10**float_precision
Expand Down Expand Up @@ -322,11 +322,13 @@ def setupUi(self):
def setupConnections(self):
"""Sets up widget signals."""
self.valueChanged.connect(self.updateLabelValue)
# pylint: disable=no-member
self.slider.valueChanged.connect(self.valueChanged.emit)
self.slider.sliderMoved.connect(self.sliderMoved.emit)
self.slider.sliderReleased.connect(self.sliderReleased.emit)
self.slider.actionTriggered.connect(self.actionTriggered.emit)
self.slider.rangeChanged.connect(self.rangeChanged.emit)
# pylint: enable=no-member

def updateLabelValue(self, value):
""" Updates the label with the slider's value at the end
Expand Down
14 changes: 8 additions & 6 deletions pycue/opencue/wrappers/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,22 +261,24 @@ def setMinMemoryIncrease(self, min_memory_increase):
raise ValueError("Minimum memory increase must be > 0")

class ServiceOverride(object):
"""Represents a display override of a service assigned to a show"""
def __init__(self, serviceOverride=None):
defaultServiceOverride = service_pb2.ServiceOverride()
# pylint: disable=no-member
self.id = defaultServiceOverride.id
self.data = defaultServiceOverride.data
if serviceOverride:
self.id = serviceOverride.id
self.data = serviceOverride.data or service_pb2.Service().data
else:
defaultServiceOverride = service_pb2.ServiceOverride()
self.id = defaultServiceOverride.id
self.data = defaultServiceOverride.data

self.stub = Cuebot.getStub("serviceOverride")
# pylint: enable=no-member

def delete(self):
"""Remove service override"""
self.stub.Delete(
service_pb2.ServiceOverrideDeleteRequest(service=self.data),
timeout=Cuebot.Timeout)

def update(self):
"""Commit a ServiceOverride change to the database"""
self.stub.Update(
Expand Down
1 change: 0 additions & 1 deletion pycue/opencue/wrappers/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ def createServiceOverride(self, data):
# min_memory_increase has to be greater than 0.
if data.min_memory_increase <= 0:
raise ValueError("Minimum memory increase must be > 0")

self.stub.CreateServiceOverride(show_pb2.ShowCreateServiceOverrideRequest(
show=self.data, service=data),
timeout=Cuebot.Timeout)
Expand Down
Loading