Rearranging code: corrections and splitting tests after file renaming

rebase020124
Ben 12 months ago
parent 2e51a018d2
commit e206fa903d
  1. 1
      led-badge-12x48.py
  2. 7
      lednamebadge.py
  3. 35
      tests/test_lednamebadge_create.py
  4. 59
      tests/test_lednamebadge_write.py

@ -1 +0,0 @@
led-badge-11x44.py

@ -225,6 +225,7 @@ class SimpleTextAndIcons:
u"ÀÅÄÉÈÊËÖÔÜÛÙŸ" u"ÀÅÄÉÈÊËÖÔÜÛÙŸ"
char_offsets = {} char_offsets = {}
pass
for i in range(len(charmap)): for i in range(len(charmap)):
char_offsets[charmap[i]] = 11 * i char_offsets[charmap[i]] = 11 * i
# print(i, charmap[i], char_offset[charmap[i]]) # print(i, charmap[i], char_offset[charmap[i]])
@ -522,7 +523,7 @@ or
def split_to_ints(list_str): def split_to_ints(list_str):
return tuple([int(x) for x in re.split(r'[\s,]+', list_str)]) return tuple([int(x) for x in re.split(r'[\s,]+', list_str)])
if __name__ == '__main__': def main():
parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter, parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter,
description='Upload messages or graphics to a 11x44 led badge via USB HID.\nVersion %s from https://github.com/jnweiger/led-badge-ls32\n -- see there for more examples and for updates.' % __version, description='Upload messages or graphics to a 11x44 led badge via USB HID.\nVersion %s from https://github.com/jnweiger/led-badge-ls32\n -- see there for more examples and for updates.' % __version,
epilog='Example combining image and text:\n sudo %s "I:HEART2:you"' % sys.argv[0]) epilog='Example combining image and text:\n sudo %s "I:HEART2:you"' % sys.argv[0])
@ -606,3 +607,7 @@ if __name__ == '__main__':
buf.extend((0,) * (64 - need_padding)) buf.extend((0,) * (64 - need_padding))
LedNameBadge.write(buf) LedNameBadge.write(buf)
if __name__ == '__main__':
main()

@ -0,0 +1,35 @@
import datetime
from array import array
from unittest import TestCase
from lednamebadge import SimpleTextAndIcons as testee
class Test(TestCase):
def test_bitmap_png(self):
creator = testee()
buf = creator.bitmap("resources/bitpatterns.png")
self.assertEqual((array('B',
[128, 64, 32, 16, 8, 4, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 64, 32, 0, 1, 2, 3,
4, 5, 15, 31, 63, 127, 255]),
3), buf)
def test_bitmap_text(self):
creator = testee()
buf = creator.bitmap("/:HEART2:\\")
self.assertEqual((array('B',
[0, 0, 2, 6, 12, 24, 48, 96, 192, 128, 0, 0, 12, 30, 63, 63, 63, 31, 15, 7, 3, 1, 0, 96,
240, 248, 248, 248, 240, 224, 192, 128, 0, 0, 128, 192, 96, 48, 24, 12, 6, 2, 0, 0]),
4), buf)
def test_preload(self):
creator = testee()
self.assertFalse(creator.are_preloaded_unused())
creator.add_preload_img("resources/bitpatterns.png")
self.assertTrue(creator.are_preloaded_unused())
buf = creator.bitmap("\x01")
self.assertFalse(creator.are_preloaded_unused())
self.assertEqual((array('B',
[128, 64, 32, 16, 8, 4, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 64, 32, 0, 1, 2, 3,
4, 5, 15, 31, 63, 127, 255]),
3), buf)

