• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

jpwsutton / instax_api / 3811978815

pending completion
3811978815

Pull #30

github

GitHub
Merge bc650e95a into 51db4a494
Pull Request #30: feat: general code improvements and adding github workflow

945 of 945 new or added lines in 15 files covered. (100.0%)

1901 of 2101 relevant lines covered (90.48%)

0.9 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.24
/instax/tests/test_premade.py
1
"""
1✔
2
Instax SP2 Test File.
3

4
@jpwsutton 2016/17
5
"""
6
import unittest
1✔
7

8
from instax.packet import Packet, PacketFactory
1✔
9

10

11
class PacketTests(unittest.TestCase):
1✔
12
    """
1✔
13
    Instax-SP2 Premade Packet Test Class.
14

15
    A series of tests to verify that existing commands and responses can be
16
    correctly decoded.
17
    """
18

19
    def helper_verify_header(
1✔
20
        self,
21
        header,
22
        direction,
23
        type,
24
        length,
25
        time,
26
        pin=None,
27
        returnCode=None,
28
        unknown1=None,
29
        ejecting=None,
30
        battery=None,
31
        printCount=None,
32
    ):
33
        """Verify the Header of a packet."""
34
        self.assertEqual(header["startByte"], direction)
×
35
        self.assertEqual(header["cmdByte"], type)
×
36
        self.assertEqual(header["packetLength"], length)
×
37
        self.assertEqual(header["sessionTime"], time)
×
38
        if direction == Packet.MESSAGE_MODE_COMMAND:
×
39
            self.assertEqual(header["password"], pin)
×
40
        if direction == Packet.MESSAGE_MODE_RESPONSE:
×
41
            self.assertEqual(header["returnCode"], returnCode)
×
42
            # self.assertEqual(header['unknown1'], unknown1)
43
            self.assertEqual(header["ejecting"], ejecting)
×
44
            self.assertEqual(header["battery"], battery)
×
45
            self.assertEqual(header["printCount"], printCount)
×
46

47
    def test_premade_resp_specifications(self):
1✔
48
        """Test Decoding a Specifications Response with an existing payload."""
49
        msg = bytearray.fromhex(
1✔
50
            "2a4f 0030 e759 eede 0000 0000 0000 0027 0258"
51
            " 0320 0100 000a 0000 0000 ea60 1000 0000 0000"
52
            " 0000 0000 0000 0000 fa41 0d0a"
53
        )
54
        packetFactory = PacketFactory()
1✔
55
        decodedPacket = packetFactory.decode(msg)
1✔
56
        self.assertEqual(decodedPacket.payload["maxHeight"], 800)
1✔
57
        self.assertEqual(decodedPacket.payload["maxWidth"], 600)
1✔
58
        self.assertEqual(decodedPacket.payload["maxColours"], 256)
1✔
59
        self.assertEqual(decodedPacket.payload["unknown1"], 10)
1✔
60
        self.assertEqual(decodedPacket.payload["maxMsgSize"], 60000)
1✔
61
        self.assertEqual(decodedPacket.payload["unknown2"], 16)
1✔
62
        self.assertEqual(decodedPacket.payload["unknown3"], 0)
1✔
63

64
    def test_premade_resp_version(self):
1✔
65
        """Test Decoding a Version Response with an existing payload."""
66
        msg = bytearray.fromhex("2ac0 001c e759 eede 0000" " 0000 0000 0027 0101 0113" " 0000 0000 fbb0 0d0a")
1✔
67
        packetFactory = PacketFactory()
1✔
68
        decodedPacket = packetFactory.decode(msg)
1✔
69
        self.assertEqual(decodedPacket.payload["unknown1"], 257)
1✔
70
        self.assertEqual(decodedPacket.payload["firmware"], "01.13")
1✔
71
        self.assertEqual(decodedPacket.payload["hardware"], "00.00")
1✔
72

73
    def test_premade_resp_printCount(self):
1✔
74
        """Test Decoding a Print Count Response with an existing payload."""
75
        msg = bytearray.fromhex(
1✔
76
            "2ac1 0024 e759 eede 0000" " 0000 0000 0027 0000 0003" " 00f3 c048 0000 1645 001e" " 0000 f946 0d0a"
77
        )
78
        packetFactory = PacketFactory()
1✔
79
        decodedPacket = packetFactory.decode(msg)
1✔
80
        self.assertEqual(decodedPacket.payload["printHistory"], 3)
1✔
81

82
    def test_premade_cmd_modelName(self):
1✔
83
        """Test Decoding a Model Name Command."""
84
        msg = bytearray.fromhex("24c2 0010 0b8d c2b4 0457 0000 fca0 0d0a")
1✔
85
        packetFactory = PacketFactory()
1✔
86
        packetFactory.decode(msg)
1✔
87

88
    def test_premade_cmd_prePrint(self):
1✔
89
        """Test Decoding a Pre Print Command."""
