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

Commit 17d668d

Browse files
committed
Support Python 3.5
Minor refactor of test code, even though test data is all 7-bit ASCII clean add explicit encoding to all conversions. Added python 3.4 and 3.5 to TravisCI - no doc changes. Primary focus is 3.6 and 2.7.
1 parent 59e1453 commit 17d668d

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
language: python
22
python:
33
- "2.7"
4+
- "3.4"
5+
- "3.5"
46
- "3.6"
57
# command to install dependencies
68
install:

tests.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ def check_data_frame(data, expected_prefix, encrypted=True):
3333
checksum = data[19:35]
3434
encrypted_json = data[35:-8]
3535

36-
json_data = pytuya.AESCipher(LOCAL_KEY.encode('utf-8')).decrypt(encrypted_json)
36+
json_data = pytuya.AESCipher(LOCAL_KEY.encode(mock_byte_encoding)).decrypt(encrypted_json)
3737
else:
38-
json_data = data[16:-8].decode('utf-8')
38+
json_data = data[16:-8].decode(mock_byte_encoding)
3939

4040
frame_ok = True
4141
if prefix != pytuya.hex2bin(expected_prefix):
@@ -103,8 +103,9 @@ def test_set_timer(self):
103103
mock_send_receive_set_timer.call_counter = 0
104104
result = d.set_timer(6666)
105105
result = result[result.find(b'{'):result.rfind(b'}')+1]
106-
result = json.loads(result.decode())
107-
106+
result = result.decode(mock_byte_encoding) # Python 3 (3.5.4 and earlier) workaround to json stdlib "behavior" https://docs.python.org/3/whatsnew/3.6.html#json
107+
result = json.loads(result)
108+
108109
# Make sure mock_send_receive_set_timer() has been called twice with correct parameters
109110
self.assertEqual(result['test_result'], "SUCCESS")
110111

@@ -113,8 +114,9 @@ def test_set_status(self):
113114
d._send_receive = MagicMock(side_effect=mock_send_receive_set_status)
114115

115116
result = d.set_status(True, 1)
116-
result = json.loads(result.decode())
117-
117+
result = result.decode(mock_byte_encoding) # Python 3 (3.5.4 and earlier) workaround to json stdlib "behavior" https://docs.python.org/3/whatsnew/3.6.html#json
118+
result = json.loads(result)
119+
118120
# Make sure mock_send_receive_set_timer() has been called twice with correct parameters
119121
self.assertEqual(result['test_result'], "SUCCESS")
120122

0 commit comments

Comments
 (0)