Commit c66c97bc authored by Julien Muchembled's avatar Julien Muchembled

qa: fix ImporterTests.test

It was failing when some .py files were not compiled.
parent f9ff4249
......@@ -14,7 +14,6 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from collections import deque
from cPickle import Pickler, Unpickler
from cStringIO import StringIO
from itertools import islice, izip_longest
......@@ -129,19 +128,28 @@ class ImporterTests(NEOThreadedTest):
self.assertDictEqual(state, load())
def test(self):
# XXX: Using NEO source files as test data was a bad idea because
# the test breaks easily in case of massive changes in the code,
# or if there are many untracked files.
importer = []
fs_dir = os.path.join(getTempDirectory(), self.id())
shutil.rmtree(fs_dir, 1) # for --loop
os.mkdir(fs_dir)
src_root, = neo.__path__
fs_list = "root", "client", "master", "tests"
def not_pyc(name):
return not name.endswith(".pyc")
# We use 'hash' to skip roughly half of files.
# They'll be added after the migration has started.
def root_filter(name):
if not name.endswith(".pyc"):
if not_pyc(name):
i = name.find(os.sep)
return i < 0 or name[:i] not in fs_list
return (i < 0 or name[:i] not in fs_list) and (
'.' not in name or hash(name) & 1)
def sub_filter(name):
return lambda n: n[-4:] != '.pyc' and \
n.split(os.sep, 1)[0] in (name, "scripts")
return lambda n: not_pyc(n) and (
hash(n) & 1 if '.' in n else
os.sep in n or n in (name, "scripts"))
conn_list = []
iter_list = []
# Setup several FileStorage databases.
......@@ -193,7 +201,7 @@ class ImporterTests(NEOThreadedTest):
cluster.start()
t, c = cluster.getTransaction()
r = c.root()["neo"]
# Test retrieving of an object from ZODB when next serial in NEO.
# Test retrieving of an object from ZODB when next serial is in NEO.
r._p_changed = 1
t.commit()
t.begin()
......@@ -204,20 +212,23 @@ class ImporterTests(NEOThreadedTest):
self.assertRaisesRegexp(NotImplementedError, " getObjectHistory$",
c.db().history, r._p_oid)
i = r.walk()
next(islice(i, 9, None))
next(islice(i, 4, None))
logging.info("start migration")
dm.doOperation(cluster.storage)
deque(i, maxlen=0)
last_import = None
for i, r in enumerate(r.treeFromFs(src_root, 10)):
# Adjust if needed. Must remain > 0.
assert 14 == sum(1 for i in i)
last_import = -1
for i, r in enumerate(r.treeFromFs(src_root, 6, not_pyc)):
t.commit()
if cluster.storage.dm._import:
last_import = i
self.tic()
self.assertTrue(last_import and not cluster.storage.dm._import)
# Same as above. We want last_import smaller enough compared to i
assert i / 3 < last_import < i - 3, (last_import, i)
self.assertFalse(cluster.storage.dm._import)
i = len(src_root) + 1
self.assertEqual(sorted(r.walk()), sorted(
(x[i:] or '.', sorted(y), sorted(z))
(x[i:] or '.', sorted(y), sorted(filter(not_pyc, z)))
for x, y, z in os.walk(src_root)))
t.commit()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment