Skip to content
This repository was archived by the owner on Jan 13, 2023. It is now read-only.

Commit 0b73ec4

Browse files
committed
Enhanced unit tests.
1 parent 69ac8bb commit 0b73ec4

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

test/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from __future__ import absolute_import, division, print_function, \
33
unicode_literals
44

5-
from collections import defaultdict
65
from typing import Dict, List, Optional, Text
76

87
from iota import BadApiResponse
@@ -25,7 +24,7 @@ def __init__(self):
2524
# type: (Optional[dict]) -> None
2625
super(MockAdapter, self).__init__()
2726

28-
self.responses = defaultdict(list) # type: Dict[Text, List[dict]]
27+
self.responses = {} # type: Dict[Text, List[dict]]
2928
self.requests = [] # type: List[dict]
3029

3130
def seed_response(self, command, response):
@@ -49,6 +48,9 @@ def seed_response(self, command, response):
4948
adapter.send_request({'command': 'sayHello'})
5049
# {'message': 'Hello!'}
5150
"""
51+
if command not in self.responses:
52+
self.responses[command] = []
53+
5254
self.responses[command].append(response)
5355
return self
5456

test/types_test.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,15 @@ def test_slice_accessor(self):
204204
self.assertEqual(ts[-4:], TryteString(b'KBFA'))
205205
self.assertEqual(ts[4:-4:4], TryteString(b'9CEY'))
206206

207+
with self.assertRaises(IndexError):
208+
# noinspection PyStatementEffect
209+
ts[42]
210+
211+
# To match the behavior of built-in types, TryteString will allow
212+
# you to access a slice that occurs after the end of the sequence.
213+
# There's nothing in it, of course, but you can access it.
214+
self.assertEqual(ts[42:43], TryteString(b''))
215+
207216
def test_slice_mutator(self):
208217
"""
209218
Modifying slices of a TryteString.
@@ -233,6 +242,14 @@ def test_slice_mutator(self):
233242
ts[2:-2:2] = b'IOTA'
234243
self.assertEqual(ts, TryteString(b'EFIFOOTAABFA'))
235244

245+
with self.assertRaises(IndexError):
246+
ts[42] = b'9'
247+
248+
# To match the behavior of built-in types, TryteString will allow
249+
# you to modify a slice that occurs after the end of the sequence.
250+
ts[42:43] = TryteString(b'9')
251+
self.assertEqual(ts, TryteString(b'EFIFOOTAABFA9'))
252+
236253
def test_iter_chunks(self):
237254
"""
238255
Iterating over a TryteString in constant-size chunks.

0 commit comments

Comments
 (0)