Skip to content

Commit 9c9b0b7

Browse files
committed
allow for blob & timer unit testing
1 parent de9f6dd commit 9c9b0b7

File tree

6 files changed

+87
-12
lines changed

6 files changed

+87
-12
lines changed

azure/functions/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# Copyright (c) Microsoft Corporation. All rights reserved.
22
# Licensed under the MIT License.
33

4-
from ._abc import TimerRequest, InputStream, Context, Out
4+
from ._abc import Context, Out
5+
from ._blob import InputStream
56
from ._eventhub import EventHubEvent
67
from ._eventgrid import EventGridEvent, EventGridOutputEvent
78
from ._cosmosdb import Document, DocumentList
@@ -24,6 +25,7 @@
2425
from ._servicebus import ServiceBusMessage
2526
from ._sql import SqlRow, SqlRowList
2627
from ._mysql import MySqlRow, MySqlRowList
28+
from ._timer import TimerRequest
2729

2830
# Import binding implementations to register them
2931
from . import blob # NoQA

azure/functions/_blob.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
from typing import Optional
5+
6+
from azure.functions import _abc as azf_abc
7+
8+
9+
class InputStream(azf_abc.InputStream):
10+
"""An InputStream object.
11+
12+
:param str name:
13+
An optional str specifying the name of the blob.
14+
15+
:param str uri:
16+
An optional str specifying the uri of the blob.
17+
18+
:param str length:
19+
An optional int specifying the length of the blob.
20+
"""
21+
def __init__(self, *,
22+
name: Optional[str] = None,
23+
uri: Optional[str] = None,
24+
length: Optional[int] = None) -> None:
25+
self._name = name
26+
self._length = length
27+
self._uri = uri
28+
29+
@property
30+
def name(self) -> Optional[str]:
31+
"""The name of the blob."""
32+
return self._name
33+
34+
@property
35+
def length(self) -> Optional[int]:
36+
"""The size of the blob in bytes."""
37+
return self._length
38+
39+
@property
40+
def uri(self) -> Optional[str]:
41+
"""The blob's primary location URI."""
42+
return self._uri
43+
44+
45+
def read(self, size=-1) -> bytes:
46+
"""Return and read up to *size* bytes.
47+
48+
:param int size:
49+
The number of bytes to read. If the argument is omitted,
50+
``None``, or negative, data is read and returned until
51+
EOF is reached.
52+
53+
:return:
54+
Bytes read from the input stream.
55+
"""
56+
return self._io.read(size)

azure/functions/_timer.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
from . import _abc
5+
6+
7+
class TimerRequest(_abc.TimerRequest):
8+
"""A Timer Request object.
9+
10+
:param bool past_due:
11+
An optional boolean specifying if the timer is past due.
12+
"""
13+
14+
def __init__(self, *, past_due: bool = False) -> None:
15+
self.__past_due = past_due
16+
17+
@property
18+
def past_due(self) -> bool:
19+
"""Whether the timer is past due."""
20+
return self.__past_due

azure/functions/blob.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,19 @@
55
from typing import Any, Optional, Union
66

77
from azure.functions import _abc as azf_abc
8+
from azure.functions import _blob as azf_blob
89
from . import meta
910

1011

11-
class InputStream(azf_abc.InputStream):
12+
class InputStream(azf_blob.InputStream):
1213
def __init__(self, *, data: Union[bytes, meta.Datum],
1314
name: Optional[str] = None,
1415
uri: Optional[str] = None,
1516
length: Optional[int] = None,
1617
blob_properties: Optional[dict] = None,
1718
metadata: Optional[dict] = None) -> None:
19+
super().__init__(name=name, length=length, uri=uri)
1820
self._io = io.BytesIO(data) # type: ignore
19-
self._name = name
20-
self._length = length
21-
self._uri = uri
2221
self._blob_properties = blob_properties
2322
self._metadata = metadata
2423

azure/functions/queue.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414

1515
class QueueMessage(azf_queue.QueueMessage):
16-
"""An HTTP response object."""
16+
"""A Queue message object."""
1717

1818
def __init__(self, *,
1919
id=None, body=None,

azure/functions/timer.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,20 @@
55
import typing
66

77
from azure.functions import _abc as azf_abc
8+
from azure.functions import _timer as azf_timer
89
from . import meta
910

1011

11-
class TimerRequest(azf_abc.TimerRequest):
12+
class TimerRequest(azf_timer.TimerRequest):
13+
"""A Timer request object."""
1214

1315
def __init__(self, *, past_due: bool = False,
1416
schedule_status: typing.Optional[dict] = None,
1517
schedule: typing.Optional[dict] = None) -> None:
16-
self.__past_due = past_due
18+
super().__init__(past_due=past_due)
1719
self.__schedule_status = schedule_status if schedule_status else {}
1820
self.__schedule = schedule if schedule else {}
1921

20-
@property
21-
def past_due(self) -> bool:
22-
return self.__past_due
23-
2422
@property
2523
def schedule_status(self) -> dict:
2624
return self.__schedule_status

0 commit comments

Comments
 (0)