Skip to content

Commit a9037e8

Browse files
authored
Merge pull request #25 from nitrictech/feature/codecov
ci: add code coverage
2 parents c30ebba + a947dbb commit a9037e8

6 files changed

Lines changed: 38 additions & 6 deletions

File tree

.github/workflows/test.yaml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
name: Tests
22

3-
on: pull_request
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
48

59
jobs:
610
build:
@@ -27,3 +31,8 @@ jobs:
2731
- name: Run Tox
2832
# Run tox using the version of Python in `PATH`
2933
run: tox -e py
34+
- name: Upload coverage to Codecov
35+
uses: codecov/codecov-action@v1
36+
with:
37+
fail_ci_if_error: true
38+
token: ${{ secrets.CODECOV_TOKEN }}

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
<img src="https://github.com/nitrictech/python-sdk/raw/main/docs/assets/dot-matrix-logo-python.png" alt="Nitric Python SDK Logo"/>
33
</p>
44

5+
![test status](https://github.com/nitrictech/python-sdk/actions/workflows/test.yaml/badge.svg?branch=main)
6+
[![codecov](https://codecov.io/gh/nitrictech/python-sdk/branch/main/graph/badge.svg?token=SBFRNSZ4ZF)](https://codecov.io/gh/nitrictech/python-sdk)
7+
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=nitrictech_python-sdk&metric=alert_status)](https://sonarcloud.io/dashboard?id=nitrictech_python-sdk)
8+
59
# Nitric Python SDK
610

711
The Python SDK supports the use of the cloud-portable [Nitric](https://nitric.io) framework with Python 3.7+.

nitric/api/documents.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ def query(
151151
)
152152

153153
def sub_collection_depth(self) -> int:
154+
"""Return the depth of this collection, which is a count of the parents above this collection."""
154155
if not self.is_sub_collection():
155156
return 0
156157
else:
@@ -271,14 +272,17 @@ class Document:
271272

272273
@property
273274
def id(self):
275+
"""Return the document's unique id."""
274276
return self._ref.id
275277

276278
@property
277279
def collection(self) -> CollectionRef:
280+
"""Return the CollectionRef for the collection that contains this document."""
278281
return self._ref.parent
279282

280283
@property
281284
def ref(self):
285+
"""Return the DocumentRef for this document."""
282286
return self._ref
283287

284288

@@ -289,6 +293,10 @@ class QueryResultsPage:
289293
paging_token: any = field(default_factory=lambda: None)
290294
documents: List[Document] = field(default_factory=lambda: [])
291295

296+
def has_more_pages(self) -> bool:
297+
"""Return false if the page token is None or empty (both represent no more pages)."""
298+
return bool(self.paging_token)
299+
292300

293301
class QueryBuilder:
294302
"""Document query builder for retrieving documents from a collection based on filters."""
@@ -416,7 +424,7 @@ async def fetch(self) -> QueryResultsPage:
416424
)
417425

418426
return QueryResultsPage(
419-
paging_token=results.paging_token,
427+
paging_token=results.paging_token if results.paging_token else None,
420428
documents=[_document_from_wire(documents=self._documents, message=result) for result in results.documents],
421429
)
422430

nitric/faas/faas.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@
3131

3232
async def _register_faas_worker(
3333
func: Callable[
34-
[Trigger], Union[Coroutine[Any, Any, Union[Response, None, dict, bytes]], Union[Response, None, dict, bytes]]
34+
[Trigger],
35+
Union[
36+
Coroutine[Any, Any, Union[Response, None, dict, list, set, bytes]],
37+
Union[Response, None, dict, list, set, bytes],
38+
],
3539
]
3640
):
3741
"""
@@ -74,7 +78,7 @@ async def _register_faas_worker(
7478
if isinstance(response, bytes):
7579
full_response.data = response
7680
# convert dict responses to JSON
77-
elif isinstance(response, dict):
81+
elif isinstance(response, (dict, list, set)):
7882
full_response.data = bytes(json.dumps(response), "utf-8")
7983
if full_response.context.is_http():
8084
full_response.context.as_http().headers["Content-Type"] = "application/json"
@@ -106,7 +110,7 @@ async def _register_faas_worker(
106110
channel.close()
107111

108112

109-
def start(handler: Callable[[Trigger], Coroutine[Any, Any, Union[Response, None, dict, bytes]]]):
113+
def start(handler: Callable[[Trigger], Coroutine[Any, Any, Union[Response, None, dict, list, set, bytes]]]):
110114
"""
111115
Register the provided function as the trigger handler and starts handling new trigger requests.
112116

nitric/faas/response.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,13 @@ class Response(object):
9393
data: Union[bytes, str, None, Any] = field(default=None)
9494

9595
def data_to_bytes(self) -> bytes:
96+
"""
97+
Return the data from this response. If not already bytes, the data will be converted.
98+
99+
None returns an empty byte array.
100+
str will be converted directly to bytes
101+
All other types are converted to JSON using json.dumps, then to bytes from the JSON string.
102+
"""
96103
if self.data is None:
97104
return bytes()
98105
elif isinstance(self.data, bytes):

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ envlist = linter,py3.8
55
deps =
66
-e .[dev]
77
commands =
8-
pytest .
8+
pytest --cov=./nitric --cov-report=xml
99

1010
[testenv:linter]
1111
deps =

0 commit comments

Comments
 (0)