Skip to content

Commit 86601da

Browse files
committed
Don't return anything at all, just exit.
More Pythonic.
1 parent 6f8a9e1 commit 86601da

2 files changed

Lines changed: 18 additions & 25 deletions

File tree

nut2.py

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -280,32 +280,20 @@ def set_var(self, ups="", var="", value=""):
280280

281281
self._srv_handler.write("SET VAR %s %s %s\n" % (ups, var, value))
282282
result = self._srv_handler.read_until("\n")
283-
if result == "OK\n":
284-
return True
285-
else:
286-
raise PyNUTError(result)
283+
if result != "OK\n":
284+
raise PyNUTError(result.replace("\n", ""))
287285

288286
def run_command(self, ups="", command=""):
289-
"""Send a command to the specified UPS.
290-
291-
Returns OK on success or raises an error.
292-
"""
293-
287+
"""Send a command to the specified UPS."""
294288
logging.debug("run_command called...")
295289

296290
self._srv_handler.write("INSTCMD %s %s\n" % (ups, command))
297291
result = self._srv_handler.read_until("\n")
298-
if result == "OK\n":
299-
return True
300-
else:
292+
if result != "OK\n":
301293
raise PyNUTError(result.replace("\n", ""))
302294

303295
def fsd(self, ups=""):
304-
"""Send FSD command.
305-
306-
Returns OK on success or raises an error.
307-
"""
308-
296+
"""Send FSD command."""
309297
logging.debug("MASTER called...")
310298

311299
self._srv_handler.write("MASTER %s\n" % ups)
@@ -316,22 +304,18 @@ def fsd(self, ups=""):
316304
logging.debug("FSD called...")
317305
self._srv_handler.write("FSD %s\n" % ups)
318306
result = self._srv_handler.read_until("\n")
319-
if result == "OK FSD-SET\n":
320-
return True
321-
else:
307+
if result != "OK FSD-SET\n":
322308
raise PyNUTError(result.replace("\n", ""))
323309

324310
def help(self):
325311
"""Send HELP command."""
326-
327312
logging.debug("HELP called...")
328313

329314
self._srv_handler.write("HELP\n")
330315
return self._srv_handler.read_until("\n")
331316

332317
def ver(self):
333318
"""Send VER command."""
334-
335319
logging.debug("VER called...")
336320

337321
self._srv_handler.write("VER\n")

tests/testclient.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,10 @@ def test_get_rw_vars_invalid_ups(self):
118118
self.assertRaises(PyNUTError, self.client.list_rw_vars, self.invalid)
119119

120120
def test_set_rw_var_valid(self):
121-
assert(self.client.set_var(self.valid, self.valid, self.valid))
121+
try:
122+
self.client.set_var(self.valid, self.valid, self.valid)
123+
except PyNUTError:
124+
assert(False)
122125

123126
def test_set_rw_var_invalid(self):
124127
self.assertRaises(PyNUTError, self.client.set_var, self.invalid,
@@ -129,7 +132,10 @@ def test_set_rw_var_broken(self):
129132
self.valid, self.valid)
130133

131134
def test_run_ups_command_valid(self):
132-
assert(self.client.run_command(self.valid, self.valid))
135+
try:
136+
self.client.run_command(self.valid, self.valid)
137+
except PyNUTError:
138+
assert(False)
133139

134140
def test_run_ups_command_invalid(self):
135141
self.assertRaises(PyNUTError, self.client.run_command, self.invalid,
@@ -140,7 +146,10 @@ def test_run_ups_command_broken(self):
140146
self.valid)
141147

142148
def test_fsd_valid_ups(self):
143-
assert(self.client.fsd(self.valid))
149+
try:
150+
self.client.fsd(self.valid)
151+
except PyNUTError:
152+
assert(False)
144153

145154
def test_fsd_invalid_ups(self):
146155
self.assertRaises(PyNUTError, self.client.fsd, self.invalid)

0 commit comments

Comments
 (0)