mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-04-04 01:19:14 +00:00
Port to Python 3.
This commit is contained in:
parent
87f1620ab0
commit
5ebb385c10
@ -1,4 +1,12 @@
|
||||
from past.builtins import unicode
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from future.utils import PY2
|
||||
if PY2:
|
||||
from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, list, object, range, str, max, min # noqa: F401
|
||||
|
||||
import os.path
|
||||
import json
|
||||
from twisted.trial import unittest
|
||||
@ -13,6 +21,7 @@ from allmydata.scripts import debug
|
||||
from ..no_network import GridTestMixin
|
||||
from .common import CLITestMixin
|
||||
|
||||
|
||||
class Check(GridTestMixin, CLITestMixin, unittest.TestCase):
|
||||
|
||||
def test_check(self):
|
||||
@ -29,7 +38,7 @@ class Check(GridTestMixin, CLITestMixin, unittest.TestCase):
|
||||
d.addCallback(lambda ign: self.do_cli("check", self.uri))
|
||||
def _check1(args):
|
||||
(rc, out, err) = args
|
||||
self.failUnlessReallyEqual(err, "")
|
||||
self.assertEqual(len(err), 0, err)
|
||||
self.failUnlessReallyEqual(rc, 0)
|
||||
lines = out.splitlines()
|
||||
self.failUnless("Summary: Healthy" in lines, out)
|
||||
@ -39,7 +48,7 @@ class Check(GridTestMixin, CLITestMixin, unittest.TestCase):
|
||||
d.addCallback(lambda ign: self.do_cli("check", "--raw", self.uri))
|
||||
def _check2(args):
|
||||
(rc, out, err) = args
|
||||
self.failUnlessReallyEqual(err, "")
|
||||
self.assertEqual(len(err), 0, err)
|
||||
self.failUnlessReallyEqual(rc, 0)
|
||||
data = json.loads(out)
|
||||
self.failUnlessReallyEqual(to_bytes(data["summary"]), b"Healthy")
|
||||
@ -54,7 +63,7 @@ class Check(GridTestMixin, CLITestMixin, unittest.TestCase):
|
||||
d.addCallback(lambda ign: self.do_cli("check", self.lit_uri))
|
||||
def _check_lit(args):
|
||||
(rc, out, err) = args
|
||||
self.failUnlessReallyEqual(err, "")
|
||||
self.assertEqual(len(err), 0, err)
|
||||
self.failUnlessReallyEqual(rc, 0)
|
||||
lines = out.splitlines()
|
||||
self.failUnless("Summary: Healthy (LIT)" in lines, out)
|
||||
@ -63,7 +72,7 @@ class Check(GridTestMixin, CLITestMixin, unittest.TestCase):
|
||||
d.addCallback(lambda ign: self.do_cli("check", "--raw", self.lit_uri))
|
||||
def _check_lit_raw(args):
|
||||
(rc, out, err) = args
|
||||
self.failUnlessReallyEqual(err, "")
|
||||
self.assertEqual(len(err), 0, err)
|
||||
self.failUnlessReallyEqual(rc, 0)
|
||||
data = json.loads(out)
|
||||
self.failUnlessReallyEqual(data["results"]["healthy"], True)
|
||||
@ -90,8 +99,8 @@ class Check(GridTestMixin, CLITestMixin, unittest.TestCase):
|
||||
cso.parseOptions([shares[1][2]])
|
||||
storage_index = uri.from_string(self.uri).get_storage_index()
|
||||
self._corrupt_share_line = " server %s, SI %s, shnum %d" % \
|
||||
(unicode(base32.b2a(shares[1][1]), "ascii"),
|
||||
unicode(base32.b2a(storage_index), "ascii"),
|
||||
(str(base32.b2a(shares[1][1]), "ascii"),
|
||||
str(base32.b2a(storage_index), "ascii"),
|
||||
shares[1][0])
|
||||
debug.corrupt_share(cso)
|
||||
d.addCallback(_clobber_shares)
|
||||
@ -99,7 +108,7 @@ class Check(GridTestMixin, CLITestMixin, unittest.TestCase):
|
||||
d.addCallback(lambda ign: self.do_cli("check", "--verify", self.uri))
|
||||
def _check3(args):
|
||||
(rc, out, err) = args
|
||||
self.failUnlessReallyEqual(err, "")
|
||||
self.assertEqual(len(err), 0, err)
|
||||
self.failUnlessReallyEqual(rc, 0)
|
||||
lines = out.splitlines()
|
||||
summary = [l for l in lines if l.startswith("Summary")][0]
|
||||
@ -113,7 +122,7 @@ class Check(GridTestMixin, CLITestMixin, unittest.TestCase):
|
||||
d.addCallback(lambda ign: self.do_cli("check", "--verify", "--raw", self.uri))
|
||||
def _check3_raw(args):
|
||||
(rc, out, err) = args
|
||||
self.failUnlessReallyEqual(err, "")
|
||||
self.assertEqual(len(err), 0, err)
|
||||
self.failUnlessReallyEqual(rc, 0)
|
||||
data = json.loads(out)
|
||||
self.failUnlessReallyEqual(data["results"]["healthy"], False)
|
||||
@ -127,7 +136,7 @@ class Check(GridTestMixin, CLITestMixin, unittest.TestCase):
|
||||
self.do_cli("check", "--verify", "--repair", self.uri))
|
||||
def _check4(args):
|
||||
(rc, out, err) = args
|
||||
self.failUnlessReallyEqual(err, "")
|
||||
self.assertEqual(len(err), 0, err)
|
||||
self.failUnlessReallyEqual(rc, 0)
|
||||
lines = out.splitlines()
|
||||
self.failUnless("Summary: not healthy" in lines, out)
|
||||
@ -141,7 +150,7 @@ class Check(GridTestMixin, CLITestMixin, unittest.TestCase):
|
||||
self.do_cli("check", "--verify", "--repair", self.uri))
|
||||
def _check5(args):
|
||||
(rc, out, err) = args
|
||||
self.failUnlessReallyEqual(err, "")
|
||||
self.assertEqual(len(err), 0, err)
|
||||
self.failUnlessReallyEqual(rc, 0)
|
||||
lines = out.splitlines()
|
||||
self.failUnless("Summary: healthy" in lines, out)
|
||||
@ -183,7 +192,7 @@ class Check(GridTestMixin, CLITestMixin, unittest.TestCase):
|
||||
d.addCallback(lambda ign: self.do_cli("deep-check", self.rooturi))
|
||||
def _check1(args):
|
||||
(rc, out, err) = args
|
||||
self.failUnlessReallyEqual(err, "")
|
||||
self.assertEqual(len(err), 0, err)
|
||||
self.failUnlessReallyEqual(rc, 0)
|
||||
lines = out.splitlines()
|
||||
self.failUnless("done: 4 objects checked, 4 healthy, 0 unhealthy"
|
||||
@ -199,7 +208,7 @@ class Check(GridTestMixin, CLITestMixin, unittest.TestCase):
|
||||
self.rooturi))
|
||||
def _check2(args):
|
||||
(rc, out, err) = args
|
||||
self.failUnlessReallyEqual(err, "")
|
||||
self.assertEqual(len(err), 0, err)
|
||||
self.failUnlessReallyEqual(rc, 0)
|
||||
lines = out.splitlines()
|
||||
self.failUnless("'<root>': Healthy" in lines, out)
|
||||
@ -213,7 +222,7 @@ class Check(GridTestMixin, CLITestMixin, unittest.TestCase):
|
||||
d.addCallback(lambda ign: self.do_cli("stats", self.rooturi))
|
||||
def _check_stats(args):
|
||||
(rc, out, err) = args
|
||||
self.failUnlessReallyEqual(err, "")
|
||||
self.assertEqual(len(err), 0, err)
|
||||
self.failUnlessReallyEqual(rc, 0)
|
||||
lines = out.splitlines()
|
||||
self.failUnlessIn(" count-immutable-files: 1", lines)
|
||||
@ -237,8 +246,8 @@ class Check(GridTestMixin, CLITestMixin, unittest.TestCase):
|
||||
cso.parseOptions([shares[1][2]])
|
||||
storage_index = uri.from_string(self.uris["mutable"]).get_storage_index()
|
||||
self._corrupt_share_line = " corrupt: server %s, SI %s, shnum %d" % \
|
||||
(unicode(base32.b2a(shares[1][1]), "ascii"),
|
||||
unicode(base32.b2a(storage_index), "ascii"),
|
||||
(str(base32.b2a(shares[1][1]), "ascii"),
|
||||
str(base32.b2a(storage_index), "ascii"),
|
||||
shares[1][0])
|
||||
debug.corrupt_share(cso)
|
||||
d.addCallback(_clobber_shares)
|
||||
@ -252,7 +261,7 @@ class Check(GridTestMixin, CLITestMixin, unittest.TestCase):
|
||||
self.do_cli("deep-check", "--verbose", self.rooturi))
|
||||
def _check3(args):
|
||||
(rc, out, err) = args
|
||||
self.failUnlessReallyEqual(err, "")
|
||||
self.assertEqual(len(err), 0, err)
|
||||
self.failUnlessReallyEqual(rc, 0)
|
||||
lines = out.splitlines()
|
||||
self.failUnless("'<root>': Healthy" in lines, out)
|
||||
@ -269,7 +278,7 @@ class Check(GridTestMixin, CLITestMixin, unittest.TestCase):
|
||||
self.rooturi))
|
||||
def _check4(args):
|
||||
(rc, out, err) = args
|
||||
self.failUnlessReallyEqual(err, "")
|
||||
self.assertEqual(len(err), 0, err)
|
||||
self.failUnlessReallyEqual(rc, 0)
|
||||
lines = out.splitlines()
|
||||
self.failUnless("'<root>': Healthy" in lines, out)
|
||||
@ -288,7 +297,7 @@ class Check(GridTestMixin, CLITestMixin, unittest.TestCase):
|
||||
self.rooturi))
|
||||
def _check5(args):
|
||||
(rc, out, err) = args
|
||||
self.failUnlessReallyEqual(err, "")
|
||||
self.assertEqual(len(err), 0, err)
|
||||
self.failUnlessReallyEqual(rc, 0)
|
||||
lines = out.splitlines()
|
||||
units = [json.loads(line) for line in lines]
|
||||
@ -302,7 +311,7 @@ class Check(GridTestMixin, CLITestMixin, unittest.TestCase):
|
||||
self.rooturi))
|
||||
def _check6(args):
|
||||
(rc, out, err) = args
|
||||
self.failUnlessReallyEqual(err, "")
|
||||
self.assertEqual(len(err), 0, err)
|
||||
self.failUnlessReallyEqual(rc, 0)
|
||||
lines = out.splitlines()
|
||||
self.failUnless("'<root>': healthy" in lines, out)
|
||||
@ -326,7 +335,7 @@ class Check(GridTestMixin, CLITestMixin, unittest.TestCase):
|
||||
fn.add_file(u"subfile", upload.Data(DATA+b"2", b"")))
|
||||
d.addCallback(lambda ign:
|
||||
self.delete_shares_numbered(self.uris["subdir"],
|
||||
range(10)))
|
||||
list(range(10))))
|
||||
|
||||
# root
|
||||
# rootg\u00F6\u00F6d/
|
||||
@ -380,7 +389,7 @@ class Check(GridTestMixin, CLITestMixin, unittest.TestCase):
|
||||
(rc, out, err) = args
|
||||
self.failUnlessReallyEqual(rc, 1)
|
||||
self.failUnlessIn("error:", err)
|
||||
self.failUnlessReallyEqual(out, "")
|
||||
self.assertEqual(len(out), 0, out)
|
||||
d.addCallback(_check)
|
||||
d.addCallback(lambda ign: self.do_cli("deep-check"))
|
||||
d.addCallback(_check)
|
||||
@ -397,7 +406,7 @@ class Check(GridTestMixin, CLITestMixin, unittest.TestCase):
|
||||
self.failUnlessReallyEqual(rc, 1)
|
||||
self.failUnlessIn("error:", err)
|
||||
self.failUnlessIn("nonexistent", err)
|
||||
self.failUnlessReallyEqual(out, "")
|
||||
self.assertEqual(len(out), 0, out)
|
||||
d.addCallback(_check)
|
||||
return d
|
||||
|
||||
@ -417,7 +426,7 @@ class Check(GridTestMixin, CLITestMixin, unittest.TestCase):
|
||||
def _check(args):
|
||||
(rc, out, err) = args
|
||||
self.failUnlessReallyEqual(rc, 0)
|
||||
self.failUnlessReallyEqual(err, "")
|
||||
self.assertEqual(len(err), 0, err)
|
||||
#Ensure healthy appears for each uri
|
||||
self.failUnlessIn("Healthy", out[:len(out)//2])
|
||||
self.failUnlessIn("Healthy", out[len(out)//2:])
|
||||
|
@ -176,6 +176,7 @@ PORTED_TEST_MODULES = [
|
||||
"allmydata.test.cli.test_alias",
|
||||
"allmydata.test.cli.test_backup",
|
||||
"allmydata.test.cli.test_backupdb",
|
||||
"allmydata.test.cli.test_check",
|
||||
"allmydata.test.cli.test_create",
|
||||
"allmydata.test.cli.test_invite",
|
||||
"allmydata.test.cli.test_status",
|
||||
|
Loading…
x
Reference in New Issue
Block a user