def test_resolve_attribute_recursive_compoundables(monkeypatch): """ Test recursive compounding of resolve_attribute(). """ import blessed from blessed.formatters import resolve_attribute, FormattingString # patch, resolve_cap = lambda term, digit: 'seq-%s' % (digit, ) monkeypatch.setattr(blessed.formatters, 'resolve_capability', resolve_cap) tparm = lambda *args: u'~'.join( arg.decode('latin1') if not num else '%s' % (arg, ) for num, arg in enumerate(args)).encode('latin1') monkeypatch.setattr(curses, 'tparm', tparm) monkeypatch.setattr(curses, 'COLOR_RED', 6502) monkeypatch.setattr(curses, 'COLOR_BLUE', 6800) color_cap = lambda digit: 'seq-%s' % (digit, ) term = mock.Mock() term._background_color = color_cap term._foreground_color = color_cap term.normal = 'seq-normal' # given, pstr = resolve_attribute(term, 'bright_blue_on_red') # exercise, assert type(pstr) == FormattingString assert str(pstr) == 'seq-6808seq-6502' assert pstr('text') == 'seq-6808seq-6502textseq-normal'
def test_resolve_attribute_recursive_compoundables(monkeypatch): """ Test recursive compounding of resolve_attribute(). """ import blessed from blessed.formatters import resolve_attribute, FormattingString # patch, resolve_cap = lambda term, digit: 'seq-%s' % (digit,) monkeypatch.setattr(blessed.formatters, 'resolve_capability', resolve_cap) tparm = lambda *args: u'~'.join( arg.decode('latin1') if not num else '%s' % (arg,) for num, arg in enumerate(args)).encode('latin1') monkeypatch.setattr(curses, 'tparm', tparm) monkeypatch.setattr(curses, 'COLOR_RED', 6502) monkeypatch.setattr(curses, 'COLOR_BLUE', 6800) color_cap = lambda digit: 'seq-%s' % (digit,) term = mock.Mock() term._background_color = color_cap term._foreground_color = color_cap term.normal = 'seq-normal' # given, pstr = resolve_attribute(term, 'bright_blue_on_red') # exercise, assert type(pstr) == FormattingString assert str(pstr) == 'seq-6808seq-6502' assert pstr('text') == 'seq-6808seq-6502textseq-normal'
def test_resolve_attribute_non_compoundables(monkeypatch): """ Test recursive compounding of resolve_attribute(). """ import blessed from blessed.formatters import resolve_attribute, ParameterizingString uncompoundables = lambda attr: ['split', 'compound'] resolve_cap = lambda term, digit: 'seq-%s' % (digit,) monkeypatch.setattr(blessed.formatters, 'split_compound', uncompoundables) monkeypatch.setattr(blessed.formatters, 'resolve_capability', resolve_cap) tparm = lambda *args: u'~'.join( arg.decode('latin1') if not num else '%s' % (arg,) for num, arg in enumerate(args)).encode('latin1') monkeypatch.setattr(curses, 'tparm', tparm) term = mock.Mock() term.normal = 'seq-normal' # given pstr = resolve_attribute(term, 'not-a-compoundable') assert type(pstr) == ParameterizingString assert str(pstr) == u'seq-not-a-compoundable' # this is like calling term.move_x(3) assert pstr(3) == u'seq-not-a-compoundable~3' # this is like calling term.move_x(3)('text') assert pstr(3)('text') == u'seq-not-a-compoundable~3textseq-normal'
def test_resolve_attribute_recursive_compoundables(monkeypatch): """Test recursive compounding of resolve_attribute().""" import blessed from blessed.formatters import resolve_attribute, FormattingString # patch, def resolve_cap(term, digit): return 'seq-%s' % (digit, ) monkeypatch.setattr(blessed.formatters, 'resolve_capability', resolve_cap) monkeypatch.setattr(curses, 'tparm', fn_tparm) monkeypatch.setattr(curses, 'COLOR_RED', 6502) monkeypatch.setattr(curses, 'COLOR_BLUE', 6800) def color_cap(digit): return 'seq-%s' % (digit, ) term = mock.Mock() term._background_color = color_cap term._foreground_color = color_cap term.normal = 'seq-normal' # given, pstr = resolve_attribute(term, 'bright_blue_on_red') # exercise, assert isinstance(pstr, FormattingString) assert str(pstr) == 'seq-6808seq-6502' assert pstr('text') == 'seq-6808seq-6502textseq-normal'
def test_resolve_attribute_non_compoundables(monkeypatch): """Test recursive compounding of resolve_attribute().""" import blessed from blessed.formatters import resolve_attribute, ParameterizingString def uncompoundables(attr): return ['split', 'compound'] def resolve_cap(term, digit): return 'seq-%s' % (digit, ) monkeypatch.setattr(blessed.formatters, 'split_compound', uncompoundables) monkeypatch.setattr(blessed.formatters, 'resolve_capability', resolve_cap) monkeypatch.setattr(curses, 'tparm', fn_tparm) term = mock.Mock() term.normal = 'seq-normal' # given pstr = resolve_attribute(term, 'not-a-compoundable') assert isinstance(pstr, ParameterizingString) assert str(pstr) == u'seq-not-a-compoundable' # this is like calling term.move_x(3) assert pstr(3) == u'seq-not-a-compoundable~3' # this is like calling term.move_x(3)('text') assert pstr(3)('text') == u'seq-not-a-compoundable~3textseq-normal'
def test_resolve_attribute_as_color(monkeypatch): """ Test simple resolve_attribte() given color name. """ import blessed from blessed.formatters import resolve_attribute resolve_color = lambda term, digit: 'seq-%s' % (digit, ) COLORS = set(['COLORX', 'COLORY']) COMPOUNDABLES = set(['JOINT', 'COMPOUND']) monkeypatch.setattr(blessed.formatters, 'resolve_color', resolve_color) monkeypatch.setattr(blessed.formatters, 'COLORS', COLORS) monkeypatch.setattr(blessed.formatters, 'COMPOUNDABLES', COMPOUNDABLES) term = mock.Mock() assert resolve_attribute(term, 'COLORX') == u'seq-COLORX'
def test_resolve_attribute_as_color(monkeypatch): """ Test simple resolve_attribte() given color name. """ import blessed from blessed.formatters import resolve_attribute resolve_color = lambda term, digit: 'seq-%s' % (digit,) COLORS = set(['COLORX', 'COLORY']) COMPOUNDABLES = set(['JOINT', 'COMPOUND']) monkeypatch.setattr(blessed.formatters, 'resolve_color', resolve_color) monkeypatch.setattr(blessed.formatters, 'COLORS', COLORS) monkeypatch.setattr(blessed.formatters, 'COMPOUNDABLES', COMPOUNDABLES) term = mock.Mock() assert resolve_attribute(term, 'COLORX') == u'seq-COLORX'
def test_resolve_attribute_as_compoundable(monkeypatch): """ Test simple resolve_attribte() given a compoundable. """ import blessed from blessed.formatters import resolve_attribute, FormattingString resolve_cap = lambda term, digit: 'seq-%s' % (digit, ) COMPOUNDABLES = set(['JOINT', 'COMPOUND']) monkeypatch.setattr(blessed.formatters, 'resolve_capability', resolve_cap) monkeypatch.setattr(blessed.formatters, 'COMPOUNDABLES', COMPOUNDABLES) term = mock.Mock() term.normal = 'seq-normal' compound = resolve_attribute(term, 'JOINT') assert type(compound) is FormattingString assert str(compound) == u'seq-JOINT' assert compound('text') == u'seq-JOINTtextseq-normal'
def test_resolve_attribute_as_compoundable(monkeypatch): """ Test simple resolve_attribte() given a compoundable. """ import blessed from blessed.formatters import resolve_attribute, FormattingString resolve_cap = lambda term, digit: 'seq-%s' % (digit,) COMPOUNDABLES = set(['JOINT', 'COMPOUND']) monkeypatch.setattr(blessed.formatters, 'resolve_capability', resolve_cap) monkeypatch.setattr(blessed.formatters, 'COMPOUNDABLES', COMPOUNDABLES) term = mock.Mock() term.normal = 'seq-normal' compound = resolve_attribute(term, 'JOINT') assert type(compound) is FormattingString assert str(compound) == u'seq-JOINT' assert compound('text') == u'seq-JOINTtextseq-normal'
def test_resolve_attribute_non_compoundables(monkeypatch): """ Test recursive compounding of resolve_attribute(). """ import blessed from blessed.formatters import resolve_attribute, ParameterizingString uncompoundables = lambda attr: ['split', 'compound'] resolve_cap = lambda term, digit: 'seq-%s' % (digit, ) monkeypatch.setattr(blessed.formatters, 'split_compound', uncompoundables) monkeypatch.setattr(blessed.formatters, 'resolve_capability', resolve_cap) tparm = lambda *args: u'~'.join( arg.decode('latin1') if not num else '%s' % (arg, ) for num, arg in enumerate(args)).encode('latin1') monkeypatch.setattr(curses, 'tparm', tparm) term = mock.Mock() term.normal = 'seq-normal' # given pstr = resolve_attribute(term, 'not-a-compoundable') assert type(pstr) == ParameterizingString assert str(pstr) == u'seq-not-a-compoundable' # this is like calling term.move_x(3) assert pstr(3) == u'seq-not-a-compoundable~3' # this is like calling term.move_x(3)('text') assert pstr(3)('text') == u'seq-not-a-compoundable~3textseq-normal'