def test_resolve_capability(monkeypatch): """Test formatters.resolve_capability and term sugaring """ from blessed.formatters import resolve_capability # given, always returns a b'seq' tigetstr = lambda attr: ('seq-%s' % (attr, )).encode('latin1') monkeypatch.setattr(curses, 'tigetstr', tigetstr) term = mock.Mock() term._sugar = dict(mnemonic='xyz') # exercise assert resolve_capability(term, 'mnemonic') == u'seq-xyz' assert resolve_capability(term, 'natural') == u'seq-natural' # given, where tigetstr returns None tigetstr_none = lambda attr: None monkeypatch.setattr(curses, 'tigetstr', tigetstr_none) # exercise, assert resolve_capability(term, 'natural') == u'' # given, where does_styling is False def raises_exception(*args): assert False, "Should not be called" term.does_styling = False monkeypatch.setattr(curses, 'tigetstr', raises_exception) # exercise, assert resolve_capability(term, 'natural') == u''
def test_resolve_capability(monkeypatch): """Test formatters.resolve_capability and term sugaring """ from blessed.formatters import resolve_capability # given, always returns a b'seq' tigetstr = lambda attr: ('seq-%s' % (attr,)).encode('latin1') monkeypatch.setattr(curses, 'tigetstr', tigetstr) term = mock.Mock() term._sugar = dict(mnemonic='xyz') # exercise assert resolve_capability(term, 'mnemonic') == u'seq-xyz' assert resolve_capability(term, 'natural') == u'seq-natural' # given, where tigetstr returns None tigetstr_none = lambda attr: None monkeypatch.setattr(curses, 'tigetstr', tigetstr_none) # exercise, assert resolve_capability(term, 'natural') == u'' # given, where does_styling is False def raises_exception(*args): assert False, "Should not be called" term.does_styling = False monkeypatch.setattr(curses, 'tigetstr', raises_exception) # exercise, assert resolve_capability(term, 'natural') == u''