Upgrade pyfakefs to current version
Fix #148. Also did some cleanup on the tests.
This commit is contained in:
parent
c513870132
commit
c76c7607f9
@ -46,6 +46,9 @@ def _get_local_editor():
|
||||
def _editor_input(editor, initial='', suffix='.tmp'):
|
||||
"""Use an editor to get input"""
|
||||
str_initial = initial.encode('utf-8') # TODO: make it a configuration item
|
||||
# tfile_name = '/tmp/pubs.tmp'
|
||||
# with open(tfile_name, 'w') as temp_file:
|
||||
# temp_file.write(str_initial)
|
||||
with tempfile.NamedTemporaryFile(suffix=suffix, delete=False) as temp_file:
|
||||
tfile_name = temp_file.name
|
||||
temp_file.write(str_initial)
|
||||
|
@ -98,11 +98,20 @@ 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()
|
||||
# self.fs.create_dir(os.path.expanduser('~'))
|
||||
# self.fs.create_dir(self.rootpath)
|
||||
# os.chdir(self.rootpath)
|
||||
|
||||
|
||||
def reset_fs(self):
|
||||
self._stubber.tearDown() # renew the filesystem
|
||||
self.setUp()
|
||||
if self.fs.isdir(self.homepath):
|
||||
self.fs.remove_object(self.homepath)
|
||||
if self.fs.isdir(self.rootpath):
|
||||
self.fs.remove_object(self.rootpath)
|
||||
|
||||
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)
|
||||
|
||||
|
@ -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
|
||||
@ -66,12 +64,12 @@ class TestFakeInput(unittest.TestCase):
|
||||
|
||||
def test_editor_input(self):
|
||||
other_input = fake_env.FakeInput(['yes', 'no'],
|
||||
module_list=[uis, color])
|
||||
module_list=[uis])
|
||||
other_input.as_global()
|
||||
self.assertEqual(uis._editor_input(), 'yes')
|
||||
self.assertEqual(uis._editor_input(), 'no')
|
||||
self.assertEqual(uis._editor_input('fake_editor'), 'yes')
|
||||
self.assertEqual(uis._editor_input('fake_editor'), 'no')
|
||||
with self.assertRaises(fake_env.FakeInput.UnexpectedInput):
|
||||
color.input()
|
||||
uis._editor_input()
|
||||
|
||||
|
||||
class CommandTestCase(fake_env.TestFakeFs):
|
||||
@ -82,7 +80,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')
|
||||
|
||||
@ -178,7 +175,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)
|
||||
@ -920,4 +917,4 @@ class TestCache(DataCommandTestCase):
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
unittest.main(verbosity=2)
|
||||
|
Loading…
x
Reference in New Issue
Block a user