90
        msg = bytearray.fromhex("24c4 0014 4e40 684c 0457" " 0000 0000 0008 fd5e 0d0a")
1✔
91
        packetFactory = PacketFactory()
1✔
92
        packetFactory.decode(msg)
1✔
93

94
    def test_premade_cmd_lock(self):
1✔
95
        """Test Decoding a Lock Command."""
96
        msg = bytearray.fromhex("24b3 0014 9619 02df 0457" " 0000 0100 0000 fd28 0d0a")
1✔
97
        packetFactory = PacketFactory()
1✔
98
        packetFactory.decode(msg)
1✔
99

100
    def test_premade_resp_lock(self):
1✔
101
        """Test Decoding a Lock Response."""
102
        msg = bytearray.fromhex("2ab3 0014 75b8 bd8e 0000" " 0000 0000 003a fc5c 0d0a")
1✔
103
        packetFactory = PacketFactory()
1✔
104
        packetFactory.decode(msg)
1✔
105

106
    def test_premade_cmd_reset(self):
1✔
107
        """Test Decoding a Reset Command."""
108
        msg = bytearray.fromhex("2450 0010 96c9 aada 0457" " 0000 fc3d 0d0a")
1✔
109
        packetFactory = PacketFactory()
1✔
110
        packetFactory.decode(msg)
1✔
111

112
    def test_premade_resp_reset(self):
1✔
113
        """Test Decoding a Reset Response."""
114
        msg = bytearray.fromhex("2a50 0014 75b8 bd8e 0000" " 0000 0000 003a fcbf 0d0a")
1✔
115
        packetFactory = PacketFactory()
1✔
116
        packetFactory.decode(msg)
1✔
117

118
    def test_premade_resp_prep(self):
1✔
119
        """Test Decoding a Prep Response."""
120
        msg = bytearray.fromhex("2451 001c 9b60 d511 0457" " 0000 1000 0015 f900 0000" "  0000 0000 fc14 0d0a")
1✔
121
        packetFactory = PacketFactory()
1✔
122
        packetFactory.decode(msg)
1✔
123

124
    def test_premade_resp_send(self):
1✔
125
        """Test decoding a send response."""
126
        msg = bytearray.fromhex("2a52 0018 75b8 bd8e 0000" " 0000 0000 003a 0000 0014 fca5 0d0a")
1✔
127
        packetFactory = PacketFactory()
1✔
128
        packetFactory.decode(msg)
1✔
129

130
    def test_premade_cmd_83(self):
1✔
131
        """Test decoding a type 83 command."""
132
        msg = bytearray.fromhex("2453 0010 c9a9 b71e 0457 0000 fcd6 0d0a")
1✔
133
        packetFactory = PacketFactory()
1✔
134
        packetFactory.decode(msg)
1✔
135

136
    def test_premade_resp_83(self):
1✔
137
        """Test decoding a type 83 response."""
138
        msg = bytearray.fromhex("2a53 0014 75b8 bd8e 0000" " 0000 0000 003a fcbc 0d0a")
1✔
139
        packetFactory = PacketFactory()
1✔
140
        packetFactory.decode(msg)
1✔
141

142
    def test_premade_cmd_lock_state(self):
1✔
143
        """Test decoding a Lock state command."""
144
        msg = bytearray.fromhex("24b0 0010 f776 ecbe 0457 0000 fba9 0d0a")
1✔
145
        packetFactory = PacketFactory()
1✔
146
        packetFactory.decode(msg)
1✔
147

148
    def test_premade_resp_lock_state(self):
1✔
149
        """Test decoding a Lock state response."""
150
        msg = bytearray.fromhex("2ab0 0018 f130 d7cc 0000 0000" " 0000 0036 0000 0064 fbaf 0d0a")
1✔
151
        packetFactory = PacketFactory()
1✔
152
        packetFactory.decode(msg)
1✔
153

154
    def test_premade_cmd_195(self):
1✔
155
        """Test decoding a 195 command."""
156
        msg = bytearray.fromhex("24c3 0010 f130 d7cc 0457 0000 fbe9 0d0a")
1✔
157
        packetFactory = PacketFactory()
1✔
158
        packetFactory.decode(msg)
1✔
159

160
    def test_premade_resp_195_first(self):
1✔
161
        """Test decoding a 195 first response."""
162
        msg = bytearray.fromhex("2ac3 0014 f130 d7cc 0000 0000" " 7f00 0436 fb81 0d0a")
1✔
163
        packetFactory = PacketFactory()
1✔
164
        packetFactory.decode(msg)
1✔
165

166
    def test_premade_resp_195_last(self):
1✔
167
        """Test decoding a 195 last response."""
168
        msg = bytearray.fromhex("2ac3 0014 f130 d7cc 0000 0000" " 0000 0035 fc05 0d0a")
1✔
169
        packetFactory = PacketFactory()
1✔
170
        packetFactory.decode(msg)
1✔
171

172

173
if __name__ == "__main__":
1✔
174

175
    unittest.main()
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc