Skip to content

Commit 9c986cb

Browse files
committed
Adjust assert to use truthy expressions
This is a small improvement, detected during code review. Re ECFLOW-2110
1 parent 6cd2782 commit 9c986cb

4 files changed

Lines changed: 36 additions & 45 deletions

File tree

libs/pyext/test/ecflow_test_util.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ def clean_up_data(port):
142142
print(" Remove OK")
143143
except:
144144
print(" Remove Failed")
145-
pass
146145

147146

148147
class Protocol(Enum):
@@ -158,7 +157,6 @@ class EcfPortLock(object):
158157
def __init__(self, protocol):
159158
print(" EcfPortLock:__init__")
160159
self._protocol = protocol
161-
pass
162160

163161
def at_time(self):
164162
return datetime.datetime.fromtimestamp(time.time()).strftime("%H:%M:%S")
@@ -173,7 +171,7 @@ def find_free_port(self, seed_port):
173171
port = seed_port
174172
while 1:
175173
# port must be free for at least 15 seconds
176-
if self._timed_free_port(port, 3) == True:
174+
if self._timed_free_port(port, 3):
177175
print(
178176
" *FOUND* free server port " + str(port) + " : " + self.at_time()
179177
)
@@ -193,7 +191,7 @@ def find_free_port(self, seed_port):
193191
def _timed_free_port(self, port, wait_time=10):
194192
count = 0
195193
while count < wait_time:
196-
if self._free_port(port) == True:
194+
if self._free_port(port):
197195
count = count + 1
198196
time.sleep(1)
199197
else:
@@ -431,7 +429,6 @@ def __enter__(self):
431429

432430
def __exit__(self, exception_type, exception_value, exception_traceback):
433431
os.remove(self.name)
434-
pass
435432

436433
def __str__(self):
437434
return f"Test.MockFile({self.name}, {self.content})"

libs/pyext/test/py_s_TestClientApi.py

Lines changed: 29 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -240,13 +240,13 @@ def test_set_host_port(self):
240240
assert _can_set_host_port(ci, "host", 4444), "Expected no errors"
241241
assert _can_set_combined_host_port(ci, "host:4444"), "Expected no errors"
242242
assert _can_set_combined_host_port(ci, "host@4444"), "Expected no errors"
243-
assert _can_set_host_port(ci, "", "") == False, "Expected errors"
244-
assert _can_set_host_port(ci, "host", "") == False, "Expected errors"
245-
assert _can_set_host_port(ci, "host", "host") == False, "Expected errors"
246-
assert _can_set_combined_host_port(ci, "host:host") == False, "Expected errors"
247-
assert _can_set_combined_host_port(ci, "3141:host") == False, "Expected errors"
248-
assert _can_set_combined_host_port(ci, "3141@host") == False, "Expected errors"
249-
assert _can_set_combined_host_port(ci, "3141@") == False, "Expected errors"
243+
assert not _can_set_host_port(ci, "", ""), "Expected errors"
244+
assert not _can_set_host_port(ci, "host", ""), "Expected errors"
245+
assert not _can_set_host_port(ci, "host", "host"), "Expected errors"
246+
assert not _can_set_combined_host_port(ci, "host:host"), "Expected errors"
247+
assert not _can_set_combined_host_port(ci, "3141:host"), "Expected errors"
248+
assert not _can_set_combined_host_port(ci, "3141@host"), "Expected errors"
249+
assert not _can_set_combined_host_port(ci, "3141@"), "Expected errors"
250250

