def test_trans(self): """ Translation functions should translate codes properly. """ for v in self.conversions: # hex2* argset = (v['hexval'],) self.assertTupleEqual( v['rgb'], hex2rgb(*argset), msg=test_msg('Failed to translate.', *argset)) argset = (v['hexval'],) self.assertEqual( v['code'], hex2term(*argset), msg=test_msg('Failed to translate.', *argset)) argset = (v['hexval'],) self.assertEqual( v['hexval'], hex2termhex(*argset), msg=test_msg('Failed to translate.', *argset)) # rgb2* argset = v['rgb'] self.assertEqual( v['hexval'], rgb2hex(*argset), msg=test_msg('Failed to translate.', *argset)) argset = v['rgb'] self.assertEqual( v['code'], rgb2term(*argset), msg=test_msg('Failed to translate.', *argset)) argset = v['rgb'] self.assertEqual( v['hexval'], rgb2termhex(*argset), msg=test_msg('Failed to translate.', *argset)) # term2* argset = (v['code'],) self.assertEqual( v['hexval'], term2hex(*argset), msg=test_msg('Failed to translate.', *argset)) argset = (v['code'],) self.assertTupleEqual( v['rgb'], term2rgb(*argset), msg=test_msg('Failed to translate.', *argset)) for hexval, termhex in self.termhex_close: argset = (hexval,) self.assertEqual( termhex, hex2termhex(*argset), msg=test_msg('Failed on close match.', *argset))
def test_trans(self): """ Translation functions should translate codes properly. """ for v in self.conversions: # hex2* argset = (v['hexval'], ) self.assertTupleEqual(v['rgb'], hex2rgb(*argset), msg=call_msg('Failed to translate.', *argset)) argset = (v['hexval'], ) self.assertEqual(v['code'], hex2term(*argset), msg=call_msg('Failed to translate.', *argset)) argset = (v['hexval'], ) self.assertEqual(v['hexval'], hex2termhex(*argset), msg=call_msg('Failed to translate.', *argset)) # rgb2* argset = v['rgb'] self.assertEqual(v['hexval'], rgb2hex(*argset), msg=call_msg('Failed to translate.', *argset)) argset = v['rgb'] self.assertEqual(v['code'], rgb2term(*argset), msg=call_msg('Failed to translate.', *argset)) argset = v['rgb'] self.assertEqual(v['hexval'], rgb2termhex(*argset), msg=call_msg('Failed to translate.', *argset)) # term2* argset = (v['code'], ) self.assertEqual(v['hexval'], term2hex(*argset), msg=call_msg('Failed to translate.', *argset)) argset = (v['code'], ) self.assertTupleEqual(v['rgb'], term2rgb(*argset), msg=call_msg('Failed to translate.', *argset)) for hexval, termhex in self.termhex_close: argset = (hexval, ) self.assertEqual(termhex, hex2termhex(*argset), msg=call_msg('Failed on close match.', *argset))
def main(sep=' '): """Palette test main function.""" for line in valid_lines(None): r, g, b, name = line.split(maxsplit=3) r, g, b = (int(x) for x in [r, g, b]) h = colr.rgb2hex(r, g, b) th = colr.rgb2termhex(r, g, b) t = colr.rgb2term(r, g, b) d = dict(r=r, g=g, b=b, name=name, h=h, th=th, t=t) d['testfg'] = Colr().hex(h, 'test', rgb_mode=False) d['testbg'] = Colr().b_hex(h, 'test ', rgb_mode=False) d['testbg_rgb'] = Colr().b_hex(h, ' ', rgb_mode=True) fmt = sep.join(['{r:3} {g:3} {b:3}', '0x{h}', '0x{th}', '{t:>3s}', '{testfg}{testbg}{testbg_rgb}', '{name}']) print(fmt.format(**d))
def hex(self) -> str: return colr.rgb2hex(*self.rgb)
def setUp(self): # Default argd, when no flags are given. self.argd = { '--auto-disable': False, '--back': None, '--center': None, '--debug': False, '--err': False, '--fore': None, '--frequency': None, '--gradient': None, '--gradientrgb': [], '--help': False, '--listcodes': False, '--ljust': None, '--names': False, '--newline': False, '--offset': None, '--rainbow': False, '--rjust': None, '--spread': None, '--stripcodes': False, '--style': None, '--translate': False, '--truecolor': False, '--unique': False, '--version': False, 'BACK': None, 'CODE': [], 'FORE': None, 'STYLE': None, 'TEXT': None, } # Number of random values to generate for tests to choose from. max_vals = 50 # Valid basic color name args for the colr tool. self.valid_basic_vals = ( 'white', 'black', 'red', 'cyan', 'green', 'blue', ) # Valid extended color names/values. self.valid_ext_vals = [ 'lightblue', 'lightcyan', ] self.valid_ext_vals.extend( set((str(r.randint(0, 255)) for _ in range(max_vals)))) # Valid rgb color values. self.valid_rgb_vals = [] self.valid_rgb_vals.extend( set((','.join(str(r.randint(0, 255)) for rgb in range(3)) for _ in range(max_vals)))) # Valid hex values. self.valid_hex_vals = ['000', 'fff', 'f0f', 'aba'] for rgb in self.valid_rgb_vals: rgbtup = tuple(int(x) for x in rgb.split(',')) self.valid_hex_vals.append(rgb2hex(*rgbtup)) # Valid style names/values. self.valid_style_vals = ( '0', '1', '2', '3', '4', '5', '7', '22', 'b', 'bold', 'bright', 'd', 'dim', 'f', 'flash', 'h', 'highlight', 'hilight', 'hilite', 'i', 'italic', 'n', 'none', 'normal', 'reset_all', 'reverse', 'u', 'underline', 'underlined', )