|
|
|
@ -10,7 +10,7 @@ from pytest import raises, skip
|
|
|
|
|
from hscommon.testutil import eq_
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
from core.pe.cache import colors_to_string, string_to_colors
|
|
|
|
|
from core.pe.cache import colors_to_bytes, bytes_to_colors
|
|
|
|
|
from core.pe.cache_sqlite import SqliteCache
|
|
|
|
|
from core.pe.cache_shelve import ShelveCache
|
|
|
|
|
except ImportError:
|
|
|
|
@ -19,32 +19,33 @@ except ImportError:
|
|
|
|
|
|
|
|
|
|
class TestCaseColorsToString:
|
|
|
|
|
def test_no_color(self):
|
|
|
|
|
eq_("", colors_to_string([]))
|
|
|
|
|
eq_(b"", colors_to_bytes([]))
|
|
|
|
|
|
|
|
|
|
def test_single_color(self):
|
|
|
|
|
eq_("000000", colors_to_string([(0, 0, 0)]))
|
|
|
|
|
eq_("010101", colors_to_string([(1, 1, 1)]))
|
|
|
|
|
eq_("0a141e", colors_to_string([(10, 20, 30)]))
|
|
|
|
|
eq_(b"\x00\x00\x00", colors_to_bytes([(0, 0, 0)]))
|
|
|
|
|
eq_(b"\x01\x01\x01", colors_to_bytes([(1, 1, 1)]))
|
|
|
|
|
eq_(b"\x0a\x14\x1e", colors_to_bytes([(10, 20, 30)]))
|
|
|
|
|
|
|
|
|
|
def test_two_colors(self):
|
|
|
|
|
eq_("000102030405", colors_to_string([(0, 1, 2), (3, 4, 5)]))
|
|
|
|
|
eq_(b"\x00\x01\x02\x03\x04\x05", colors_to_bytes([(0, 1, 2), (3, 4, 5)]))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestCaseStringToColors:
|
|
|
|
|
def test_empty(self):
|
|
|
|
|
eq_([], string_to_colors(""))
|
|
|
|
|
eq_([], bytes_to_colors(b""))
|
|
|
|
|
|
|
|
|
|
def test_single_color(self):
|
|
|
|
|
eq_([(0, 0, 0)], string_to_colors("000000"))
|
|
|
|
|
eq_([(2, 3, 4)], string_to_colors("020304"))
|
|
|
|
|
eq_([(10, 20, 30)], string_to_colors("0a141e"))
|
|
|
|
|
eq_([(0, 0, 0)], bytes_to_colors(b"\x00\x00\x00"))
|
|
|
|
|
eq_([(2, 3, 4)], bytes_to_colors(b"\x02\x03\x04"))
|
|
|
|
|
eq_([(10, 20, 30)], bytes_to_colors(b"\x0a\x14\x1e"))
|
|
|
|
|
|
|
|
|
|
def test_two_colors(self):
|
|
|
|
|
eq_([(10, 20, 30), (40, 50, 60)], string_to_colors("0a141e28323c"))
|
|
|
|
|
eq_([(10, 20, 30), (40, 50, 60)], bytes_to_colors(b"\x0a\x14\x1e\x28\x32\x3c"))
|
|
|
|
|
|
|
|
|
|
def test_incomplete_color(self):
|
|
|
|
|
# don't return anything if it's not a complete color
|
|
|
|
|
eq_([], string_to_colors("102"))
|
|
|
|
|
eq_([], bytes_to_colors(b"\x01"))
|
|
|
|
|
eq_([(1, 2, 3)], bytes_to_colors(b"\x01\x02\x03\x04"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class BaseTestCaseCache:
|
|
|
|
|