Validates that the JSON response is A-OK
"""
try:
- assert response is not None
- assert 'ok' in response
- assert response['ok']
+ assert response is not None, "Response not provided"
+ assert 'ok' in response, "Response lacks status"
+ assert response['ok'], "Response not good"
except AssertionError:
raise RuntimeError('There was a problem with GV: %s' % response)
)
def start(self):
- assert self._session.state == self._session.LOGGEDOUT_STATE
+ assert self._session.state == self._session.LOGGEDOUT_STATE, "Initialization messed up"
if self._defaultCredentials != ("", ""):
username, password = self._defaultCredentials[0], self._defaultCredentials[1]
self._curentCredentials = username, password
child.set_fullscreen(isFullscreen)
def _initialize_tab(self, index):
- assert index < self.MAX_TABS
+ assert index < self.MAX_TABS, "Invalid tab"
if not self._tabsContents[index].has_child():
tab = self._TAB_CLASS[index](self._app, self._session, self._errorLog)
self._tabsContents[index].set_child(tab)
def _on_row_activated(self, index):
with qui_utils.notify_error(self._errorLog):
timeIndex = index.parent()
- assert timeIndex.isValid()
+ assert timeIndex.isValid(), "Invalid row"
timeRow = timeIndex.row()
row = index.row()
detailsItem = self._categoryManager.get_item(timeRow, row, self.DETAILS_IDX)
def _on_row_activated(self, index):
with qui_utils.notify_error(self._errorLog):
timeIndex = index.parent()
- assert timeIndex.isValid()
+ assert timeIndex.isValid(), "Invalid row"
timeRow = timeIndex.row()
row = index.row()
item = self._categoryManager.get_item(timeRow, row, 0)
def _on_row_activated(self, index):
with qui_utils.notify_error(self._errorLog):
letterIndex = index.parent()
- assert letterIndex.isValid()
+ assert letterIndex.isValid(), "Invalid row"
letterRow = letterIndex.row()
letter = list(self._prefixes())[letterRow]
letterItem = self._alphaItem[letter]
self._backend = backend
def send(self, text):
- assert 0 < len(self._contacts)
+ assert 0 < len(self._contacts), "No contacts selected"
numbers = [misc_utils.make_ugly(contact.selectedNumber) for contact in self._contacts.itervalues()]
le = concurrent.AsyncLinearExecution(self._pool, self._send)
le.start(numbers, text)
def call(self):
- assert len(self._contacts) == 1
+ assert len(self._contacts) == 1, "Must select 1 and only 1 contact"
(contact, ) = self._contacts.itervalues()
number = misc_utils.make_ugly(contact.selectedNumber)
le = concurrent.AsyncLinearExecution(self._pool, self._call)
self.recipientsChanged.emit()
def remove_contact(self, contactId):
- assert contactId in self._contacts
+ assert contactId in self._contacts, "Contact missing"
del self._contacts[contactId]
self.recipientsChanged.emit()
def set_selected_number(self, cid, number):
# @note I'm lazy, this isn't firing any kind of signal since only one
# controller right now and that is the viewer
- assert number in (nWD[0] for nWD in self._contacts[cid].numbers)
+ assert number in (nWD[0] for nWD in self._contacts[cid].numbers), "Number not selectable"
self._contacts[cid].selectedNumber = number
def clear(self):
return self._draft
def login(self, username, password):
- assert self.state == self.LOGGEDOUT_STATE
- assert username != ""
+ assert self.state == self.LOGGEDOUT_STATE, "Can only log-in when logged out"
+ assert username != "", "No username specified"
if self._cachePath is not None:
cookiePath = os.path.join(self._cachePath, "%s.cookies" % username)
else:
le.start(username, password)
def logout(self):
- assert self.state != self.LOGGEDOUT_STATE
+ assert self.state != self.LOGGEDOUT_STATE, "Can only logout if logged in"
self._pool.stop()
self._loggedInTime = self._LOGGEDOUT_TIME
self._backend[0].persist()
self._save_to_cache()
def clear(self):
- assert self.state == self.LOGGEDOUT_STATE
+ assert self.state == self.LOGGEDOUT_STATE, "Can only clear when logged out"
self._backend[0].logout()
del self._backend[0]
self._clear_cache()
self._draft.clear()
def logout_and_clear(self):
- assert self.state != self.LOGGEDOUT_STATE
+ assert self.state != self.LOGGEDOUT_STATE, "Can only logout if logged in"
self._pool.stop()
self._loggedInTime = self._LOGGEDOUT_TIME
self.clear()
def _set_dnd(self, dnd):
# I'm paranoid about our state geting out of sync so we set no matter
# what but act as if we have the cannonical state
- assert self.state == self.LOGGEDIN_STATE
+ assert self.state == self.LOGGEDIN_STATE, "DND requires being logged in"
oldDnd = self._dnd
try:
with notify_busy(self._errorLog, "Setting DND Status"):
def _set_callback_number(self, callback):
# I'm paranoid about our state geting out of sync so we set no matter
# what but act as if we have the cannonical state
- assert self.state == self.LOGGEDIN_STATE
+ assert self.state == self.LOGGEDIN_STATE, "Callbacks configurable only when logged in"
oldCallback = self._callback
try:
with notify_busy(self._errorLog, "Setting Callback"):
self._push_login_op(op)
def _push_login_op(self, asyncOp):
- assert self.state != self.LOGGEDIN_STATE
+ assert self.state != self.LOGGEDIN_STATE, "Can only queue work when logged out"
if asyncOp in self._loginOps:
_moduleLogger.info("Skipping queueing duplicate op: %r" % asyncOp)
return
self._run = None
def start(self, *args, **kwds):
- assert self._run is None
+ assert self._run is None, "Task already started"
self._run = self._func(*args, **kwds)
trampoline, args, kwds = self._run.send(None) # priming the function
self._pool.add_task(
elif uglynumber.startswith("1"):
uglynumber = "+"+uglynumber
elif 10 <= len(uglynumber):
- assert uglynumber[0] not in ("+", "1")
+ assert uglynumber[0] not in ("+", "1"), "Number format confusing"
uglynumber = "+1"+uglynumber
else:
pass
self._stopPool.emit()
def add_task(self, func, args, kwds, on_success, on_error):
- assert self._isRunning
+ assert self._isRunning, "Task queue not started"
task = func, args, kwds, on_success, on_error
self._addTask.emit(task)
@QtCore.pyqtSlot()
@misc_utils.log_exception(_moduleLogger)
def _on_delayed_popup(self):
- assert self._popupLocation is not None
+ assert self._popupLocation is not None, "Widget location abuse"
self._popup_child(self._popupLocation)
@misc_utils.log_exception(_moduleLogger)
self._report_error("closed too early")
def _report_success(self):
- assert not self._didReport
+ assert not self._didReport, "Double reporting a missed call"
self._didReport = True
self._onTimeout.cancel()
self.__on_success(self)
def _report_error(self, reason):
- assert not self._didReport
+ assert not self._didReport, "Double reporting a missed call"
self._didReport = True
self._onTimeout.cancel()
self.__on_error(self, reason)