Merge pull request #151 from pubs/fix/pyfakefs37

Fix compatibility with latest Pyfakefs.
main
Olivier Mangin 7 years ago committed by GitHub
commit fe2e31e2d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -29,6 +29,8 @@
### Fixed bugs ### 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) - [[#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) - Fixes tests for printing help on `--help` and without argument. [(#137)](https://github.com/pubs/pubs/issues/137)

@ -11,11 +11,11 @@ import subprocess
from . import color from . import color
from . import config from . import config
from .p3 import _get_raw_stdout, _get_raw_stderr, input, ustr 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 = 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 : # package-shared ui that can be accessed using :
# from uis import get_ui # from uis import get_ui
# ui = get_ui() # ui = get_ui()
@ -45,7 +45,7 @@ def _get_local_editor():
def get_ui(): def get_ui():
if _ui is None: 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 return _ui
@ -85,7 +85,7 @@ class PrintUI(object):
kwargs['file'] = self._stderr kwargs['file'] = self._stderr
print('{}: {}'.format(color.dye_err('error', 'error'), message), **kwargs) 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: if sys.exc_info()[0] is not None:
traceback.print_exception(*sys.exc_info) traceback.print_exception(*sys.exc_info)
@ -104,6 +104,7 @@ class PrintUI(object):
self.exit() self.exit()
return True # never happens return True # never happens
class InputUI(PrintUI): class InputUI(PrintUI):
"""UI class. Stores configuration parameters and system information. """UI class. Stores configuration parameters and system information.
""" """
@ -158,7 +159,6 @@ class InputUI(PrintUI):
pass pass
self.message('Incorrect option.', option_str) self.message('Incorrect option.', option_str)
def input_choice(self, options, option_chars, default=None, question=''): def input_choice(self, options, option_chars, default=None, question=''):
"""Ask the user to chose between a set of options. The user is asked """Ask the user to chose between a set of options. The user is asked
to input a char corresponding to the option he chooses. to input a char corresponding to the option he chooses.

@ -97,11 +97,16 @@ class TestFakeFs(fake_filesystem_unittest.TestCase):
def setUp(self): def setUp(self):
self.rootpath = os.path.abspath(os.path.dirname(__file__)) self.rootpath = os.path.abspath(os.path.dirname(__file__))
self.homepath = os.path.expanduser('~')
self.setUpPyfakefs() self.setUpPyfakefs()
self.fs.CreateDirectory(os.path.expanduser('~')) self.reset_fs()
self.fs.CreateDirectory(self.rootpath)
os.chdir(self.rootpath)
def reset_fs(self): def reset_fs(self):
self._stubber.tearDown() # renew the filesystem """Reset the fake filesystem"""
self.setUp() 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 # those are the additional packages required to run the tests
six six
pyfakefs==3.3 pyfakefs
ddt ddt
mock mock

@ -1,7 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals from __future__ import unicode_literals
import os
import unittest import unittest
import copy import copy

@ -2,7 +2,7 @@
import unittest import unittest
import dotdot import dotdot
from pubs.config import conf # from pubs.config import conf
# class TestConfig(unittest.TestCase): # class TestConfig(unittest.TestCase):
# #

@ -5,8 +5,7 @@ import os
import dotdot import dotdot
import fake_env import fake_env
from pubs import content, filebroker, databroker, datacache from pubs import content, databroker, datacache
from pubs.config import conf
import str_fixtures import str_fixtures
from pubs import endecoder from pubs import endecoder
@ -35,7 +34,7 @@ class TestDataBroker(fake_env.TestFakeFs):
self.assertEqual(db.pull_metadata('citekey1'), page99_metadata) self.assertEqual(db.pull_metadata('citekey1'), page99_metadata)
pulled = db.pull_bibentry('citekey1')['Page99'] 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(pulled[key], page99_bibentry['Page99'][key])
self.assertEqual(db.pull_bibentry('citekey1'), page99_bibentry) self.assertEqual(db.pull_bibentry('citekey1'), page99_bibentry)
@ -91,4 +90,4 @@ class TestDataBroker(fake_env.TestFakeFs):
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main(verbosity=2)

@ -3,7 +3,6 @@ import unittest
import time import time
import dotdot import dotdot
import fake_env
from pubs.datacache import CacheEntrySet from pubs.datacache import CacheEntrySet

@ -1,10 +1,8 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import unittest import unittest
import os
import dotdot import dotdot
import fake_env
from pubs import endecoder, pretty, color, config from pubs import endecoder, pretty, color, config

@ -15,14 +15,12 @@ from pyfakefs.fake_filesystem import FakeFileOpen
import dotdot import dotdot
import fake_env 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 from pubs.config import conf
import configobj
import str_fixtures import str_fixtures
import fixtures import fixtures
from pubs.commands import init_cmd, import_cmd
# makes the tests very noisy # makes the tests very noisy
PRINT_OUTPUT = False PRINT_OUTPUT = False
@ -68,10 +66,10 @@ class TestInput(unittest.TestCase):
ui = uis.InputUI(sample_conf) ui = uis.InputUI(sample_conf)
other_input = fake_env.FakeInput(['yes', 'no'], other_input = fake_env.FakeInput(['yes', 'no'],
module_list=[uis, color]) module_list=[uis])
other_input.as_global() other_input.as_global()
self.assertEqual(ui.editor_input(), 'yes') self.assertEqual(ui.editor_input('fake_editor'), 'yes')
self.assertEqual(ui.editor_input(), 'no') self.assertEqual(ui.editor_input('fake_editor'), 'no')
with self.assertRaises(fake_env.FakeInput.UnexpectedInput): with self.assertRaises(fake_env.FakeInput.UnexpectedInput):
ui.editor_input() ui.editor_input()
@ -84,7 +82,6 @@ class CommandTestCase(fake_env.TestFakeFs):
def setUp(self, nsec_stat=True): def setUp(self, nsec_stat=True):
super(CommandTestCase, self).setUp() super(CommandTestCase, self).setUp()
os.stat_float_times(nsec_stat) 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_pubs_dir = os.path.expanduser('~/.pubs')
self.default_conf_path = os.path.expanduser('~/.pubsrc') self.default_conf_path = os.path.expanduser('~/.pubsrc')
@ -180,7 +177,7 @@ class URLContentTestCase(DataCommandTestCase):
return p3.urlparse(url).path return p3.urlparse(url).path
def url_exists(self, url): 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): def url_to_byte_content(self, url, ui=None):
path = self._url_to_path(url) path = self._url_to_path(url)
@ -922,4 +919,4 @@ class TestCache(DataCommandTestCase):
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main(verbosity=2)

Loading…
Cancel
Save