mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-23 23:02:25 +00:00
Merge pull request #1012 from tahoe-lafs/3646.backupdb-python-3
Port test_backupdb to Python 3 Fixes ticket:3646
This commit is contained in:
commit
590f71ad10
0
newsfragments/3646.minor
Normal file
0
newsfragments/3646.minor
Normal file
@ -303,8 +303,8 @@ class BackupDB_v2(object):
|
||||
for name in contents:
|
||||
entries.append( [name.encode("utf-8"), contents[name]] )
|
||||
entries.sort()
|
||||
data = "".join([netstring(name_utf8)+netstring(cap)
|
||||
for (name_utf8,cap) in entries])
|
||||
data = b"".join([netstring(name_utf8)+netstring(cap)
|
||||
for (name_utf8,cap) in entries])
|
||||
dirhash = backupdb_dirhash(data)
|
||||
dirhash_s = base32.b2a(dirhash)
|
||||
c = self.cursor
|
||||
|
@ -1,4 +1,15 @@
|
||||
"""
|
||||
Ported to Python 3.
|
||||
"""
|
||||
from __future__ import print_function
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from future.utils import PY2
|
||||
if PY2:
|
||||
# Don't import future bytes so we don't break a couple of tests
|
||||
from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, dict, list, object, range, str, max, min # noqa: F401
|
||||
|
||||
import sys
|
||||
import os.path, time
|
||||
@ -8,7 +19,7 @@ from twisted.trial import unittest
|
||||
from allmydata.util import fileutil
|
||||
from allmydata.util.encodingutil import listdir_unicode
|
||||
from allmydata.scripts import backupdb
|
||||
from .common_util import skip_if_cannot_represent_filename
|
||||
from ..common_util import skip_if_cannot_represent_filename
|
||||
|
||||
class BackupDB(unittest.TestCase):
|
||||
def create(self, dbfile):
|
||||
@ -70,7 +81,7 @@ class BackupDB(unittest.TestCase):
|
||||
|
||||
|
||||
def writeto(self, filename, data):
|
||||
fn = os.path.join(self.basedir, unicode(filename))
|
||||
fn = os.path.join(self.basedir, filename)
|
||||
parentdir = os.path.dirname(fn)
|
||||
fileutil.make_dirs(parentdir)
|
||||
fileutil.write(fn, data)
|
||||
@ -87,15 +98,15 @@ class BackupDB(unittest.TestCase):
|
||||
|
||||
r = bdb.check_file(foo_fn)
|
||||
self.failUnlessEqual(r.was_uploaded(), False)
|
||||
r.did_upload("foo-cap")
|
||||
r.did_upload(b"foo-cap")
|
||||
|
||||
r = bdb.check_file(blah_fn)
|
||||
self.failUnlessEqual(r.was_uploaded(), False)
|
||||
r.did_upload("blah-cap")
|
||||
|
||||
r = bdb.check_file(foo_fn)
|
||||
self.failUnlessEqual(r.was_uploaded(), "foo-cap")
|
||||
self.failUnlessEqual(type(r.was_uploaded()), str)
|
||||
self.failUnlessEqual(r.was_uploaded(), b"foo-cap")
|
||||
self.failUnlessEqual(type(r.was_uploaded()), bytes)
|
||||
self.failUnlessEqual(r.should_check(), False)
|
||||
|
||||
time.sleep(1.0) # make sure the timestamp changes
|
||||
@ -103,28 +114,28 @@ class BackupDB(unittest.TestCase):
|
||||
|
||||
r = bdb.check_file(foo_fn)
|
||||
self.failUnlessEqual(r.was_uploaded(), False)
|
||||
r.did_upload("new-cap")
|
||||
r.did_upload(b"new-cap")
|
||||
|
||||
r = bdb.check_file(foo_fn)
|
||||
self.failUnlessEqual(r.was_uploaded(), "new-cap")
|
||||
self.failUnlessEqual(r.was_uploaded(), b"new-cap")
|
||||
self.failUnlessEqual(r.should_check(), False)
|
||||
# if we spontaneously decide to upload it anyways, nothing should
|
||||
# break
|
||||
r.did_upload("new-cap")
|
||||
r.did_upload(b"new-cap")
|
||||
|
||||
r = bdb.check_file(foo_fn, use_timestamps=False)
|
||||
self.failUnlessEqual(r.was_uploaded(), False)
|
||||
r.did_upload("new-cap")
|
||||
r.did_upload(b"new-cap")
|
||||
|
||||
r = bdb.check_file(foo_fn)
|
||||
self.failUnlessEqual(r.was_uploaded(), "new-cap")
|
||||
self.failUnlessEqual(r.was_uploaded(), b"new-cap")
|
||||
self.failUnlessEqual(r.should_check(), False)
|
||||
|
||||
bdb.NO_CHECK_BEFORE = 0
|
||||
bdb.ALWAYS_CHECK_AFTER = 0.1
|
||||
|
||||
r = bdb.check_file(blah_fn)
|
||||
self.failUnlessEqual(r.was_uploaded(), "blah-cap")
|
||||
self.failUnlessEqual(r.was_uploaded(), b"blah-cap")
|
||||
self.failUnlessEqual(r.should_check(), True)
|
||||
r.did_check_healthy("results") # we know they're ignored for now
|
||||
|
||||
@ -132,7 +143,7 @@ class BackupDB(unittest.TestCase):
|
||||
bdb.ALWAYS_CHECK_AFTER = 400
|
||||
|
||||
r = bdb.check_file(blah_fn)
|
||||
self.failUnlessEqual(r.was_uploaded(), "blah-cap")
|
||||
self.failUnlessEqual(r.was_uploaded(), b"blah-cap")
|
||||
self.failUnlessEqual(r.should_check(), False)
|
||||
|
||||
os.unlink(os.path.join(basedir, "foo.txt"))
|
||||
@ -165,13 +176,13 @@ class BackupDB(unittest.TestCase):
|
||||
dbfile = os.path.join(basedir, "dbfile")
|
||||
bdb = self.create(dbfile)
|
||||
|
||||
contents = {u"file1": "URI:CHK:blah1",
|
||||
u"file2": "URI:CHK:blah2",
|
||||
u"dir1": "URI:DIR2-CHK:baz2"}
|
||||
contents = {u"file1": b"URI:CHK:blah1",
|
||||
u"file2": b"URI:CHK:blah2",
|
||||
u"dir1": b"URI:DIR2-CHK:baz2"}
|
||||
r = bdb.check_directory(contents)
|
||||
self.failUnless(isinstance(r, backupdb.DirectoryResult))
|
||||
self.failIf(r.was_created())
|
||||
dircap = "URI:DIR2-CHK:foo1"
|
||||
dircap = b"URI:DIR2-CHK:foo1"
|
||||
r.did_create(dircap)
|
||||
|
||||
r = bdb.check_directory(contents)
|
||||
@ -185,7 +196,7 @@ class BackupDB(unittest.TestCase):
|
||||
r = bdb.check_directory(contents)
|
||||
self.failUnless(r.was_created())
|
||||
self.failUnlessEqual(r.was_created(), dircap)
|
||||
self.failUnlessEqual(type(r.was_created()), str)
|
||||
self.failUnlessEqual(type(r.was_created()), bytes)
|
||||
self.failUnlessEqual(r.should_check(), False)
|
||||
|
||||
bdb.NO_CHECK_BEFORE = 0
|
||||
@ -207,14 +218,14 @@ class BackupDB(unittest.TestCase):
|
||||
self.failUnlessEqual(r.should_check(), False)
|
||||
|
||||
|
||||
contents2 = {u"file1": "URI:CHK:blah1",
|
||||
u"dir1": "URI:DIR2-CHK:baz2"}
|
||||
contents2 = {u"file1": b"URI:CHK:blah1",
|
||||
u"dir1": b"URI:DIR2-CHK:baz2"}
|
||||
r = bdb.check_directory(contents2)
|
||||
self.failIf(r.was_created())
|
||||
|
||||
contents3 = {u"file1": "URI:CHK:blah1",
|
||||
u"file2": "URI:CHK:blah3",
|
||||
u"dir1": "URI:DIR2-CHK:baz2"}
|
||||
contents3 = {u"file1": b"URI:CHK:blah1",
|
||||
u"file2": b"URI:CHK:blah3",
|
||||
u"dir1": b"URI:DIR2-CHK:baz2"}
|
||||
r = bdb.check_directory(contents3)
|
||||
self.failIf(r.was_created())
|
||||
|
||||
@ -228,17 +239,17 @@ class BackupDB(unittest.TestCase):
|
||||
bdb = self.create(dbfile)
|
||||
|
||||
self.writeto(u"f\u00f6\u00f6.txt", "foo.txt")
|
||||
files = [fn for fn in listdir_unicode(unicode(basedir)) if fn.endswith(".txt")]
|
||||
files = [fn for fn in listdir_unicode(str(basedir)) if fn.endswith(".txt")]
|
||||
self.failUnlessEqual(len(files), 1)
|
||||
foo_fn = os.path.join(basedir, files[0])
|
||||
#print(foo_fn, type(foo_fn))
|
||||
|
||||
r = bdb.check_file(foo_fn)
|
||||
self.failUnlessEqual(r.was_uploaded(), False)
|
||||
r.did_upload("foo-cap")
|
||||
r.did_upload(b"foo-cap")
|
||||
|
||||
r = bdb.check_file(foo_fn)
|
||||
self.failUnlessEqual(r.was_uploaded(), "foo-cap")
|
||||
self.failUnlessEqual(r.was_uploaded(), b"foo-cap")
|
||||
self.failUnlessEqual(r.should_check(), False)
|
||||
|
||||
bar_fn = self.writeto(u"b\u00e5r.txt", "bar.txt")
|
||||
@ -246,9 +257,9 @@ class BackupDB(unittest.TestCase):
|
||||
|
||||
r = bdb.check_file(bar_fn)
|
||||
self.failUnlessEqual(r.was_uploaded(), False)
|
||||
r.did_upload("bar-cap")
|
||||
r.did_upload(b"bar-cap")
|
||||
|
||||
r = bdb.check_file(bar_fn)
|
||||
self.failUnlessEqual(r.was_uploaded(), "bar-cap")
|
||||
self.failUnlessEqual(r.was_uploaded(), b"bar-cap")
|
||||
self.failUnlessEqual(r.should_check(), False)
|
||||
|
@ -144,6 +144,7 @@ PORTED_MODULES = [
|
||||
|
||||
PORTED_TEST_MODULES = [
|
||||
"allmydata.test.cli.test_alias",
|
||||
"allmydata.test.cli.test_backupdb",
|
||||
"allmydata.test.cli.test_create",
|
||||
"allmydata.test.cli.test_status",
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user