Skip to content

Commit

Permalink
Bug 1438253 - Add Python 3 support to mozunit. r=gps
Browse files Browse the repository at this point in the history
MozReview-Commit-ID: AJEb9Wcm2T4

--HG--
extra : rebase_source : 3b7dccc542b4d4b146d7f96bf89ee6c54b307a0c
  • Loading branch information
davehunt committed Feb 14, 2018
1 parent 62aa51e commit 99c36d0
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions config/mozunit.py
Expand Up @@ -2,14 +2,17 @@
# 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
import inspect
import os
import sys
import unittest
from StringIO import StringIO
from unittest import TextTestRunner as _TestRunner, TestResult as _TestResult

import pytest
import six

StringIO = six.StringIO

'''Helper to make python unit tests report the way that the Mozilla
unit test infrastructure expects tests to report.
Expand Down Expand Up @@ -76,7 +79,9 @@ def addFailure(self, test, err):

def printFail(self, test, err):
exctype, value, tb = err
message = value.message.splitlines()[0] if value.message else 'NO MESSAGE'
message = value or 'NO MESSAGE'
if hasattr(value, 'message'):
message = value.message.splitlines()[0]
# Skip test runner traceback levels
while tb and self._is_relevant_tb_level(tb):
tb = tb.tb_next
Expand Down Expand Up @@ -149,7 +154,7 @@ class MockedOpen(object):
'''
def __init__(self, files={}):
self.files = {}
for name, content in files.iteritems():
for name, content in files.items():
self.files[normcase(os.path.abspath(name))] = content

def __call__(self, name, mode='r'):
Expand All @@ -170,19 +175,19 @@ def __call__(self, name, mode='r'):
return file

def __enter__(self):
import __builtin__
self.open = __builtin__.open
import six.moves.builtins
self.open = six.moves.builtins.open
self._orig_path_exists = os.path.exists
self._orig_path_isdir = os.path.isdir
self._orig_path_isfile = os.path.isfile
__builtin__.open = self
six.moves.builtins.open = self
os.path.exists = self._wrapped_exists
os.path.isdir = self._wrapped_isdir
os.path.isfile = self._wrapped_isfile

def __exit__(self, type, value, traceback):
import __builtin__
__builtin__.open = self.open
import six.moves.builtins
six.moves.builtins.open = self.open
os.path.exists = self._orig_path_exists
os.path.isdir = self._orig_path_isdir
os.path.isfile = self._orig_path_isfile
Expand Down

0 comments on commit 99c36d0

Please sign in to comment.