Skip to content

Commit

Permalink
Merge pull request #89 from copyninja/master
Browse files Browse the repository at this point in the history
Clean up the files created during test run.
  • Loading branch information
meejah authored Mar 20, 2024
2 parents 39f8a73 + 6c68394 commit 48b0ba3
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 13 deletions.
4 changes: 4 additions & 0 deletions src/foolscap/test/test_banana.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import print_function
import six
import os
import os.path
from twisted.trial import unittest
from twisted.python.failure import Failure
from twisted.python.components import registerAdapter
Expand Down Expand Up @@ -809,6 +811,8 @@ def setUp(self):
self.banana.connectionMade()

def tearDown(self):
if os.path.exists("unserializable.txt"):
os.remove("unserializable.txt")
return flushEventualQueue()

def send(self, obj):
Expand Down
10 changes: 10 additions & 0 deletions src/foolscap/test/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,10 @@ def test_list_incident_names(self):
# dump some other files in the incident directory
self._write_to(logdir, "distraction.bz2")
self._write_to(logdir, "noise")

os.remove(os.path.join(logdir,"distraction.bz2"))
os.remove(os.path.join(logdir, "noise"))

# and a few real-looking incidents
I1 = "incident-2008-07-29-204211-aspkxoi"
I2 = "incident-2008-07-30-112233-wodaei"
Expand All @@ -955,6 +959,9 @@ def test_list_incident_names(self):
new = list(p.list_incident_names(since=I1))
self.assertEqual(set([name for (name,fn) in new]), set([I2]))

os.remove(os.path.join(logdir, I1 + ".flog"))
os.remove(os.path.join(logdir, I2 + ".flog.bz2"))


def test_get_incidents(self):
basedir = "logging/IncidentPublisher/get_incidents"
Expand All @@ -973,6 +980,8 @@ def test_get_incidents(self):
f.write("stuff")
f.close()

os.remove(os.path.join(logdir, "distraction.bz2"))

# fill the buffers with some messages
t.logger.msg("one")
t.logger.msg("two")
Expand Down Expand Up @@ -1832,6 +1841,7 @@ def test_logprinter_saveto(self):
self.assertEqual(data["from"], "jiijpvbg")
self.assertEqual(data["d"]["message"], "howdy")
self.assertEqual(data["d"]["num"], 123)
os.remove(saveto_filename)

def test_options(self):
basedir = "logging/Tail/options"
Expand Down
36 changes: 23 additions & 13 deletions src/foolscap/test/test_tub.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from __future__ import print_function
import os.path
import os
from twisted.trial import unittest
from twisted.internet import defer
from twisted.application import service
Expand Down Expand Up @@ -75,6 +76,9 @@ def test_certfile(self):
data2 = t2.getCertData()
self.assertTrue(data1 == data2)

if os.path.exists(fn):
os.remove(fn)

def test_tubid(self):
t = Tub(certData=CERT_DATA)
self.assertEqual(t.getTubID(), CERT_TUBID)
Expand Down Expand Up @@ -114,35 +118,42 @@ class FurlFile(unittest.TestCase):
def setUp(self):
self.s = service.MultiService()
self.s.startService()
self.cfn = "test_tub.FurlFile.test_furlfile.certfile"
self.ffn_furl = "test_tub.FurlFile.test_furlfile.furlfile"
self.ffn_tubid = "test_tub.FurlFile.test_tubid_check.furlfile"

def tearDown(self):
d = self.s.stopService()
d.addCallback(flushEventualQueue)
if os.path.exists(self.cfn):
os.remove(self.cfn)
if os.path.exists(self.ffn_furl):
os.remove(self.ffn_furl)
if os.path.exists(self.ffn_tubid):
os.remove(self.ffn_tubid)
return d

def test_furlfile(self):
cfn = "test_tub.FurlFile.test_furlfile.certfile"
t1 = Tub(certFile=cfn)
t1 = Tub(certFile=self.cfn)
t1.setServiceParent(self.s)
portnum = allocate_tcp_port()
port1 = "tcp:%d:interface=127.0.0.1" % portnum
t1.listenOn(port1)
t1.setLocation("127.0.0.1:%d" % portnum)
r1 = Referenceable()
ffn = "test_tub.FurlFile.test_furlfile.furlfile"
furl1 = t1.registerReference(r1, furlFile=ffn)
furl1 = t1.registerReference(r1, furlFile=self.ffn_furl)
d = defer.maybeDeferred(t1.disownServiceParent)

self.assertTrue(os.path.exists(ffn))
self.assertEqual(furl1, open(ffn,"r").read().strip())
self.assertTrue(os.path.exists(self.ffn_furl))
self.assertEqual(furl1, open(self.ffn_furl,"r").read().strip())

def _take2(res):
t2 = Tub(certFile=cfn)
t2 = Tub(certFile=self.cfn)
t2.setServiceParent(self.s)
t2.listenOn(port1)
t2.setLocation("127.0.0.1:%d" % portnum)
r2 = Referenceable()
furl2 = t2.registerReference(r2, furlFile=ffn)
furl2 = t2.registerReference(r2, furlFile=self.ffn_furl)
self.assertEqual(furl1, furl2)
return t2.disownServiceParent()
d.addCallback(_take2)
Expand All @@ -156,12 +167,11 @@ def test_tubid_check(self):
t1.listenOn(port1)
t1.setLocation("127.0.0.1:%d" % portnum)
r1 = Referenceable()
ffn = "test_tub.FurlFile.test_tubid_check.furlfile"
furl1 = t1.registerReference(r1, furlFile=ffn)
furl1 = t1.registerReference(r1, furlFile=self.ffn_tubid)
d = defer.maybeDeferred(t1.disownServiceParent)

self.assertTrue(os.path.exists(ffn))
self.assertEqual(furl1, open(ffn,"r").read().strip())
self.assertTrue(os.path.exists(self.ffn_tubid))
self.assertEqual(furl1, open(self.ffn_tubid,"r").read().strip())

def _take2(res):
t2 = Tub() # gets a different key
Expand All @@ -170,7 +180,7 @@ def _take2(res):
t2.setLocation("127.0.0.1:%d" % portnum)
r2 = Referenceable()
self.assertRaises(WrongTubIdError,
t2.registerReference, r2, furlFile=ffn)
t2.registerReference, r2, furlFile=self.ffn_tubid)
return t2.disownServiceParent()
d.addCallback(_take2)
return d
Expand Down

0 comments on commit 48b0ba3

Please sign in to comment.