251251
assert _can_construct_client_with_host_port(
252252
"host", "3141"
@@ -255,18 +255,16 @@ def test_set_host_port(self):
255255
assert _can_construct_client_with_combined_host_port(
256256
"host:4444"
257257
), "Expected no errors"
258-
assert _can_construct_client_with_host_port("", "") == False, "Expected errors"
259-
assert (
260-
_can_construct_client_with_host_port("host", "") == False
258+
assert not _can_construct_client_with_host_port("", ""), "Expected errors"
259+
assert not _can_construct_client_with_host_port("host", ""), "Expected errors"
260+
assert not _can_construct_client_with_host_port(
261+
"host", "host"
261262
), "Expected errors"
262-
assert (
263-
_can_construct_client_with_host_port("host", "host") == False
263+
assert not _can_construct_client_with_combined_host_port(
264+
"host:host"
264265
), "Expected errors"
265-
assert (
266-
_can_construct_client_with_combined_host_port("host:host") == False
267-
), "Expected errors"
268-
assert (
269-
_can_construct_client_with_combined_host_port("3141:host") == False
266+
assert not _can_construct_client_with_combined_host_port(
267+
"3141:host"
270268
), "Expected errors"
271269

272270

@@ -480,8 +478,8 @@ def test_client_checkpt(self):
480478
assert os.path.exists(
481479
Test.checkpt_file_path(port)
482480
), "Expected check pt file to exist after ci.checkpt()"
483-
assert (
484-
os.path.exists(Test.backup_checkpt_file_path(port)) == False
481+
assert not os.path.exists(
482+
Test.backup_checkpt_file_path(port)
485483
), "Expected back up check pt file to *NOT* exist"
486484

487485
self.ci.checkpt() # second check pt should cause backup check pt to be written
@@ -1927,9 +1925,9 @@ def test_client_alter_change(self):
19271925
sync_local(self.ci)
19281926
task_t1 = self.ci.get_defs().find_abs_node(t1)
19291927
event = task_t1.find_event("event")
1930-
assert (
1931-
event.value() == True
1932-
), "Expected alter of event to be set but found " + str(event.value())
1928+
assert event.value(), "Expected alter of event to be set but found " + str(
1929+
event.value()
1930+
)
19331931
res = self.ci.query("event", task_t1.get_abs_node_path(), "event")
19341932
assert res == "set", "Expected alter of event to be 'set' but found " + res
19351933

@@ -2129,12 +2127,10 @@ def test_client_force(self):
21292127
for event in task.events:
21302128
event_fnd = True
21312129
if ev_state == "set":
2132-
assert event.value() == True, " Expected event value to be set"
2130+
assert event.value(), " Expected event value to be set"
21332131
else:
2134-
assert (
2135-
event.value() == False
2136-
), " Expected event value to be clear"
2137-
assert event_fnd == True, " Expected event to be found"
2132+
assert not event.value(), " Expected event value to be clear"
2133+
assert event_fnd, " Expected event to be found"
21382134

21392135
event_path_list = [
21402136
"/test_client_force/f1/t1:event",
@@ -2150,12 +2146,10 @@ def test_client_force(self):
21502146
for event in task.events:
21512147
event_fnd = True
21522148
if ev_state == "set":
2153-
assert event.value() == True, " Expected event value to be set"
2149+
assert event.value(), " Expected event value to be set"
21542150
else:
2155-
assert (
2156-
event.value() == False
2157-
), " Expected event value to be clear"
2158-
assert event_fnd == True, " Expected event to be found"
2151+
assert not event.value(), " Expected event value to be clear"
2152+
assert event_fnd, " Expected event to be found"
21592153

21602154
@pytest.mark.parametrize("on_disk", [False, True], ids=["in_memory", "on_disk"])
21612155
def test_client_replace(self, on_disk):
@@ -2405,7 +2399,7 @@ def test_client_resume(self):
24052399
self.ci.resume("/test_client_resume")
24062400
sync_local(self.ci)
24072401
suite = self.ci.get_defs().find_suite("test_client_resume")
2408-
assert suite.is_suspended() == False, "Expected to find suite resumed"
2402+
assert not suite.is_suspended(), "Expected to find suite resumed"
24092403

24102404
def test_client_resume_multiple_paths(self):
24112405
print_test(self.ci, "test_client_resume_multiple_paths")
@@ -2443,8 +2437,8 @@ def test_client_resume_multiple_paths(self):
24432437
task_t2 = self.ci.get_defs().find_abs_node(
24442438
"/test_client_resume_multiple_paths/f1/t2"
24452439
)
2446-
assert task_t1.is_suspended() == False, "Expected to find task t1 to be resumed"
2447-
assert task_t2.is_suspended() == False, "Expected to find task t2 to be resumed"
2440+
assert not task_t1.is_suspended(), "Expected to find task t1 to be resumed"
2441+
assert not task_t2.is_suspended(), "Expected to find task t2 to be resumed"
24482442

24492443
def test_client_delete_node(self):
24502444
print_test(self.ci, "test_client_delete_node")

libs/pyext/test/py_u_TestNodeAdd.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def test_node_dunder_lshift(self):
116116
len(list(suite))
117117
)
118118

119-
assert suite.t4.get_trigger() == None, "Trigger not as expected: " + str(
119+
assert suite.t4.get_trigger() is None, "Trigger not as expected: " + str(
120120
suite.t4.get_trigger()
121121
)
122122
assert (
@@ -134,7 +134,7 @@ def test_node_dunder_lshift(self):
134134
len(list(fam))
135135
)
136136

137-
assert fam.t4.get_trigger() == None, "Trigger not as expected: " + str(
137+
assert fam.t4.get_trigger() is None, "Trigger not as expected: " + str(
138138
fam.t4.get_trigger()
139139
)
140140
assert (
@@ -161,7 +161,7 @@ def test_node_dunder_lshift_trigger_cat(self):
161161
len(list(suite))
162162
)
163163

164-
assert suite.t4.get_trigger() == None, "Trigger not as expected: " + str(
164+
assert suite.t4.get_trigger() is None, "Trigger not as expected: " + str(
165165
suite.t4.get_trigger()
166166
)
167167
assert (

libs/pyext/test/py_u_TestRepeatArithmetic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def _test_repeat_arithmetic(repeat_to_add, repeat_to_add2):
2828

2929
# Initial value of repeat is 20090101 hence trigger should fail to evaluate
3030
assert (
31-
t2.evaluate_trigger() is False
31+
not t2.evaluate_trigger()
3232
), "Expected trigger to evaluate. 20090101 >= 20100601"
3333

3434
# Check end of month - 1
@@ -62,7 +62,7 @@ def _test_repeat_datetime_arithmetic(repeat_to_add, repeat_to_add2):
6262

6363
# Initial value of repeat is 20090101 hence trigger should fail to evaluate
6464
assert (
65-
t2.evaluate_trigger() is False
65+
not t2.evaluate_trigger()
6666
), "Expected trigger to evaluate. 20090101T000000 >= 20100601T000000"
6767

6868
# Check end of month - 1 day

0 commit comments

Comments
 (0)