Skip to content

Commit

Permalink
Merge f93a0e9 into e7a4e13
Browse files Browse the repository at this point in the history
  • Loading branch information
timgates42 committed Mar 18, 2020
2 parents e7a4e13 + f93a0e9 commit 115330d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
10 changes: 10 additions & 0 deletions app/meticulous/_input_queue.py
Expand Up @@ -26,6 +26,16 @@ def pop(self):
_, taskjson = heapq.heappop(self.queue)
return taskjson

def save(self):
"""
Get json serialization of queue
"""
result = []
while self.queue:
priority, taskjson = heapq.heappop(self.queue)
result.append({"priority": priority, "task": taskjson})
return result


def get_input_queue():
"""
Expand Down
17 changes: 17 additions & 0 deletions app/meticulous/_input_queue_test.py
Expand Up @@ -17,3 +17,20 @@ def test_priority():
task = manager.pop()
# Verify
assert task["name"] == "now" # noqa=S101 # nosec


def test_save():
"""
Ensure tasks are pulled off for suspension
"""
# Setup
manager = get_input_queue()
manager.add(10, {"name": "later"})
manager.add(1, {"name": "now"})
# Exercise
tasks = manager.save()
# Verify
assert tasks == [ # noqa=S101 # nosec
{"priority": 1, "task": {"name": "now"}},
{"priority": 10, "task": {"name": "later"}},
]

0 comments on commit 115330d

Please sign in to comment.