Skip to content
This repository was archived by the owner on Dec 14, 2021. It is now read-only.

Commit ad36d47

Browse files
committed
Add testing library to patch dependencies in unittests
- Since there needs to be a support for python 2.7, 3.5 and 3.6 the default unittest.mock will not work. The dependency "mock" makes it work but it forced to rename the already existing mock.py (so it can be properly imported)
1 parent 586ef88 commit ad36d47

File tree

4 files changed

+11
-10
lines changed

4 files changed

+11
-10
lines changed
File renamed without changes.

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ pycodestyle
55
grpcio==1.7.3
66
protobuf
77
googleapis-common-protos
8+
mock==2.0.0

test_application.py

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

66

77
import unittest
8-
from mock import MockApplicationManager
8+
from app_mock import MockApplicationManager
99
from ttn import ApplicationClient
1010
import ttn.github_com.TheThingsNetwork.api.handler.handler_pb2 as handler
1111
from ttn.utils import stubs

test_discovery.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# MIT license that can be found in the LICENSE file.
55

66
import unittest
7-
from unittest.mock import patch
7+
from mock import patch
88

99
from ttn import DiscoveryClient
1010

@@ -15,15 +15,15 @@ def test_constructor_discovery(self):
1515
self.discovery = DiscoveryClient()
1616
assert hasattr(self.discovery, "client")
1717

18-
def test_default_insecure_channel_set_to_false(self):
19-
with patch("grpc.secure_channel") as mock_grpc_secure_channel:
20-
self.discovery = DiscoveryClient()
21-
assert mock_grpc_secure_channel.call_count == 1
18+
@patch("grpc.secure_channel")
19+
def test_default_insecure_channel_set_to_false(self, mock_grpc_secure_channel):
20+
self.discovery = DiscoveryClient()
21+
assert mock_grpc_secure_channel.call_count == 1
2222

23-
def test_insecure_channel_called(self):
24-
with patch("grpc.insecure_channel") as mock_grpc_insecure_channel:
25-
self.discovery = DiscoveryClient(insecure_channel=True)
26-
assert mock_grpc_insecure_channel.call_count == 1
23+
@patch("grpc.insecure_channel")
24+
def test_insecure_channel_called(self,mock_grpc_insecure_channel):
25+
self.discovery = DiscoveryClient(insecure_channel=True)
26+
assert mock_grpc_insecure_channel.call_count == 1
2727

2828
def test_get_by_app_id(self):
2929
self.discovery = DiscoveryClient()

0 commit comments

Comments
 (0)