def test_repr(self): """ repr() should work for Presets. """ # Main here for test coverage. self.assertEqual( repr(Preset('red', 'white', 'bold')), 'Preset(fore=\'red\', back=\'white\', style=\'bold\')', msg='repr() is wrong.', )
def test_init(self): """ Initializing a Preset should work. """ st = Preset('red', 'white', 'bold') for text in ('test', 'this', 'out okay?'): self.assertCallEqual( Colr(text, 'red', 'white', 'bold'), func=st, args=(text, ), msg='Failed to build correct Colr from Preset call.', )
def test_eq(self): """ __eq__ should work for identical Presets. """ cases = ( ('red', 'white', 'bold'), ('blue', 'red', 'normal'), (1, 2, None), ((1, 2, 3), (4, 5, 6), None), ) for fore, back, style in cases: self.assertEqual( Preset(fore, back, style), Preset(fore, back, style), msg='Identical Presets did not compare equal.', ) raiser = self.assertRaises(TypeError, msg='Failed to raise for __eq__.') for badtype in (1, 's', {}, None): with raiser: Preset() == badtype
def test_lt(self): """ __lt__ should work for Presets. """ styles = [ Preset('black', 'grey', 'highlight'), Preset('blue', 'red', 'normal'), Preset('red', 'white', 'bold'), Preset('white', 'yellow', 'bold'), Preset('yellow', 'lightblue', 'underline'), ] randomized = styles[:] random.shuffle(randomized) self.assertListEqual( list(sorted(randomized)), styles, msg='Failed to sort Presets properly due to __lt__.', ) cases = ( ('fore', Preset('blue', 'white', 'normal'), Preset('red', 'blue', 'bold')), ('back', Preset('blue', 'blue', 'normal'), Preset('blue', 'red', 'bold')), ('style', Preset('red', 'blue', 'bold'), Preset('red', 'blue', 'normal')), ) for argtype, a, b in cases: self.assertLess( a, b, msg='__lt__ failed on a {} color.'.format(argtype), ) self.assertGreater( b, a, msg='__lt__ failed on a {} color.'.format(argtype), ) raiser = self.assertRaises(TypeError, msg='Failed to raise for __lt__.') for badtype in (1, 's', {}, None): with raiser: Preset() < badtype
def test_hash(self): """ hash() should not change for identical Presets. """ self.assertEqual(hash(Preset('red', 'white', 'bold')), hash(Preset('red', 'white', 'bold')), msg='hash() failed for identical Presets.')
def test_merge(self): st = Preset('red', 'white', 'bold') st2 = Preset('blue') self.assertEqual( st.merge(st2), Preset('blue', 'white', 'bold'), msg='Failed to merge Preset properly.', ) self.assertEqual( st.merge(st2, fore='yellow'), Preset('yellow', 'white', 'bold'), msg='Failed to merge Preset properly.', ) self.assertEqual( st.merge(st2, back='black'), Preset('blue', 'black', 'bold'), msg='Failed to merge Preset properly.', ) self.assertEqual( st.merge(st2, style='normal'), Preset('blue', 'white', 'normal'), msg='Failed to merge Preset properly.', )
patterns. -R,--refactor : Use --rewrite and --view. When no files are given, they are collected recursively from the current directory. Common source code file extensions are matched. Binary files are not touched. -r,--rewrite : Rewrite the input file/s, in place. -o file,--out file : Target file for output. * stdout is used if no -o flag is given. -v,--version : Show version. -V,--view : View the replaced lines before writing. There is a chance to cancel the write. """ # Colr presets. CNum = Preset('blue', style='bright') def main(argd): """ Main entry point, expects docopt arg dict as argd. """ debugprinter.enable(argd['--debug']) if argd['--listfiles'] or argd['--refactor']: argd['--rewrite'] = True argd['--view'] = True if not argd['FILE']: argd['FILE'] = list( iter_source_files(exts=parse_exts(argd['--exts']), )) if not argd['--file']: argd['FILE'] = list( filter_files(