Merge pull request #151 from pubs/fix/pyfakefs37
Fix compatibility with latest Pyfakefs.
This commit is contained in:
commit
fe2e31e2d0
@ -29,6 +29,8 @@
|
||||
|
||||
### Fixed bugs
|
||||
|
||||
- [[#148]](https://github.com/pubs/pubs/issues/148) Fix compatibility with Pyfakefs 3.7 [(#151)](https://github.com/pubs/pubs/pull/151)
|
||||
|
||||
- [[#95]](https://github.com/pubs/pubs/issues/95) Error message when editor is missing [(#141)](https://github.com/pubs/pubs/issues/141)
|
||||
|
||||
- Fixes tests for printing help on `--help` and without argument. [(#137)](https://github.com/pubs/pubs/issues/137)
|
||||
|
10
pubs/uis.py
10
pubs/uis.py
@ -11,11 +11,11 @@ import subprocess
|
||||
from . import color
|
||||
from . import config
|
||||
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
|
||||
|
||||
|
||||
DEBUG = False # unhandled exceptions traces are printed
|
||||
DEBUG_ALL_TRACES = False # handled exceptions traces are printed
|
||||
DEBUG_ALL_TRACES = False # handled exceptions traces are printed
|
||||
# package-shared ui that can be accessed using :
|
||||
# from uis import get_ui
|
||||
# ui = get_ui()
|
||||
@ -45,7 +45,7 @@ def _get_local_editor():
|
||||
|
||||
def get_ui():
|
||||
if _ui is None:
|
||||
return PrintUI(config.load_default_conf()) # no editor support. (#FIXME?)
|
||||
return PrintUI(config.load_default_conf()) # no editor support. (#FIXME?)
|
||||
return _ui
|
||||
|
||||
|
||||
@ -85,7 +85,7 @@ class PrintUI(object):
|
||||
kwargs['file'] = self._stderr
|
||||
print('{}: {}'.format(color.dye_err('error', 'error'), message), **kwargs)
|
||||
|
||||
if DEBUG_ALL_TRACES: # if an exception has been raised, print the trace.
|
||||
if DEBUG_ALL_TRACES: # if an exception has been raised, print the trace.
|
||||
if sys.exc_info()[0] is not None:
|
||||
traceback.print_exception(*sys.exc_info)
|
||||
|
||||
@ -104,6 +104,7 @@ class PrintUI(object):
|
||||
self.exit()
|
||||
return True # never happens
|
||||
|
||||
|
||||
class InputUI(PrintUI):
|
||||
"""UI class. Stores configuration parameters and system information.
|
||||
"""
|
||||
@ -158,7 +159,6 @@ class InputUI(PrintUI):
|
||||
pass
|
||||
self.message('Incorrect option.', option_str)
|
||||
|
||||
|
||||
def input_choice(self, options, option_chars, default=None, question=''):
|
||||
"""Ask the user to chose between a set of options. The user is asked
|
||||
to input a char corresponding to the option he chooses.
|
||||
|
@ -97,11 +97,16 @@ class TestFakeFs(fake_filesystem_unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.rootpath = os.path.abspath(os.path.dirname(__file__))
|
||||
self.homepath = os.path.expanduser('~')
|
||||
self.setUpPyfakefs()
|
||||
self.fs.CreateDirectory(os.path.expanduser('~'))
|
||||
self.fs.CreateDirectory(self.rootpath)
|
||||
os.chdir(self.rootpath)
|
||||
self.reset_fs()
|
||||
|
||||
def reset_fs(self):
|
||||
self._stubber.tearDown() # renew the filesystem
|
||||
self.setUp()
|
||||
"""Reset the fake filesystem"""
|
||||
for dir_name in self.fs.listdir('/'):
|
||||
if dir_name not in ['var', 'tmp']:
|
||||
self.fs.remove_object(os.path.join('/', dir_name))
|
||||
|
||||
self.fs.create_dir(os.path.expanduser('~'))
|
||||
self.fs.create_dir(self.rootpath)
|
||||
os.chdir(self.rootpath)
|
||||
|
@ -1,5 +1,5 @@
|
||||
# those are the additional packages required to run the tests
|
||||
six
|
||||
pyfakefs==3.3
|
||||
pyfakefs
|
||||
ddt
|
||||
mock
|
||||
|
@ -1,7 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import os
|
||||
import unittest
|
||||
import copy
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
import unittest
|
||||
|
||||
import dotdot
|
||||
from pubs.config import conf
|
||||
# from pubs.config import conf
|
||||
|
||||
# class TestConfig(unittest.TestCase):
|
||||
#
|
||||
|
@ -5,8 +5,7 @@ import os
|
||||
import dotdot
|
||||
import fake_env
|
||||
|
||||
from pubs import content, filebroker, databroker, datacache
|
||||
from pubs.config import conf
|
||||
from pubs import content, databroker, datacache
|
||||
|
||||
import str_fixtures
|
||||
from pubs import endecoder
|
||||
@ -35,7 +34,7 @@ class TestDataBroker(fake_env.TestFakeFs):
|
||||
|
||||
self.assertEqual(db.pull_metadata('citekey1'), page99_metadata)
|
||||
pulled = db.pull_bibentry('citekey1')['Page99']
|
||||
for key, value in pulled.items():
|
||||
for key in pulled.keys():
|
||||
self.assertEqual(pulled[key], page99_bibentry['Page99'][key])
|
||||
self.assertEqual(db.pull_bibentry('citekey1'), page99_bibentry)
|
||||
|
||||
@ -91,4 +90,4 @@ class TestDataBroker(fake_env.TestFakeFs):
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
unittest.main(verbosity=2)
|
||||
|
@ -3,7 +3,6 @@ import unittest
|
||||
import time
|
||||
|
||||
import dotdot
|
||||
import fake_env
|
||||
|
||||
from pubs.datacache import CacheEntrySet
|
||||
|
||||
|
@ -1,10 +1,8 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import unittest
|
||||
import os
|
||||
|
||||
import dotdot
|
||||
import fake_env
|
||||
|
||||
from pubs import endecoder, pretty, color, config
|
||||
|
||||
|
@ -15,14 +15,12 @@ from pyfakefs.fake_filesystem import FakeFileOpen
|
||||
import dotdot
|
||||
import fake_env
|
||||
|
||||
from pubs import pubs_cmd, update, color, content, filebroker, uis, p3, endecoder
|
||||
from pubs import pubs_cmd, color, content, uis, p3, endecoder
|
||||
from pubs.config import conf
|
||||
import configobj
|
||||
|
||||
import str_fixtures
|
||||
import fixtures
|
||||
|
||||
from pubs.commands import init_cmd, import_cmd
|
||||
|
||||
# makes the tests very noisy
|
||||
PRINT_OUTPUT = False
|
||||
@ -68,10 +66,10 @@ class TestInput(unittest.TestCase):
|
||||
ui = uis.InputUI(sample_conf)
|
||||
|
||||
other_input = fake_env.FakeInput(['yes', 'no'],
|
||||
module_list=[uis, color])
|
||||
module_list=[uis])
|
||||
other_input.as_global()
|
||||
self.assertEqual(ui.editor_input(), 'yes')
|
||||
self.assertEqual(ui.editor_input(), 'no')
|
||||
self.assertEqual(ui.editor_input('fake_editor'), 'yes')
|
||||
self.assertEqual(ui.editor_input('fake_editor'), 'no')
|
||||
with self.assertRaises(fake_env.FakeInput.UnexpectedInput):
|
||||
ui.editor_input()
|
||||
|
||||
@ -84,7 +82,6 @@ class CommandTestCase(fake_env.TestFakeFs):
|
||||
def setUp(self, nsec_stat=True):
|
||||
super(CommandTestCase, self).setUp()
|
||||
os.stat_float_times(nsec_stat)
|
||||
# self.fs = fake_env.create_fake_fs([content, filebroker, conf, init_cmd, import_cmd, configobj, update], nsec_stat=nsec_stat)
|
||||
self.default_pubs_dir = os.path.expanduser('~/.pubs')
|
||||
self.default_conf_path = os.path.expanduser('~/.pubsrc')
|
||||
|
||||
@ -180,7 +177,7 @@ class URLContentTestCase(DataCommandTestCase):
|
||||
return p3.urlparse(url).path
|
||||
|
||||
def url_exists(self, url):
|
||||
return self.fs.Exists(self._url_to_path(url))
|
||||
return self.fs.exists(self._url_to_path(url))
|
||||
|
||||
def url_to_byte_content(self, url, ui=None):
|
||||
path = self._url_to_path(url)
|
||||
@ -922,4 +919,4 @@ class TestCache(DataCommandTestCase):
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
unittest.main(verbosity=2)
|
||||
|
Loading…
x
Reference in New Issue
Block a user