summaryrefslogtreecommitdiff
path: root/utilities/test_blinkenrocket.py
blob: b2da0fde21a016d0369ccbff7176b479ce58f676 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/usr/bin/python
import unittest
from blinkenrocket import *

class TestFrame(unittest.TestCase):

  def test_notImplemented(self):
      frame = Frame()
      with self.assertRaises(NotImplementedError):
        frame.getRepresentation()

class TestAnimation(unittest.TestCase):

  def test_speedDefault(self):
    anim = animationFrame([])
    self.assertEquals(ord(anim.getHeader()[0]),1)

  def test_speedOkay(self):
    anim = animationFrame([],speed=7)
    self.assertEquals(ord(anim.getHeader()[0]),7)

  def test_speedNotOkay(self):
    anim = animationFrame([],speed=70)
    self.assertEquals(ord(anim.getHeader()[0]),1)

  def test_delayDefault(self):
    anim = animationFrame([])
    self.assertEquals(ord(anim.getHeader()[1]),0)

  def test_delayOkay(self):
    anim = animationFrame([],delay=7)
    self.assertEquals(ord(anim.getHeader()[1]),7)

  def test_delayNotOkay(self):
    anim = animationFrame([],delay=70)
    self.assertEquals(ord(anim.getHeader()[1]),0)

  def test_illegalLength(self):
    with self.assertRaises(Exception):
      anim = animationFrame([0x11,0x12,0x13,0x14])

  def test_allowedLength(self):
    anim = animationFrame([0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18])

  def test_defaultHeaderOK(self):
    anim = animationFrame([])
    self.assertEquals(anim.getHeader(),[chr(1),chr(0)])

  def test_differentHeaderOK(self):
    anim = animationFrame([],speed=7,delay=8)
    self.assertEquals(anim.getHeader(),[chr(7),chr(8)])

class TestText(unittest.TestCase):

  def test_speedDefault(self):
    text = textFrame([])
    self.assertEquals(ord(text.getHeader()[0]),(1 << 4 | 0))

  def test_speedOkay(self):
    text = textFrame([],speed=7)
    self.assertEquals(ord(text.getHeader()[0]),(7 << 4 | 0))

  def test_speedNotOkay(self):
    text = textFrame([],speed=70)
    self.assertEquals(ord(text.getHeader()[0]),(1 << 4 | 0))

  def test_delayDefault(self):
    text = textFrame([])
    self.assertEquals(ord(text.getHeader()[0]),(1 << 4 | 0))

  def test_delayOkay(self):
    text = textFrame([],delay=7)
    self.assertEquals(ord(text.getHeader()[0]),(1 << 4 | 7))

  def test_delayNotOkay(self):
    text = textFrame([],delay=70)
    self.assertEquals(ord(text.getHeader()[0]),(1 << 4 | 0))

  def test_directionDefault(self):
    text = textFrame([])
    self.assertEquals(ord(text.getHeader()[1]),0)

  def test_directionOkay(self):
    text = textFrame([],direction=1)
    self.assertEquals(ord(text.getHeader()[1]),(1 << 4 | 0))

  def test_directionNotOkay(self):
    text = textFrame([],direction=7)
    self.assertEquals(ord(text.getHeader()[1]),0)

  def test_defaultHeaderOK(self):
    text = textFrame([])
    self.assertEquals(text.getHeader(),[chr(1 << 4 | 0),chr(0)])

  def test_differentHeaderOK(self):
    text = textFrame([],speed=7,delay=8,direction=1)
    self.assertEquals(text.getHeader(),[chr(7 << 4 | 8),chr(1 << 4 | 0)])

class TestBlinkenrocket(unittest.TestCase):

  def test_addFrameFail(self):
    br = blinkenrocket()
    with self.assertRaises(Exception):
      br.addFrame([])

  def test_addFrameText(self):
    text = textFrame("MUZY",speed=7,delay=8,direction=1)
    self.assertEquals(text.getFrameHeader(),[chr(0x01 << 4), chr(4)])
    self.assertEquals(text.getHeader(),[chr(7 << 4 | 8),chr(1 << 4 | 0)])
    self.assertEquals(text.getRepresentation(),[chr(0x01 << 4), chr(4),chr(7 << 4 | 8),chr(1 << 4 | 0),'M','U','Z','Y'])
    br = blinkenrocket()
    br.addFrame(text)
    expect = [chr(0x99),chr(0x99),chr(0xA9),chr(0xA9),chr(0x01 << 4), chr(4),chr(7 << 4 | 8),chr(1 << 4 | 0),'M','U','Z','Y']
    self.assertEquals(br.getMessage(),expect)

if __name__ == '__main__':
    unittest.main()