Skip to content

Commit

Permalink
Merge several nested if conditions into one (#83)
Browse files Browse the repository at this point in the history
* Merge nested if conditions

* Use f-string instead of string concatenation

* Revert modification on third party file `flask_uploads.py`
  • Loading branch information
ThibFrgsGmz authored Jul 13, 2022
1 parent ac1b669 commit 65126bf
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
15 changes: 8 additions & 7 deletions src/fprime_gds/common/testing_fw/predicates.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@ def is_predicate(pred):
if callable(pred):
sig = signature(pred.__call__)
arg_count = len(sig.parameters)
if arg_count == 1:
if hasattr(pred, "__str__"):
return True
if arg_count == 1 and hasattr(pred, "__str__"):
return True
return False


Expand Down Expand Up @@ -538,10 +537,12 @@ def __call__(self, telemetry):
"""
if not isinstance(telemetry, ChData):
return False
if self.id_pred(telemetry.get_id()):
if self.value_pred(telemetry.get_val()):
if self.time_pred(telemetry.get_time()):
return True
if (
self.id_pred(telemetry.get_id())
and self.value_pred(telemetry.get_val())
and self.time_pred(telemetry.get_time())
):
return True
return False

def __str__(self):
Expand Down
2 changes: 1 addition & 1 deletion src/fprime_gds/flask/flask_uploads.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def config_for_set(uset, app, defaults=None):
using_defaults = True
destination = os.path.join(defaults["dest"], uset.name)
else:
raise RuntimeError(f"no destination for set {uset.name}")
raise RuntimeError(f"no destination for set {uset.name}")

if base_url is None and using_defaults and defaults["url"]:
base_url = addslash(defaults["url"]) + uset.name + "/"
Expand Down
5 changes: 2 additions & 3 deletions test/fprime_gds/common/testing_fw/api_unit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,8 @@ def fill_history(self, callback, items, timestep=0.0):
for item in items:
if timestep:
time.sleep(timestep)
if isinstance(item, ChData) or isinstance(item, EventData):
if item.time == 0:
item.time = self.t0 + time.time()
if isinstance(item, (ChData, EventData)) and item.time == 0:
item.time = self.t0 + time.time()
callback(item)

def fill_history_async(self, callback, items, timestep=1.0):
Expand Down

0 comments on commit 65126bf

Please sign in to comment.