@ -1,9 +1,8 @@
import datetime import datetime
import importlib
from array import array from array import array
from unittest import TestCase from unittest import TestCase
testee = importlib.import_module("led-badge-11x44") from lednamebadge import LedNameBadge as testee
class Test(TestCase): class Test(TestCase):
@ -11,72 +10,44 @@ class Test(TestCase):
self.test_date = datetime.datetime(2022, 11, 13, 17, 38, 24) self.test_date = datetime.datetime(2022, 11, 13, 17, 38, 24)
def test_header_2msgs(self): def test_header_2msgs(self):
buf = testee.LedNameBadge.header((6, 7), (5, 3), (6, 2), (0, 1), (1, 0), 75, self.test_date) buf = testee.header((6, 7), (5, 3), (6, 2), (0, 1), (1, 0), 75, self.test_date)
self.assertEqual([119, 97, 110, 103, 0, 16, 254, 1, 70, 34, 34, 34, 34, 34, 34, 34, 0, 6, 0, 7, 0, 0, 0, 0, 0, self.assertEqual([119, 97, 110, 103, 0, 16, 254, 1, 70, 34, 34, 34, 34, 34, 34, 34, 0, 6, 0, 7, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 22, 11, 13, 17, 38, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 22, 11, 13, 17, 38, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0], buf) 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], buf)
def test_header_8msgs(self): def test_header_8msgs(self):
buf = testee.LedNameBadge.header((1, 2, 3, 4, 5, 6, 7, 8), buf = testee.header((1, 2, 3, 4, 5, 6, 7, 8),
(1, 2, 3, 4, 5, 6, 7, 8), (1, 2, 3, 4, 5, 6, 7, 8),
(1, 2, 3, 4, 5, 6, 7, 8), (1, 2, 3, 4, 5, 6, 7, 8),
(0, 1, 0, 1, 0, 1, 0, 1), (0, 1, 0, 1, 0, 1, 0, 1),
(1, 0, 1, 0, 1, 0, 1, 0), (1, 0, 1, 0, 1, 0, 1, 0),
25, 25,
self.test_date) self.test_date)
self.assertEqual([119, 97, 110, 103, 0, 64, 170, 85, 1, 18, 35, 52, 69, 86, 103, 120, 0, 1, 0, 2, 0, 3, 0, 4, 0, self.assertEqual([119, 97, 110, 103, 0, 64, 170, 85, 1, 18, 35, 52, 69, 86, 103, 120, 0, 1, 0, 2, 0, 3, 0, 4, 0,
5, 0, 6, 0, 7, 0, 8, 0, 0, 0, 0, 0, 0, 22, 11, 13, 17, 38, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 6, 0, 7, 0, 8, 0, 0, 0, 0, 0, 0, 22, 11, 13, 17, 38, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0], buf) 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], buf)
def test_header_brightness(self): def test_header_brightness(self):
buf = testee.LedNameBadge.header((6,), (4,), (4,), (0,), (0,), 25, self.test_date) buf = testee.header((6,), (4,), (4,), (0,), (0,), 25, self.test_date)
self.assertEqual([119, 97, 110, 103, 0, 64, 0, 0, 52, 52, 52, 52, 52, 52, 52, 52, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, self.assertEqual([119, 97, 110, 103, 0, 64, 0, 0, 52, 52, 52, 52, 52, 52, 52, 52, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 22, 11, 13, 17, 38, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 22, 11, 13, 17, 38, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0], buf) 0, 0, 0, 0, 0, 0, 0, 0, 0], buf)
buf = testee.LedNameBadge.header((6,), (4,), (4,), (0,), (0,), 26, self.test_date) buf = testee.header((6,), (4,), (4,), (0,), (0,), 26, self.test_date)
self.assertEqual([119, 97, 110, 103, 0, 32, 0, 0, 52, 52, 52, 52, 52, 52, 52, 52, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, self.assertEqual([119, 97, 110, 103, 0, 32, 0, 0, 52, 52, 52, 52, 52, 52, 52, 52, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 22, 11, 13, 17, 38, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 22, 11, 13, 17, 38, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0], buf) 0, 0, 0, 0, 0, 0, 0, 0, 0], buf)
buf = testee.LedNameBadge.header((6,), (4,), (4,), (0,), (0,), 60, self.test_date) buf = testee.header((6,), (4,), (4,), (0,), (0,), 60, self.test_date)
self.assertEqual([119, 97, 110, 103, 0, 16, 0, 0, 52, 52, 52, 52, 52, 52, 52, 52, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, self.assertEqual([119, 97, 110, 103, 0, 16, 0, 0, 52, 52, 52, 52, 52, 52, 52, 52, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 22, 11, 13, 17, 38, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 22, 11, 13, 17, 38, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0], buf) 0, 0, 0, 0, 0, 0, 0, 0, 0], buf)
buf = testee.LedNameBadge.header((6,), (4,), (4,), (0,), (0,), 80, self.test_date) buf = testee.header((6,), (4,), (4,), (0,), (0,), 80, self.test_date)
self.assertEqual([119, 97, 110, 103, 0, 0, 0, 0, 52, 52, 52, 52, 52, 52, 52, 52, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, self.assertEqual([119, 97, 110, 103, 0, 0, 0, 0, 52, 52, 52, 52, 52, 52, 52, 52, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 22, 11, 13, 17, 38, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 22, 11, 13, 17, 38, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0], buf) 0, 0, 0, 0, 0, 0, 0, 0, 0], buf)
def test_header_date(self): def test_header_date(self):
buf1 = testee.LedNameBadge.header((6,), (4,), (4,), (0,), (0,), 100, self.test_date) buf1 = testee.header((6,), (4,), (4,), (0,), (0,), 100, self.test_date)
buf2 = testee.LedNameBadge.header((6,), (4,), (4,), (0,), (0,), 100) buf2 = testee.header((6,), (4,), (4,), (0,), (0,), 100)
self.assertEqual(buf1[0:38], buf2[0:38]) self.assertEqual(buf1[0:38], buf2[0:38])
self.assertEqual(buf1[38 + 6:], buf2[38 + 6:]) self.assertEqual(buf1[38 + 6:], buf2[38 + 6:])
self.assertNotEqual(buf1[38:38 + 6], buf2[38:38 + 6]) self.assertNotEqual(buf1[38:38 + 6], buf2[38:38 + 6])
def test_bitmap_png(self):
creator = testee.SimpleTextAndIcons()
buf = creator.bitmap("resources/bitpatterns.png")
self.assertEqual((array('B',
[128, 64, 32, 16, 8, 4, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 64, 32, 0, 1, 2, 3,
4, 5, 15, 31, 63, 127, 255]),
3), buf)
def test_bitmap_text(self):
creator = testee.SimpleTextAndIcons()
buf = creator.bitmap("/:HEART2:\\")
self.assertEqual((array('B',
[0, 0, 2, 6, 12, 24, 48, 96, 192, 128, 0, 0, 12, 30, 63, 63, 63, 31, 15, 7, 3, 1, 0, 96,
240, 248, 248, 248, 240, 224, 192, 128, 0, 0, 128, 192, 96, 48, 24, 12, 6, 2, 0, 0]),
4), buf)
def test_preload(self):
creator = testee.SimpleTextAndIcons()
self.assertFalse(creator.are_preloaded_unused())
creator.add_preload_img("resources/bitpatterns.png")
self.assertTrue(creator.are_preloaded_unused())
buf = creator.bitmap("\x01")
self.assertFalse(creator.are_preloaded_unused())
self.assertEqual((array('B',
[128, 64, 32, 16, 8, 4, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 64, 32, 0, 1, 2, 3,
4, 5, 15, 31, 63, 127, 255]),
3), buf)

Loading…
Cancel
Save