mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-20 13:33:09 +00:00
tests: use fileutil.write() instead of open() to ensure timely close even without CPython-style reference counting
Some of these already had an explicit close() but I went ahead and replaced them with fileutil.write() as well for the sake of uniformity.
This commit is contained in:
parent
2da3f69f25
commit
3505a8a31c
@ -21,16 +21,16 @@ class Basic(testutil.ReallyEqualMixin, unittest.TestCase):
|
|||||||
def test_loadable(self):
|
def test_loadable(self):
|
||||||
basedir = "test_client.Basic.test_loadable"
|
basedir = "test_client.Basic.test_loadable"
|
||||||
os.mkdir(basedir)
|
os.mkdir(basedir)
|
||||||
open(os.path.join(basedir, "introducer.furl"), "w").write("")
|
fileutil.write(os.path.join(basedir, "introducer.furl"), "")
|
||||||
client.Client(basedir)
|
client.Client(basedir)
|
||||||
|
|
||||||
def test_loadable_old_config_bits(self):
|
def test_loadable_old_config_bits(self):
|
||||||
basedir = "test_client.Basic.test_loadable_old_config_bits"
|
basedir = "test_client.Basic.test_loadable_old_config_bits"
|
||||||
os.mkdir(basedir)
|
os.mkdir(basedir)
|
||||||
open(os.path.join(basedir, "introducer.furl"), "w").write("")
|
fileutil.write(os.path.join(basedir, "introducer.furl"), "")
|
||||||
open(os.path.join(basedir, "no_storage"), "w").write("")
|
fileutil.write(os.path.join(basedir, "no_storage"), "")
|
||||||
open(os.path.join(basedir, "readonly_storage"), "w").write("")
|
fileutil.write(os.path.join(basedir, "readonly_storage"), "")
|
||||||
open(os.path.join(basedir, "debug_discard_storage"), "w").write("")
|
fileutil.write(os.path.join(basedir, "debug_discard_storage"), "")
|
||||||
c = client.Client(basedir)
|
c = client.Client(basedir)
|
||||||
try:
|
try:
|
||||||
c.getServiceNamed("storage")
|
c.getServiceNamed("storage")
|
||||||
@ -41,9 +41,9 @@ class Basic(testutil.ReallyEqualMixin, unittest.TestCase):
|
|||||||
def test_loadable_old_storage_config_bits(self):
|
def test_loadable_old_storage_config_bits(self):
|
||||||
basedir = "test_client.Basic.test_loadable_old_storage_config_bits"
|
basedir = "test_client.Basic.test_loadable_old_storage_config_bits"
|
||||||
os.mkdir(basedir)
|
os.mkdir(basedir)
|
||||||
open(os.path.join(basedir, "introducer.furl"), "w").write("")
|
fileutil.write(os.path.join(basedir, "introducer.furl"), "")
|
||||||
open(os.path.join(basedir, "readonly_storage"), "w").write("")
|
fileutil.write(os.path.join(basedir, "readonly_storage"), "")
|
||||||
open(os.path.join(basedir, "debug_discard_storage"), "w").write("")
|
fileutil.write(os.path.join(basedir, "debug_discard_storage"), "")
|
||||||
c = client.Client(basedir)
|
c = client.Client(basedir)
|
||||||
s = c.getServiceNamed("storage")
|
s = c.getServiceNamed("storage")
|
||||||
self.failUnless(s.no_storage)
|
self.failUnless(s.no_storage)
|
||||||
@ -52,7 +52,7 @@ class Basic(testutil.ReallyEqualMixin, unittest.TestCase):
|
|||||||
def test_secrets(self):
|
def test_secrets(self):
|
||||||
basedir = "test_client.Basic.test_secrets"
|
basedir = "test_client.Basic.test_secrets"
|
||||||
os.mkdir(basedir)
|
os.mkdir(basedir)
|
||||||
open(os.path.join(basedir, "introducer.furl"), "w").write("")
|
fileutil.write(os.path.join(basedir, "introducer.furl"), "")
|
||||||
c = client.Client(basedir)
|
c = client.Client(basedir)
|
||||||
secret_fname = os.path.join(basedir, "private", "secret")
|
secret_fname = os.path.join(basedir, "private", "secret")
|
||||||
self.failUnless(os.path.exists(secret_fname), secret_fname)
|
self.failUnless(os.path.exists(secret_fname), secret_fname)
|
||||||
@ -64,36 +64,33 @@ class Basic(testutil.ReallyEqualMixin, unittest.TestCase):
|
|||||||
def test_reserved_1(self):
|
def test_reserved_1(self):
|
||||||
basedir = "client.Basic.test_reserved_1"
|
basedir = "client.Basic.test_reserved_1"
|
||||||
os.mkdir(basedir)
|
os.mkdir(basedir)
|
||||||
f = open(os.path.join(basedir, "tahoe.cfg"), "w")
|
fileutil.write(os.path.join(basedir, "tahoe.cfg"), \
|
||||||
f.write(BASECONFIG)
|
BASECONFIG + \
|
||||||
f.write("[storage]\n")
|
"[storage]\n" + \
|
||||||
f.write("enabled = true\n")
|
"enabled = true\n" + \
|
||||||
f.write("reserved_space = 1000\n")
|
"reserved_space = 1000\n")
|
||||||
f.close()
|
|
||||||
c = client.Client(basedir)
|
c = client.Client(basedir)
|
||||||
self.failUnlessEqual(c.getServiceNamed("storage").reserved_space, 1000)
|
self.failUnlessEqual(c.getServiceNamed("storage").reserved_space, 1000)
|
||||||
|
|
||||||
def test_reserved_2(self):
|
def test_reserved_2(self):
|
||||||
basedir = "client.Basic.test_reserved_2"
|
basedir = "client.Basic.test_reserved_2"
|
||||||
os.mkdir(basedir)
|
os.mkdir(basedir)
|
||||||
f = open(os.path.join(basedir, "tahoe.cfg"), "w")
|
fileutil.write(os.path.join(basedir, "tahoe.cfg"), \
|
||||||
f.write(BASECONFIG)
|
BASECONFIG + \
|
||||||
f.write("[storage]\n")
|
"[storage]\n" + \
|
||||||
f.write("enabled = true\n")
|
"enabled = true\n" + \
|
||||||
f.write("reserved_space = 10K\n")
|
"reserved_space = 10K\n")
|
||||||
f.close()
|
|
||||||
c = client.Client(basedir)
|
c = client.Client(basedir)
|
||||||
self.failUnlessEqual(c.getServiceNamed("storage").reserved_space, 10*1000)
|
self.failUnlessEqual(c.getServiceNamed("storage").reserved_space, 10*1000)
|
||||||
|
|
||||||
def test_reserved_3(self):
|
def test_reserved_3(self):
|
||||||
basedir = "client.Basic.test_reserved_3"
|
basedir = "client.Basic.test_reserved_3"
|
||||||
os.mkdir(basedir)
|
os.mkdir(basedir)
|
||||||
f = open(os.path.join(basedir, "tahoe.cfg"), "w")
|
fileutil.write(os.path.join(basedir, "tahoe.cfg"), \
|
||||||
f.write(BASECONFIG)
|
BASECONFIG + \
|
||||||
f.write("[storage]\n")
|
"[storage]\n" + \
|
||||||
f.write("enabled = true\n")
|
"enabled = true\n" + \
|
||||||
f.write("reserved_space = 5mB\n")
|
"reserved_space = 5mB\n")
|
||||||
f.close()
|
|
||||||
c = client.Client(basedir)
|
c = client.Client(basedir)
|
||||||
self.failUnlessEqual(c.getServiceNamed("storage").reserved_space,
|
self.failUnlessEqual(c.getServiceNamed("storage").reserved_space,
|
||||||
5*1000*1000)
|
5*1000*1000)
|
||||||
@ -101,12 +98,11 @@ class Basic(testutil.ReallyEqualMixin, unittest.TestCase):
|
|||||||
def test_reserved_4(self):
|
def test_reserved_4(self):
|
||||||
basedir = "client.Basic.test_reserved_4"
|
basedir = "client.Basic.test_reserved_4"
|
||||||
os.mkdir(basedir)
|
os.mkdir(basedir)
|
||||||
f = open(os.path.join(basedir, "tahoe.cfg"), "w")
|
fileutil.write(os.path.join(basedir, "tahoe.cfg"), \
|
||||||
f.write(BASECONFIG)
|
BASECONFIG + \
|
||||||
f.write("[storage]\n")
|
"[storage]\n" + \
|
||||||
f.write("enabled = true\n")
|
"enabled = true\n" + \
|
||||||
f.write("reserved_space = 78Gb\n")
|
"reserved_space = 78Gb\n")
|
||||||
f.close()
|
|
||||||
c = client.Client(basedir)
|
c = client.Client(basedir)
|
||||||
self.failUnlessEqual(c.getServiceNamed("storage").reserved_space,
|
self.failUnlessEqual(c.getServiceNamed("storage").reserved_space,
|
||||||
78*1000*1000*1000)
|
78*1000*1000*1000)
|
||||||
@ -114,12 +110,11 @@ class Basic(testutil.ReallyEqualMixin, unittest.TestCase):
|
|||||||
def test_reserved_bad(self):
|
def test_reserved_bad(self):
|
||||||
basedir = "client.Basic.test_reserved_bad"
|
basedir = "client.Basic.test_reserved_bad"
|
||||||
os.mkdir(basedir)
|
os.mkdir(basedir)
|
||||||
f = open(os.path.join(basedir, "tahoe.cfg"), "w")
|
fileutil.write(os.path.join(basedir, "tahoe.cfg"), \
|
||||||
f.write(BASECONFIG)
|
BASECONFIG + \
|
||||||
f.write("[storage]\n")
|
"[storage]\n" + \
|
||||||
f.write("enabled = true\n")
|
"enabled = true\n" + \
|
||||||
f.write("reserved_space = bogus\n")
|
"reserved_space = bogus\n")
|
||||||
f.close()
|
|
||||||
c = client.Client(basedir)
|
c = client.Client(basedir)
|
||||||
self.failUnlessEqual(c.getServiceNamed("storage").reserved_space, 0)
|
self.failUnlessEqual(c.getServiceNamed("storage").reserved_space, 0)
|
||||||
|
|
||||||
@ -139,7 +134,7 @@ class Basic(testutil.ReallyEqualMixin, unittest.TestCase):
|
|||||||
def test_versions(self):
|
def test_versions(self):
|
||||||
basedir = "test_client.Basic.test_versions"
|
basedir = "test_client.Basic.test_versions"
|
||||||
os.mkdir(basedir)
|
os.mkdir(basedir)
|
||||||
open(os.path.join(basedir, "introducer.furl"), "w").write("")
|
fileutil.write(os.path.join(basedir, "introducer.furl"), "")
|
||||||
c = client.Client(basedir)
|
c = client.Client(basedir)
|
||||||
ss = c.getServiceNamed("storage")
|
ss = c.getServiceNamed("storage")
|
||||||
verdict = ss.remote_get_version()
|
verdict = ss.remote_get_version()
|
||||||
@ -177,15 +172,15 @@ class Run(unittest.TestCase, testutil.StallMixin):
|
|||||||
basedir = "test_client.Run.test_loadable"
|
basedir = "test_client.Run.test_loadable"
|
||||||
os.mkdir(basedir)
|
os.mkdir(basedir)
|
||||||
dummy = "pb://wl74cyahejagspqgy4x5ukrvfnevlknt@127.0.0.1:58889/bogus"
|
dummy = "pb://wl74cyahejagspqgy4x5ukrvfnevlknt@127.0.0.1:58889/bogus"
|
||||||
open(os.path.join(basedir, "introducer.furl"), "w").write(dummy)
|
fileutil.write(os.path.join(basedir, "introducer.furl"), dummy)
|
||||||
open(os.path.join(basedir, "suicide_prevention_hotline"), "w")
|
fileutil.write(os.path.join(basedir, "suicide_prevention_hotline"), "")
|
||||||
client.Client(basedir)
|
client.Client(basedir)
|
||||||
|
|
||||||
def test_reloadable(self):
|
def test_reloadable(self):
|
||||||
basedir = "test_client.Run.test_reloadable"
|
basedir = "test_client.Run.test_reloadable"
|
||||||
os.mkdir(basedir)
|
os.mkdir(basedir)
|
||||||
dummy = "pb://wl74cyahejagspqgy4x5ukrvfnevlknt@127.0.0.1:58889/bogus"
|
dummy = "pb://wl74cyahejagspqgy4x5ukrvfnevlknt@127.0.0.1:58889/bogus"
|
||||||
open(os.path.join(basedir, "introducer.furl"), "w").write(dummy)
|
fileutil.write(os.path.join(basedir, "introducer.furl"), dummy)
|
||||||
c1 = client.Client(basedir)
|
c1 = client.Client(basedir)
|
||||||
c1.setServiceParent(self.sparent)
|
c1.setServiceParent(self.sparent)
|
||||||
|
|
||||||
@ -218,9 +213,7 @@ class NodeMaker(testutil.ReallyEqualMixin, unittest.TestCase):
|
|||||||
def test_maker(self):
|
def test_maker(self):
|
||||||
basedir = "client/NodeMaker/maker"
|
basedir = "client/NodeMaker/maker"
|
||||||
fileutil.make_dirs(basedir)
|
fileutil.make_dirs(basedir)
|
||||||
f = open(os.path.join(basedir, "tahoe.cfg"), "w")
|
fileutil.write(os.path.join(basedir, "tahoe.cfg"), BASECONFIG)
|
||||||
f.write(BASECONFIG)
|
|
||||||
f.close()
|
|
||||||
c = client.Client(basedir)
|
c = client.Client(basedir)
|
||||||
|
|
||||||
n = c.create_node_from_uri("URI:CHK:6nmrpsubgbe57udnexlkiwzmlu:bjt7j6hshrlmadjyr7otq3dc24end5meo5xcr5xe5r663po6itmq:3:10:7277")
|
n = c.create_node_from_uri("URI:CHK:6nmrpsubgbe57udnexlkiwzmlu:bjt7j6hshrlmadjyr7otq3dc24end5meo5xcr5xe5r663po6itmq:3:10:7277")
|
||||||
|
Loading…
Reference in New Issue
Block a user