blob: 8fd53d782b8d8c34c000c1927f396415ee46c416 [file] [log] [blame]
From 5384f455631a973661af84bbe823b9d59af4d5b1 Mon Sep 17 00:00:00 2001
From: Thomas Ballinger <thomasballinger@gmail.com>
Date: Sun, 6 Dec 2015 14:09:37 -0500
Subject: [PATCH] skip tests when blessings Terminal can't be made
---
tests/test_input.py | 13 ++++++++++++-
tests/test_terminal.py | 16 ++++++++++++++++
tests/test_window.py | 14 ++++++++++++++
3 files changed, 42 insertions(+), 1 deletion(-)
diff --git a/tests/test_input.py b/tests/test_input.py
index 13cb25a..31a7d23 100644
--- a/tests/test_input.py
+++ b/tests/test_input.py
@@ -1,20 +1,30 @@
import os
import signal
+import sys
import threading
import time
import unittest
from mock import Mock
try:
- from unittest import skip
+ from unittest import skip, skipIf
except ImportError:
+
def skip(f):
return lambda self: None
+ def skipIf(condition, reason):
+ if condition:
+ return lambda x: x
+ else:
+ return lambda x: None
+
from curtsies import events
from curtsies.input import Input
+fds_closed = sys.stdin.closed or sys.stdout.closed
+
class CustomEvent(events.Event):
pass
@@ -24,6 +34,7 @@ class CustomScheduledEvent(events.ScheduledEvent):
pass
+@skipIf(fds_closed, "need open file descriptors to test")
class TestInput(unittest.TestCase):
def test_create(self):
Input()
diff --git a/tests/test_terminal.py b/tests/test_terminal.py
index 0df11b0..58f40e3 100644
--- a/tests/test_terminal.py
+++ b/tests/test_terminal.py
@@ -17,6 +17,19 @@
from curtsies.window import BaseWindow, FullscreenWindow, CursorAwareWindow
+try:
+ from unittest import skipIf
+except ImportError:
+ def skipIf(condition, reason):
+ if condition:
+ return lambda x: x
+ else:
+ return lambda x: None
+
+
+fds_closed = sys.stdin.closed or sys.stdout.closed
+
+
class FakeStdin(StringIO):
encoding = 'ascii'
@@ -85,6 +98,7 @@ def write(self, s):
def flush(self): pass
+@skipIf(fds_closed, 'blessings Terminal needs streams open')
class TestFullscreenWindow(unittest.TestCase):
def setUp(self):
self.screen = pyte.Screen(10, 3)
@@ -110,6 +124,7 @@ def __enter__(*args): pass
def __exit__(*args): pass
+@skipIf(fds_closed, 'blessings Terminal needs streams open')
class TestCursorAwareWindow(unittest.TestCase):
def setUp(self):
self.screen = ReportingScreen(6, 3)
@@ -142,6 +157,7 @@ def test_inital_cursor_position(self):
self.assertEqual(self.screen.display, [u' ', u'hi ', u'there '])
+@skipIf(fds_closed, 'blessings Terminal needs streams open')
class TestCursorAwareWindowWithExtraInput(unittest.TestCase):
def setUp(self):
self.screen = ReportingScreenWithExtra(6, 3)
diff --git a/tests/test_window.py b/tests/test_window.py
index 1f4485c..89a3480 100644
--- a/tests/test_window.py
+++ b/tests/test_window.py
@@ -9,10 +9,24 @@
else:
from cStringIO import StringIO
+try:
+ from unittest import skipIf
+except ImportError:
+ def skipIf(condition, reason):
+ if condition:
+ return lambda x: x
+ else:
+ return lambda x: None
+
+
+fds_closed = sys.stdin.closed or sys.stdout.closed
+
+
class FakeFullscreenWindow(FullscreenWindow):
width = property(lambda self: 10)
height = property(lambda self: 4)
+@skipIf(fds_closed, "blessings Terminal needs streams open")
class TestBaseWindow(unittest.TestCase):
"""Pretty pathetic tests for window"""
def test_window(self):