Fix tests for Python 2
Also, some cleanup in fake_env.py
This commit is contained in:
parent
66a91b3c0c
commit
3b4cfe635d
@ -70,9 +70,14 @@ def read_text_file(filepath, fail=True):
|
|||||||
try:
|
try:
|
||||||
with _open(filepath, 'r') as f:
|
with _open(filepath, 'r') as f:
|
||||||
content = f.read()
|
content = f.read()
|
||||||
|
try: # Python 2
|
||||||
|
content = content.decode('utf-8')
|
||||||
|
except AttributeError: # Python 3
|
||||||
|
pass
|
||||||
except UnicodeDecodeError:
|
except UnicodeDecodeError:
|
||||||
raise UnableToDecodeTextFile(filepath)
|
raise UnableToDecodeTextFile(filepath)
|
||||||
# Should "raise from", if Python 2 support is dropped.
|
# Should "raise from", if Python 2 support is dropped.
|
||||||
|
|
||||||
return content
|
return content
|
||||||
|
|
||||||
def read_binary_file(filepath, fail=True):
|
def read_binary_file(filepath, fail=True):
|
||||||
|
@ -14,6 +14,7 @@ from .p3 import _get_raw_stdout, _get_raw_stderr, input, ustr
|
|||||||
from .content import check_file, read_text_file, write_file, system_path
|
from .content import check_file, read_text_file, write_file, system_path
|
||||||
|
|
||||||
|
|
||||||
|
DEBUG = False
|
||||||
# package-shared ui that can be accessed using :
|
# package-shared ui that can be accessed using :
|
||||||
# from uis import get_ui
|
# from uis import get_ui
|
||||||
# ui = get_ui()
|
# ui = get_ui()
|
||||||
@ -117,7 +118,7 @@ class PrintUI(object):
|
|||||||
|
|
||||||
:returns: True if exception has been handled (currently never happens)
|
:returns: True if exception has been handled (currently never happens)
|
||||||
"""
|
"""
|
||||||
if not self.debug:
|
if (not DEBUG) and (not self.debug):
|
||||||
self.error(ustr(exc))
|
self.error(ustr(exc))
|
||||||
self.exit()
|
self.exit()
|
||||||
return False
|
return False
|
||||||
|
@ -23,27 +23,6 @@ real_shutil = shutil
|
|||||||
real_glob = glob
|
real_glob = glob
|
||||||
real_io = io
|
real_io = io
|
||||||
|
|
||||||
# def copy_dir(fs, real_dir, fake_dir=None):
|
|
||||||
# """Copy all the data directory into the fake fs"""
|
|
||||||
# if fake_dir is None:
|
|
||||||
# fake_dir = real_dir
|
|
||||||
#
|
|
||||||
# for filename in real_os.listdir(real_dir):
|
|
||||||
# real_path = real_os.path.join(real_dir, filename)
|
|
||||||
# fake_path = os.path.join(fake_dir, filename)
|
|
||||||
# if real_os.path.isfile(real_path):
|
|
||||||
# _, ext = real_os.path.splitext(filename)
|
|
||||||
# if ext in ['.yaml', '.bib', '.txt', '.md']:
|
|
||||||
# with real_io.open(real_path, 'r', encoding='utf-8') as f:
|
|
||||||
# fs.CreateFile(os.path.abspath(fake_path), contents=f.read())
|
|
||||||
# else:
|
|
||||||
# with real_io.open(real_path, 'rb') as f:
|
|
||||||
# fs.CreateFile(fake_path, contents=f.read())
|
|
||||||
#
|
|
||||||
# if real_os.path.isdir(real_path):
|
|
||||||
# fs.CreateDirectory(fake_path)
|
|
||||||
# copy_dir(fs, real_path, fake_path)
|
|
||||||
|
|
||||||
|
|
||||||
# redirecting output
|
# redirecting output
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ from pubs.commands import init_cmd, import_cmd
|
|||||||
|
|
||||||
|
|
||||||
# makes the tests very noisy
|
# makes the tests very noisy
|
||||||
PRINT_OUTPUT = False
|
PRINT_OUTPUT = False
|
||||||
CAPTURE_OUTPUT = True
|
CAPTURE_OUTPUT = True
|
||||||
|
|
||||||
|
|
||||||
@ -124,7 +124,7 @@ class CommandTestCase(fake_env.TestFakeFs):
|
|||||||
self.fail('Unexpected input asked by command: {}.'.format(
|
self.fail('Unexpected input asked by command: {}.'.format(
|
||||||
actual_cmd))
|
actual_cmd))
|
||||||
if PRINT_OUTPUT:
|
if PRINT_OUTPUT:
|
||||||
print(outs)
|
print(outs)
|
||||||
return outs
|
return outs
|
||||||
except SystemExit as exc:
|
except SystemExit as exc:
|
||||||
exc_class, exc, tb = sys.exc_info()
|
exc_class, exc, tb = sys.exc_info()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user