Skip to content

Commit

Permalink
handle jobs with no credit cost
Browse files Browse the repository at this point in the history
  • Loading branch information
jtherrmann committed Feb 28, 2024
1 parent b89b1ed commit f6a5c2d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/hyp3_sdk/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,4 +293,4 @@ def filter_jobs(
return Batch(filtered_jobs)

def total_credit_cost(self):
return sum(job.credit_cost for job in self.jobs)
return sum(job.credit_cost for job in self.jobs if job.credit_cost is not None)
18 changes: 18 additions & 0 deletions tests/test_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,17 @@ def test_batch_total_credit_cost():
batch = Batch()
assert batch.total_credit_cost() == 0

batch = Batch([
Job.from_dict({
'job_type': 'foo',
'job_id': 'foo',
'request_time': '2024-01-01T00:00:00Z',
'status_code': 'foo',
'user_id': 'foo',
}),
])
assert batch.total_credit_cost() == 0

batch = Batch([
Job.from_dict({
'job_type': 'foo',
Expand All @@ -455,6 +466,13 @@ def test_batch_total_credit_cost():
'user_id': 'foo',
'credit_cost': 4
}),
Job.from_dict({
'job_type': 'foo',
'job_id': 'foo',
'request_time': '2024-01-01T00:00:00Z',
'status_code': 'foo',
'user_id': 'foo',
}),
])
assert batch.total_credit_cost() == 4

Expand Down

0 comments on commit f6a5c2d

Please sign in to comment.