Bug 1466211 - Run mozterm tests using pipenv; r?ahal
MozReview-Commit-ID: 9WxSwwXkLS2
--- a/python/mozterm/test/test_terminal.py
+++ b/python/mozterm/test/test_terminal.py
@@ -2,43 +2,57 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from __future__ import absolute_import, unicode_literals
import os
import sys
+from six.moves import builtins
+import blessings
import mozunit
import pytest
from mozterm import Terminal, NullTerminal
+@pytest.fixture
+def without_blessings(monkeypatch):
+ builtins_import = builtins.__import__
+
+ def import_error(name, *args, **kwargs):
+ if name == 'blessings':
+ raise ImportError(name)
+
+ return builtins_import(name, *args, **kwargs)
+
+ monkeypatch.setattr('six.moves.builtins.__import__', import_error)
+
+
def test_terminal():
- blessings = pytest.importorskip('blessings')
term = Terminal()
assert isinstance(term, blessings.Terminal)
+
+def test_terminal_with_disabled_styling():
term = Terminal(disable_styling=True)
assert isinstance(term, NullTerminal)
- del sys.modules['blessings']
- orig = sys.path[:]
- for path in orig:
- if 'blessings' in path:
- sys.path.remove(path)
+@pytest.mark.usefixtures('without_blessings')
+def test_terminal_without_blessings():
term = Terminal()
assert isinstance(term, NullTerminal)
+
+@pytest.mark.usefixtures('without_blessings')
+def test_terminal_without_blessings_raises():
with pytest.raises(ImportError):
- term = Terminal(raises=True)
-
- sys.path = orig
+ Terminal(raises=True)
def test_null_terminal():
term = NullTerminal()
assert term.red("foo") == "foo"
assert term.red == ""
assert term.color(1) == ""
assert term.number_of_colors == 0