70a847
From ba9489d42e8535435e76e97d0da792998abc893e Mon Sep 17 00:00:00 2001
70a847
From: Dan Callaghan <dcallagh@redhat.com>
70a847
Date: Fri, 30 Nov 2012 14:05:04 +1000
70a847
Subject: [PATCH] fix tests when run without a tty (fixes #25)
70a847
70a847
---
70a847
 blessings/__init__.py | 2 +-
70a847
 blessings/tests.py    | 8 +++++---
70a847
 2 files changed, 6 insertions(+), 4 deletions(-)
70a847
70a847
diff --git a/blessings/__init__.py b/blessings/__init__.py
70a847
index 68212c2..e1adbda 100644
70a847
--- a/blessings/__init__.py
70a847
+++ b/blessings/__init__.py
70a847
@@ -448,7 +448,7 @@ class NullCallableString(unicode):
70a847
         new = unicode.__new__(cls, u'')
70a847
         return new
70a847
 
70a847
-    def __call__(self, arg):
70a847
+    def __call__(self, arg, *extra_args):
70a847
         if isinstance(arg, int):
70a847
             return u''
70a847
         return arg  # TODO: Force even strs in Python 2.x to be unicodes? Nah. How would I know what encoding to use to convert it?
70a847
diff --git a/blessings/tests.py b/blessings/tests.py
70a847
index a885c65..38eced4 100644
70a847
--- a/blessings/tests.py
70a847
+++ b/blessings/tests.py
70a847
@@ -44,6 +44,8 @@ def test_capability():
70a847
 
70a847
     """
70a847
     t = TestTerminal()
70a847
+    if not t.is_a_tty:
70a847
+        raise SkipTest
70a847
     sc = unicode_cap('sc')
70a847
     eq_(t.save, sc)
70a847
     eq_(t.save, sc)  # Make sure caching doesn't screw it up.
70a847
@@ -64,7 +66,7 @@ def test_capability_with_forced_tty():
70a847
 
70a847
 def test_parametrization():
70a847
     """Test parametrizing a capability."""
70a847
-    eq_(TestTerminal().cup(3, 4), unicode_parm('cup', 3, 4))
70a847
+    eq_(TestTerminal(force_styling=True).cup(3, 4), unicode_parm('cup', 3, 4))
70a847
 
70a847
 
70a847
 def height_and_width():
70a847
@@ -143,7 +145,7 @@ def test_mnemonic_colors():
70a847
 
70a847
     # Avoid testing red, blue, yellow, and cyan, since they might someday
70a847
     # change depending on terminal type.
70a847
-    t = TestTerminal()
70a847
+    t = TestTerminal(force_styling=True)
70a847
     eq_(t.white, color(7))
70a847
     eq_(t.green, color(2))  # Make sure it's different than white.
70a847
     eq_(t.on_black, on_color(0))
70a847
@@ -247,7 +249,7 @@ def test_nice_formatting_errors():
70a847
 def test_init_descriptor_always_initted():
70a847
     """We should be able to get a height and width even on no-tty Terminals."""
70a847
     t = Terminal(stream=StringIO())
70a847
-    eq_(type(t.height), int)
70a847
+    assert isinstance(t.height, int) or t.height is None
70a847
 
70a847
 
70a847
 def test_force_styling_none():
70a847
-- 
70a847
1.7.11.7
70a847